difference beterrn exp.addData() and trials.addData()

751 views
Skip to first unread message

mhfh...@gmail.com

unread,
Oct 31, 2013, 4:46:21 AM10/31/13
to psychop...@googlegroups.com
Hi,

What's the difference between exp.addData() and trial.addData() in the following script? They seem to be doing exactly the same thing.

from psychopy import visual,data,event,core

letters = [u'a',u'b',u'c']

win = visual.Window()
Letter = visual.TextStim(win)

timer = core.Clock()

exp = data.ExperimentHandler(dataFileName='exp')
trials = data.TrialHandler(letters, dataTypes=['letter','key','rt'])
exp.addLoop(trials)

for letter in trials:

    Letter.setText(letter)
    Letter.draw()
    event.clearEvents()
    win.flip()
    timer.reset()
    core.wait(1, hogCPUperiod=1)

    key = event.getKeys(timeStamped=timer)
  
    trials.addData('letter', letter) #OR exp.addData('letter', letter)
    trials.addData('key', key) #OR exp.addData('key', key)

    exp.nextEntry()

win.close()


Are there situations where one should be used instead of the other?

Thanks!

Max

Michael MacAskill

unread,
Oct 31, 2013, 4:54:39 PM10/31/13
to psychop...@googlegroups.com
Hi Max,

Practically, not very much difference I suspect. The TrialHandler has been around in PsychoPy since the early days, whereas the ExperimentHandler was a later addition. So the TrialHandler was originally designed to stand on its own feet, whereas now it will more typically have a parent ExperimentHandler. So there can be a little overlap between their functions, which may not have occurred if they had been developed by Jon at the same time.

I suspect you might find that the variables wind up in a slightly different order in the resulting .csv data file?

If in doubt, check for any differences in the output depending on which you use. i.e. switching between them during the course of a study might make for .csv files which aren't "column compatible". Just a suspicion: would be interested to hear if that is the case.

Regards,

Michael

Jonathan Peirce

unread,
Nov 1, 2013, 1:18:29 PM11/1/13
to psychop...@googlegroups.com
Michael is exactly right. ExperimentHandler came later and any data
received by a loop (TrialHandler) is passed on to the experiment, so
it's stored in both. But the ExperimentHandler can technically store
additional data, including things that occurred before or between loops.

For the standard csv output these things will be almost
indistinugishable. But if you save out to an xlsx file, for example,
that stores data according to loops, with one worksheet for each loop in
the experiment. Data saved using exp.addData() won't be included in that
output because the experiment doesn't know which loop it belongs to.

In your example the data does make sense in terms of the trials loop, so
I would attach it to that and the exp will automatically receive a copy.

cheers,
Jon
--
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.




mhfh...@gmail.com

unread,
Nov 2, 2013, 4:25:40 PM11/2/13
to psychop...@googlegroups.com
Hi Mike and Jon,

Many thanks for the info! I think I got the difference now.

Max
Reply all
Reply to author
Forward
0 new messages