psychopy.org | Reference | Downloads | Github

.psydat to .csv problems

Good afternoon,

I am new to using the coder view in PsychoPy (and to coding in general) and am having an issue using the .psydat to .csv converter tool. I’m using PsychoPy v1.84.2 on OS X, but the data was collected on a Windows computer probably using an older version of PsychoPy (waiting to hear back from the researcher about which version exactly, in case that makes a difference). Here is what happens when I try to use the tool:

psydat: /Users/stevenalcorn/Desktop/Conversion/999Diego.psydat
Exception AttributeError: “‘ExperimentHandler’ object has no attribute ‘dataFileName’” in <bound method ExperimentHandler.del of <psychopy.data.ExperimentHandler object at 0x119df9510>> ignored
Traceback (most recent call last):
File “/Users/stevenalcorn/Desktop/PsychoPy2.app/Contents/Resources/lib/python2.7/psychopy/app/_psychopyApp.py”, line 343, in csvFromPsydat
exp = fromFile(filePsydat)
File “/Users/stevenalcorn/Desktop/PsychoPy2.app/Contents/Resources/lib/python2.7/psychopy/tools/filetools.py”, line 35, in fromFile
contents = cPickle.load(f)
EOFError

Is there anything else I can try in order to get this data in .csv format? Thanks in advance!

Steven

I have been looking for alternative bits of code to use instead of the option included in PsychoPy, but have not found anything. Does anyone know how I could go about converting these .psydat files? Thanks again!

It would be useful to know the version of PsychoPy with which these files were created. Maybe the ExperimentHandler class has changed in structure since then. I think it is now possible to tell PsychoPy to run as a previous version (as the distribution includes a git repository going back a few releases). This might help.

Perhaps get back to us with the version and even post an example .psydat file here.

I’m still trying to find out which version was used to create the .psydat files, and as soon as the researcher informs me I will post it. I have an example to upload, the forum doesn’t allow .psydat files to be posted here. Can I host the file somewhere else and post the link here?

Also, in case it helps narrow down the problem, the researcher has since updated to PsychoPy version 1.83.04, and the .psydat files created using THAT version can be converted on my end using the “csv from psydat” tool in coder view.

I think I just upgraded your membership status, so hopefully you can now upload the file (haven’t done this before, so hope it works).

Anyway, it seems that PsychoPy can indeed now be instructed to run itself as an earlier version. e.g. you could write a script that starts like this:

import psychopy
psychopy.useVersion('1.76.00') # use the exact version string you need

from psychopy.tools.filetools import fromFile

exp = fromFile('your_file.psydat')

and see what happens

Hi Michael,

I tried the code that you posted and it successfully imported the version that I specified, but then it gave me this error:

############### Running: /Users/stevenalcorn/Desktop/007/007.py ################
Traceback (most recent call last):
File “/Users/stevenalcorn/Desktop/007/007.py”, line 3, in
exp = fromFile (‘Desktop/007/007.psydat’)
NameError: name ‘fromFile’ is not defined

Is there something else I should be adding to this code that wasn’t specified in your previous message?

Also, the researcher is not sure which version of PsychoPy he used because he has since updated. And it appears the restriction on uploading .psydat files is for the entire site, not only new users. It’s not listed as a format that can be uploaded.

Sorry, the fromFile() function needs to be explicitly imported to become available. Have amended the code above to include:

from psychopy.tools.filetools import fromFile

http://www.psychopy.org/api/tools/filetools.html

Also note that your path 'Desktop/007/007.psydat' probably won’t work as it implies that ‘Desktop’ is in your current folder. You’ll need either a full path to the file (e.g. '/Users/stevenalcorn/Desktop/007/007.psydat' or a path relative to where the script is running from (in this case, probably just '007.psydat').

Also, the version of PsychoPy used to run the experiment should be embedded in the .psydat file. These files aren’t really designed to be easily human-readable, but if you open one in a text editor, search for the first instance of the string PsychoPy2experiment

Next to this should be the version of PsychoPy used.

Be careful not to actually make any changes to the file (perhaps best to just open a copy of one).

1 Like

But do upload a psydat file for us to try and extract from if you want further help!

So I tried Michael’s suggestions but didn’t get anywhere. The string “PsychoPy2” is nowhere in the .psydat file, so I can’t use that to figure out which version was used to create this file. And when I tried the new code to use a previous version (I tried 1.83.01, just guessing at what version they were using previously), I got the same error as before:

Traceback (most recent call last):
File “/Users/stevenalcorn/Desktop/007/007.py”, line 4, in
exp = fromFile(‘007.psydat’)
File “/Users/stevenalcorn/.psychopy2/versions/psychopy/tools/filetools.py”, line 34, in fromFile
contents = cPickle.load(f)
EOFError

Here’s a link to the .psydat file if either of you wouldn’t mind trying to convert it to .csv yourselves. I greatly appreciate the help I’ve gotten so far and hope we can get it figured out!

https://app.box.com/s/03imfi0bz660jhg085hus9fws9lhnep1

Bad news I’m afraid; that psydat file looks corrupt. It appears to have halted part-way through writing the file :frowning:

And I assume the csv files are not working either, hence you’re using the psydats?

Well that’s no good! The reason I was trying to convert the .psydat to .csv is because the version of PsychoPy used to create these files was not outputting .csv files. I’m not sure if it was because it was a very old version of the program or the researcher did not check some box to create a .csv file, but either way, there was no .csv in the output, only .psydat and .log.

But fortunately there may still be hope…the .log file seems to contain all of the information that I need (which audio stimuli were played in what order and which key the subject pressed in response to that stimuli). The only bad news is it looks like I’ll have to transfer that information to a spreadsheet by hand, but still, that’s better than losing the data completely.

Thank you both for trying to help me resolve this, and if you think of any other solutions, please post them here!

Sorry about that. Actually, I think the two things are related. If a program is struggling to save data then the csv didn’t get saved and the psydat broke halfway through (I think it was around version 1.81, a couple of years ago, that was having a brain-freeze on certain experiments).

The log files are the braces of “belt and braces” but as you say they aren’t ideal to analyze. I’d be happy to help try and write a script to extract something useful for you, to save you doing it manually in excel

1 Like

I think at this point I’ll go ahead and bite the bullet and do it manually. It’s a mild inconvenience that will take a couple of hours at most. I really do appreciate your willingness to go the extra mile to fix the issue though. :slight_smile:

2 Likes