Re: [psychopy-users] Nested loops for block design

1,095 views
Skip to first unread message

Chris Cox

unread,
Jan 15, 2013, 10:16:13 AM1/15/13
to psychop...@googlegroups.com
Hey Niko,

Just as you are not familiar with coding in python, I am unfamiliar with the builder.  However, what you are saying sounds to be on track.  I don't think you'd be too out in left field if you tried that, even if it failed.  By that time someone who knows better than I might reply.

Just to throw it out there, there are a couple ways you could think about doing this in code.  I think you'll see that they are conceptually similar to what you proposed doing in the builder, but allow you to extend those (probably basic) capacities.

In the simplest form, you might have a list of stimuli for each inner loop, that you could read from the hard drive.  You then have a list in the program, and each element of that list is the path to one of those files.  You could shuffle the list, iterate over it, and read in the stimulus lists one at a time.  This will work if all of the stimuli are presented in roughly the same paradigm. 

Slightly more sophisticated, you could use dictionaries.  Dictionaries store data in key:value pairs, and the values can be anything (even another dictionary).  So, you could set of a dictionary keyed by condition names, and stimulus lists as values.  Or you could nest dictionaries---the outer dictionary would be keyed by condition name, and the inner dictionaries could be keyed by condition attributes. Maybe something like 
OuterLoop = {
  'ConditionA': 
    {'stimlist':[ ... ], 'instructions':" ... ", 'positions': [(x,y) ... ]}, 
  'ConditionB': 
    {'stimlist':[ ... ], 'instructions':" ... ", 'positions': [(x,y) ... ]}
}

for stim in OuterLoop['ConditionA']['stimlist']:
  ...
Would loop over the stimlist for ConditionA for example.

The next option is a considerable jump in complexity, but I'll just mention it for the sake of planting the seed of what is possible. You could implement your experiment as a class, which you can initialize and then call conditions as sub-methods.  This gives you the ultimately flexibility.  Each condition might be a completely different paradigm---you don't have to loop each condition's stimuli list through the same code for presenting stimuli. You can call the conditions in any arbitrary order, because each condition's code is encapsulated.  I did this for a project once---an implementation of a battery of tasks to be completed with young children where restarting, pausing, backing up, and potentially jumping around were all desirable features.

HTH,
Chris


On Tue, Jan 15, 2013 at 8:32 AM, Niko Bubalo <cox...@googlemail.com> wrote:
Hi everyone,

I jus started using Psychopy and have no experience what so ever with Python, which is why I am using the Builder interface on v1.75.01.
The goal is to have multiple randomly ordered blocks of stimuli and every block uses a unique set of stimuli which are also shuffled within the block.

Using nested loops, the inner loop should only randomly iterate through the given set of stimuli, while the outer loop defines the order of the stimuli-sets to be used by the inner loop.
As far as I understood this means that i have to define the conditionsFile of the inner loop as a variable which is defined in the conditionsFile of the outer loop.
This would result in a large number of condition files of which one would have only one parameter containing the names of the other condition files.

So my question is: "Am I on the right track or is there something wrong with that line of thought? And is there a simpler and/or more sophisticated way that maybe only needs one conditions file in total?"

Thanks a lot and best regards,
Niko

--
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.
To view this discussion on the web visit https://groups.google.com/d/msg/psychopy-users/-/jO7UEQBCMyYJ.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Jonathan Peirce

unread,
Jan 15, 2013, 10:14:48 AM1/15/13
to psychop...@googlegroups.com
You would have one xlsx file for each block. Then an outer loop would
have a single xlsx file with one line per block, specifying the name of
the inner loop conditions files.

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.

shark_scott

unread,
Feb 16, 2013, 11:39:51 PM2/16/13
to psychop...@googlegroups.com
Hi,
    I was playing around with a similar experiment design and got the multiple xlsx files you mention.  I was wondering (if it's easy to implement) if it wouldn't be an idea to have a check box on the loop dialogue box asking whether the loop defines trials.  Then have all loops that DO define trials write to a single xlsx file and those loops that DON'T define trials (i.e. are being used to organize block/condition ordering) would not have their own xlsx files.  That way, at the end of the experiment there would be a single date file containing a line from each trial, and there would be no "empty" xlsx files.  This would be easier for analysis and data maintenance.
    I suppose another way to implement it that would not require input from the user is to have only the lowest loop in any nesting write a line to a data file.
    Again, I have no idea if the suggestion is easy to implement or if people would prefer things that way, just thought I'd toss the idea out there.
    Thanks!
    Mark

Jonathan Peirce

unread,
Feb 17, 2013, 5:12:32 AM2/17/13
to psychop...@googlegroups.com
I'd recommend moving away from the xlsx (summarised) data file altogether and switch to the trial-by-trial csv file instead. That results in a single file that incorporates data from all levels of all loops stored in a chronological order. Does it fix what you need?

Jon
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/msg/psychopy-users/-/ihJxJyp3VBIJ.

For more options, visit https://groups.google.com/groups/opt_out.
 
 
-- 
Jonathan Peirce
Nottingham Visual Neuroscience

shark_scott

unread,
Feb 17, 2013, 9:55:04 AM2/17/13
to psychop...@googlegroups.com
Hi,
    Yes, that's exactly what I need.
    Thanks!
    Mark
Reply all
Reply to author
Forward
0 new messages