Open *.psydat file

1,581 views
Skip to first unread message

Nils Klöckner

unread,
Jun 12, 2012, 1:04:08 PM6/12/12
to psychopy-users
Hello,

I'm very new to Python / Psychopy. I did a color discrimination
experiment with the experiment builder. Within blocks, trial
conditions were randomized. Now all I'm trying is to reproduce the
randomization process.

My understanding is that this can be done by having a look at the
"*.psydat"-file, where the results are stored. Psychopy Online
Documentation offers a mini-demo-script:

###############################################################################
from psychopy.misc import fromFile
datFile = fromFile('fileName.psydat')
#get info (added when the handler was created)
print datFile.extraInfo
#get data
print datFile.data
#get list of conditions
conditions = datFile.trialList
for condN, condition in enumerate(conditions):
print condition, datFile.data['response'][condN],
numpy.mean(datFile.data['response'][condN])
###############################################################################

I don't know what 'response' stands for in the last line.

All I'm able to infere from the output are the 30 different trials
(with variables set as defined by me in the conditions file) and the
corresponding reponses - but not the order in which the trials have
actually been presented.

I also can't find any information regarding the 4 repetitions (4 of
these blocks à 30 trials formed a meta-block).


I would apreciate it very much if someone could give me a hand with
this... or even provide a more comprehensive demo-script.


With best regards,

Nils Klöckner
Berlin Institut of Technology

Jonathan Peirce

unread,
Jun 14, 2012, 11:57:23 AM6/14/12
to psychop...@googlegroups.com
Hi Nils,

This has come up before. It will be fixed by the new file format in
version 1.74 (not out yet). You can convert your existing data, using
the psydat files with something like the following. If you get an error
about psydat files not loading (you may well if you updated psychopy
lately) then I'll need to send an additional tweak.

Jon

from psychopy import gui, misc, core, misc
import os

files = gui.fileOpenDlg('.')
if len(files)==0:
core.quit()

for filename in files:
#load data
dat = misc.fromFile(filename)
#get file name from complete path
baseFilename = os.path.split(filename)[1]
baseFilename = os.path.splitext(baseFilename)[0]
#save as 'long wide' format
dat.saveAsWideText('longWide/'+baseFilename+'.csv', delim=',')
> these blocks � 30 trials formed a meta-block).
>
>
> I would apreciate it very much if someone could give me a hand with
> this... or even provide a more comprehensive demo-script.
>
>
> With best regards,
>
> Nils Kl�ckner
> Berlin Institut of Technology
>

--
Jonathan Peirce
Nottingham Visual Neuroscience

http://www.peirce.org.uk


This message and any attachment are intended solely for the addressee and may contain confidential information. If you have received this message in error, please send it back to me, and immediately delete it. Please do not use, copy or disclose the information contained in this message or in any attachment. Any views or opinions expressed by the author of this email do not necessarily reflect the views of the University of Nottingham.

This message has been checked for viruses but the contents of an attachment
may still contain software viruses which could damage your computer system:
you are advised to perform your own checks. Email communications with the
University of Nottingham may be monitored as permitted by UK legislation.

Katrina Connell

unread,
May 1, 2016, 7:32:30 PM5/1/16
to psychopy-users
I ran an experiment and only saved the csv files since I thought that was what i wanted, but I now realize the excel sheets will be a lot easier for me to use so I would like to use the psydat file to recreate the xlsx files.  I am trying to use part of the code above mixed with code for saving  to create an xslx file from the psydat file, but I keep getting the error message AttributeError: 'ExperimentHandler' object has no attribute 'saveAsExcel'.

I am pretty new to coding, so I just don't know what I need to add or change to get this code to save the excel files, not the csv files.  I looked all over but haven't found anything.  Any suggestions?  The code I'm trying to use is below.

Thanks
Katrina 

from psychopy import gui, misc, core, misc 
import os 

files = gui.fileOpenDlg('.') 
if len(files)==0: 
     core.quit() 

for filename in files: 
     #load data 
     dat = fromFile(filename) 
     #get file name from complete path 
     baseFilename = os.path.split(filename)[1] 
     baseFilename = os.path.splitext(baseFilename)[0] 
     dat.saveAsExcel(baseFilename)

Michael MacAskill

unread,
May 1, 2016, 7:51:29 PM5/1/16
to psychop...@googlegroups.com
Hi Katrina,

These days, we generally discourage people from using the Excel output, for a variety of reasons, and to be honest, at some point that capability should probably be dropped.

Perhaps you could explain why the Excel files seem easier to work with, and we might be able to suggest ways to get that result by using the .csv-format data.

Best wishes,

Michael


> On 2/05/2016, at 05:18, Katrina Connell <katcon...@gmail.com> wrote:
>
> I ran an experiment and only saved the csv files since I thought that was what i wanted, but I now realize the excel sheets will be a lot easier for me to use so I would like to use the psydat file to recreate the xlsx files. I am trying to use part of the code above mixed with code for saving to create an xslx file from the psydat file, but I keep getting the error message AttributeError: 'ExperimentHandler' object has no attribute 'saveAsExcel'.
>
> I am pretty new to coding, so I just don't know what I need to add or change to get this code to save the excel files, not the csv files. I looked all over but haven't found anything. Any suggestions? The code I'm trying to use is below.
>
> Thanks
> Katrina

--
Michael R. MacAskill, PhD 66 Stewart St
Research Director, Christchurch 8011
New Zealand Brain Research Institute NEW ZEALAND

Senior Research Fellow, michael....@nzbri.org
Te Whare Wānanga o Otāgo, Otautahi Ph: +64 3 3786 072
University of Otago, Christchurch http://www.nzbri.org/macaskill

Katrina Connell

unread,
May 2, 2016, 10:57:05 AM5/2/16
to psychopy-users
   I already have a VBA excel macro that perfectly extracts and processes the data I want from the excel formatted data.  Personally, I think one of the major draws of the program is that it is user friendly and doesn't require a knowledge of coding to use, though it has the capability if you do have the necessary skills.  Removing the excel output feature would, in my opinion, make it difficult for people who want it to run simple experiments, where excel is more than sufficient.
    I use the csv outputs in most circumstances, but for this particular experiment the way the data is formatted in the excel file ended up being easier to work with.  The csv files stores a lot of unnecessary data for my purposes, and since it stores each loop in different columns, if there are a different number of blocks recorded for each participant,  when the data is concatenated it doesn't align properly.  It is also clunky for experiments with a lot of very short loops, such as mine.  This issue is not present in the excel files, where each block is stored in a seperate tab and so my macro easily concatenates everything and processes the data.  So in this case, working with the excel files is much easier for me. 

Katrina 

Michael MacAskill

unread,
May 2, 2016, 6:27:22 PM5/2/16
to psychop...@googlegroups.com
Hi Katrina,

You clearly know what you are doing from the Excel end, so the caveats with that format aren't going to trip you up…

I think the issue with that code is that it is four years old. Back then, I don't think the ExperimentHandler class existed. Jon added that to bundle up a collection of individual loops (e.g. TrialHandler objects) into a unified experimental object, to cater for more advanced designs.

i.e. back in 2012, I think loading a .psydat file instantiated a simple TrialHandler object, whereas now it creates an encompassing ExperimentHandler. The TrialHandler object has the SaveAsExcel method, but the ExperimentHandler doesn't.

I'm flying a bit blind here, but I think you could iterate over the individual TrialHandlers held within the ExperimentHandler and get them to save themselves in Excel format. e.g. something like:

# the ExperimentHandler has a .loops attribute:
for loop in dat.loops:
loop.saveAsExcel('somefilename.xlsx', appendFile=True)

Completely untested, your mileage may vary, refer to the API here: <http://www.psychopy.org/api/data.html>…

Good luck,

Michael
Reply all
Reply to author
Forward
0 new messages