saving data

669 views
Skip to first unread message

Mickael Le Gal

unread,
Apr 11, 2011, 10:05:47 AM4/11/11
to psychopy-users
Hi,

I'm a beginner with PsychoPy and I was wondering if there was a way to
save data (in an excel or text file) before an experiment ends, after
each trial for instance?

My fear is that, if the subject quit in the middle of the experiment
or if the software crashes for any reason, I won't be able to recover
anything from it.

Is there a simple command line to do that?

Thank you very much for your help.

Best,

Mickael

Jonathan Peirce

unread,
Apr 11, 2011, 11:48:53 AM4/11/11
to psychop...@googlegroups.com
If you're writing scripts (e.g. in Coder) then yes, you can either use
the save commands from the Stair/TrialHandler:

http://www.psychopy.org/api/data.html#psychopy.data.TrialHandler.saveAsExcel

http://www.psychopy.org/api/data.html#psychopy.data.TrialHandler.saveAsPickle
If you save at the end of each trial you probably want to set
appendFile=False to overwrite (or by the last trial you'll have written
the first trial outcome many times!)

You can also use the logging functions to send a log message at the end
of each trial. That would carry less overhead than writing an excel file
repeatedly, so might be better. See the coder demo on logging for that.

I always add a function to shut down the experiment (e.g. when subjects
press 'q') and I normally include saving data in that shutdown routine.

best wishes,
Jon

--
Dr. 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.

Andre Gouws

unread,
Apr 12, 2011, 12:20:34 PM4/12/11
to psychop...@googlegroups.com
While psychopy probably provides some nice functionality to do this,
you could use basic python commands to this very easily.

on each stimulus loop, after your particpant has responded, simply
write the trial number, stim params and response (even time) out to a
defined file: something like:

#define all your stimuli....

#now loop through your stim list
for i in range(1,100):
#show a stim with psychopy
stim.draw()
win.flip()
#wait for a response
while response == 'None':
#wait
#now you have a response

f = open('mylogfile.txt','a') #open a named file in 'append' mode
f.write('the things I want written to the logfile')
f.close()


I can rattle together a real example if you like.

good luck

Andre'

> --
> You received this message because you are subscribed to the Google Groups "psychopy-users" group.
> To post to this group, send email to psychop...@googlegroups.com.
> To unsubscribe from this group, send email to psychopy-user...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/psychopy-users?hl=en.
>
>

Jonathan Peirce

unread,
May 29, 2011, 2:29:36 PM5/29/11
to PsychoPy Users, mickae...@gmail.com
To be honest, I haven't tried to create a Go/No-go task before in
builder (I assume you're using builder) and I don't know off the top of
my head how to make this work. For now it might require a custom code
component to handle the case that there was no response - i'm not sure
how that would get handled currently. When it crashes, was there a message?

Jon

On 27/05/2011 16:59, Mickael Le Gal wrote:
> Dear Jon,
>
> I'm currently running a kind of Go/No-Go experiment with psychopy and
> I'm struggling to tell psychopy that not pressing any key when the
> screen displays a No-Go cue is the right answer. Ultimately that
> causes some problems when the data are saved into the excel file.
>
> Is there anything I should do with the Excel file? Is there something
> I should add to the "allowedKeys"? Do you know a good trick to solve
> this problem?
>
> I also want to randomize the duration of each cue so I created a
> column in the excel file with random numbers and made it correspond
> with the builder. This works pretty fine when the screen displays a Go
> cue but somehow crashes when a No-Go signal appears. Is there you
> would suggest me to do?


>
> Thank you very much for your help.
>
> Best
>

Reply all
Reply to author
Forward
0 new messages