Exception AttributeError: "'ExperimentHandler' object has no attribute 'dataFileName'"

299 views
Skip to first unread message

Rob.

unread,
Mar 17, 2016, 6:23:22 AM3/17/16
to psychopy-users
Hi,

I run an experiment with Psychopy 1.83.1 and I'm actually looking at the data I recorded. I'm working with python and Jupyter.
When I try to open a single .psydat file I'm able to see the data I recorded and work on it.
However I need to use a routine to work on all the data of my participants togheter. Specifically I'm using the following script to save the data in a dict in order to work on it:

data_cntr ={}

for subject in range(1,13):
   
    print 'cntr= ',subject
   
    try:
        datFile_blocks = fromFile('C:\\Users\\Roberta\\Desktop\\analysis\\data_Spain\\psydat\\blocks\\blocks_c00'+str(subject)+'.psydat')

        for trial in range(len(datFile_blocks.entries)):

            if trial == 0: block = 'meta'

            block = 0
            img_block = 0


            if  0 < trial < 19:
                block = ''
                img_block = '1'

            if  19 < trial < 38:
                block = '_2'
                img_block = '2'


            try:

                img = datFile_blocks.entries[trial]['Images'+img_block]
                cond = datFile_blocks.entries[trial]['cond']
                ar = datFile_blocks.entries[trial]['Arousal'+block+'.response']
                vl = datFile_blocks.entries[trial]['Valence'+block+'.response']
                dm = datFile_blocks.entries[trial]['Dominance'+block+'.response']
                eyes = datFile_blocks.entries[trial]['eyes data']
                eda = datFile_blocks.entries[trial]['eda']
                ecg = datFile_blocks.entries[trial]['ecg']


                if block not in data_cntr.keys(): data_cntr[block] = {}

                if img not in data_cntr[block].keys(): data_cntr[block][img] = {}

                if 'cond' not in data_cntr[block][img].keys(): data_cntr[block][img]['cond'] = []
                if 'ar' not in data_cntr[block][img].keys(): data_cntr[block][img]['ar'] = []
                if 'vl' not in data_cntr[block][img].keys(): data_cntr[block][img]['vl'] = []
                if 'dm' not in data_cntr[block][img].keys(): data_cntr[block][img]['dm'] = []
                if 'eyes' not in data_cntr[block][img].keys(): data_cntr[block][img]['eyes'] = []
                if 'eda' not in data_cntr[block][img].keys(): data_cntr[block][img]['eda'] = []
                if 'ecg' not in data_cntr[block][img].keys(): data_cntr[block][img]['ecg'] = []

                data_cntr[block][img]['cond'].append(cond)
                data_cntr[block][img]['ar'].append(ar)
                data_cntr[block][img]['vl'].append(vl)
                data_cntr[block][img]['dm'].append(dm)
                data_cntr[block][img]['eyes'].append(eyes)
                data_cntr[block][img]['eda'].append(eda)
                data_cntr[block][img]['ecg'].append(ecg)

            except:
                pass
       
    except:
        print 'none'

I have similar code for acontrol group and a clinical group, for blocks data and baseline data.
When I run the whole code I get this error:

Exception AttributeError: "'ExperimentHandler' object has no attribute 'dataFileName'" in <bound method ExperimentHandler.__del__ of <psychopy.data.ExperimentHandler object at 0x26C65470>> ignored

The strange thing is that if I run only some of the files or only part of the script  it doesn't happen. Thinking that the problem was with some of the files, I checked file by file and I have no problem to open single files, except for one of them. In this case I get the same error:

Exception AttributeError: "'ExperimentHandler' object has no attribute 'dataFileName'" in <bound method ExperimentHandler.__del__ of <psychopy.data.ExperimentHandler object at 0x2AF8D850>> ignored
---------------------------------------------------------------------------
EOFError                                  Traceback (most recent call last)
<ipython-input-15-cac711417e75> in <module>()
----> 1 datFile= fromFile('C:\\Users\\Roberta\\Desktop\\analysis\\data_Spain\\psydat\\blocks\\blocks_c001.psydat')

C:\Program Files (x86)\PsychoPy2\Lib\site-packages\PsychoPy-1.83.01-py2.7.egg\psychopy\tools\filetools.pyc in fromFile(filename)
     32     """
     33     f = open(filename)
---> 34     contents = cPickle.load(f)
     35     f.close()
     36     #if loading an experiment file make sure we don't save further copies using __del__

EOFError: 


First of all I'm not sure if the problem is related to how I open the file or how I save the data.
In the second case, I can modify my script for the next experiment but how can I deal with this problem now?


I hope that someone can help me!I can provide more information if needed!

Thank you in advance!
ROb


Jeremy Gray

unread,
Mar 17, 2016, 7:30:17 AM3/17/16
to psychop...@googlegroups.com
Is your code working the way you want? This kind of message (Exception ...: "'...' object has no attribute '...'" in <bound method ....__del__ of <... object at ... >> ignored) is really just a warning, and can usually be ignored. Its happening inside the __del__ method when the object is being deleted, and its telling you that its ignoring that exception.

--Jeremy

--
You received this message because you are subscribed to the Google Groups "psychopy-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to psychopy-user...@googlegroups.com.
To post to this group, send email to psychop...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/psychopy-users/8f33bc61-bff5-4924-8316-41eb604f10e0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Rob.

unread,
Mar 18, 2016, 5:18:59 AM3/18/16
to psychopy-users
Hi Jeremy,

Thank you for your reply.
My code does't work properly. When I do not get the error my data are saved in the dict and I can work on it. When I get the error the data are not saved in the dict and so I cannot do anything. I suppose that the problem is related to the fact that I open my files with "try, exept". When I have the exeption the script move direclty to the next file without organizing the data in data={}. Could it be?
Unfortunatly I'm not an expert in using python so this is only a supposition.
However the exception happen only for part of the data and when I run all the data (with a single file I have no problem). It sound a bit strange for me.

My script:


data_cntr ={}

for subject in range(1,13):
   
    print 'cntr= ',subject
   
   
    try:
        datFile_blocks = fromFile('C:\\Users\\Roberta\\Desktop\\analysis\\data_Spain\\psydat\\blocks\\blocks_c00'+str(subject)+'.psydat')

        for trial in range(len(datFile_blocks.entries)):

            if trial == 0: block = 'meta'

            block = 0
            img_block = 0


            if  0 < trial < 19:
                block = ''
                print 'here1'

                img_block = '1'

            if  19 < trial < 38:
                block = '_2'
                print 'here2'
        pass

The output:

cntr=  1
cntr= 
Exception AttributeError: "'ExperimentHandler' object has no attribute 'dataFileName'" in <bound method ExperimentHandler.__del__ of <psychopy.data.ExperimentHandler object at 0x16ED4990>> ignored
Exception 
 2
cntr= 
AttributeError: "'ExperimentHandler' object has no attribute 'dataFileName'" in <bound method ExperimentHandler.__del__ of <psychopy.data.ExperimentHandler object at 0x16F248B0>> ignored
Exception 
 3
cntr= 
AttributeError: "'ExperimentHandler' object has no attribute 'dataFileName'" in <bound method ExperimentHandler.__del__ of <psychopy.data.ExperimentHandler object at 0x1808C9F0>> ignored
Exception 
 4
cntr= 
AttributeError: "'ExperimentHandler' object has no attribute 'dataFileName'" in <bound method ExperimentHandler.__del__ of <psychopy.data.ExperimentHandler object at 0x15E7F7B0>> ignored
Exception 
 5
cntr= 
AttributeError: "'ExperimentHandler' object has no attribute 'dataFileName'" in <bound method ExperimentHandler.__del__ of <psychopy.data.ExperimentHandler object at 0x17D7D830>> ignored
Exception 
 6
cntr= 
AttributeError: "'ExperimentHandler' object has no attribute 'dataFileName'" in <bound method ExperimentHandler.__del__ of <psychopy.data.ExperimentHandler object at 0x29C49AF0>> ignored
Exception 
 7
cntr=  8
here1
AttributeError: "'ExperimentHandler' object has no attribute 'dataFileName'" in <bound method ExperimentHandler.__del__ of <psychopy.data.ExperimentHandler object at 0x295076B0>> ignored
Exception 
here1
here1
cntr=  9
cntr= 
AttributeError: "'ExperimentHandler' object has no attribute 'dataFileName'" in <bound method ExperimentHandler.__del__ of <psychopy.data.ExperimentHandler object at 0x13FCD610>> ignored
Exception 
 10
cntr= 
AttributeError: "'ExperimentHandler' object has no attribute 'dataFileName'" in <bound method ExperimentHandler.__del__ of <psychopy.data.ExperimentHandler object at 0x20236170>> ignored
Exception 
 11
cntr=  12
AttributeError: "'ExperimentHandler' object has no attribute 'dataFileName'" in <bound method ExperimentHandler.__del__ of <psychopy.data.ExperimentHandler object at 0x24BA9C50>> ignored

the next part of the code:

blocks_1_cntr = data_cntr['']
blocks_2_cntr = data_cntr['_2']
blocks_cntr= dict(blocks_1_cntr.items() + blocks_2_cntr.items())


blocks_images_cntr   = blocks_cntr.keys()


the error:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-10-b95a7f34d547> in <module>()
     12 #practice_cntr = baseline_cntr['_P']
     13 blocks_1_cntr = data_cntr['']
---> 14 blocks_2_cntr = data_cntr['_2']
     15 blocks_cntr= dict(blocks_1_cntr.items() + blocks_2_cntr.items())
     16 

KeyError: '_2'



As I sayd before I have 4 similar syntax (two for the baseline (cntr and pz) and two for blocks (cntr and pz).
If needed I can post all of them.

Thank you in advance for your help

Roberta

I post again my code and the error to give more information

Jeremy Gray

unread,
Mar 18, 2016, 7:05:27 AM3/18/16
to psychop...@googlegroups.com
Hi Roberta,

My code does't work properly. When I do not get the error my data are saved in the dict and I can work on it. When I get the error the data are not saved in the dict and so I cannot do anything. I suppose that the problem is related to the fact that I open my files with "try, exept". When I have the exeption the script move direclty to the next file without organizing the data in data={}. Could it be?

Yes, very likely this is contributing to the problem, by hiding the actual error. Using try + except is powerful, but here it simply suppressing all of the actual error messages--and you need to see those in order to figure out what the actual problem is. So I would remove both instances of try + except here. python provides a lot of very useful info about errors, so its good to take advantage of that, and then fix the specific error.

There are ways to use try + except more carefully. 1) enclose only the potentially problematic line or two of code inside the try part, and 2) catch specific exceptions, like 'except OSError:' rather than catching everything and anything.

--Jeremy
    
 

Rob.

unread,
Mar 18, 2016, 7:19:51 AM3/18/16
to psychopy-users
Thank you Jeremy.
You're right.
I run the code without "try/exept" and this is the error:

Exception AttributeError: "'ExperimentHandler' object has no attribute 'dataFileName'" in <bound method ExperimentHandler.__del__ of <psychopy.data.ExperimentHandler object at 0x081B6FB0>> ignored
---------------------------------------------------------------------------
MemoryError                               Traceback (most recent call last)
<ipython-input-4-5a7130fe9b38> in <module>()
      9 
     10 
---> 11     datFile_blocks = fromFile('C:\\Users\\Roberta\\Desktop\\analysis\\data_Spain\\psydat\\blocks\\blocks_c00'+str(subject)+'.psydat')
     12 
     13     for trial in range(len(datFile_blocks.entries)):


C:\Program Files (x86)\PsychoPy2\Lib\site-packages\PsychoPy-1.83.01-py2.7.egg\psychopy\tools\filetools.pyc in 
fromFile(filename)

     32     """
     33     f = open(filename)
---> 34     contents = cPickle.load(f)
     35     f.close()
     36     #if loading an experiment file make sure we don't save further copies using __del__

MemoryError: 

In [ ]:


I had the suspect that the problem could be related to the size of the files because the script worked properly only with less files.I know that this is not properly related to Psychopy or psydat files but can I ask you if you have suggestion about how to deal with this problem?


Thanik you very much for the help!

Rob

Jeremy Gray

unread,
Mar 18, 2016, 8:02:35 AM3/18/16
to psychop...@googlegroups.com
I agree that a MemoryError could be somehow related to file size -- how large are the .psydat files that won't load?

--Jeremy

Rob.

unread,
Mar 18, 2016, 8:39:14 AM3/18/16
to psychopy-users
They are all 80/100KB.
Reply all
Reply to author
Forward
0 new messages