Q: Iterations of trial loop

95 views
Skip to first unread message

saup...@gmail.com

unread,
May 9, 2016, 9:51:21 AM5/9/16
to psychopy-users
Dear PsychoPy group members,

I'm stuck with programming a Gating experiment in PsychoPy and hope that you'll be able to help me. I'm quite new to PsychoPy and this is the first time I'd like to use it for an experiment.

The general design of the experiment is like this: I'd like to know at which point in time people are able to predict the upcoming words in a sentence.

I use the Gating paradigm for this. The sentences were audio-recorded and cut into pieces and the participants will hear one of those pieces at a time and are then asked to indicate what they think how the sentence will continue (with a free text input). Each trial consists of playing all the audio files from each sentence one after the other. This is where it becomes tricky: The sentences are of different lengths, which means that there will also be differing numbers of audio files to play.

The "solution" that I came up with is this (but its not working): Inside the trial loop, I have an increments loop and its nReps is controlled by a variable in the conditions file (NIncrements). The audio file to be played at each repetition is defined by evaluating a list and taking the nth element of it (= number of the repetition).

After the instructions screen (press SPACE to advance), the experiment crashes. I get the following error message:

############ Running: C:\Users\ivs\Desktop\Gating\gating_lastrun.py ############
Unexpected error loading library avbin: 
pyo version 0.6.6 (uses single precision)
1.7471 ERROR avbin.dll failed to load.
                     Try importing psychopy.visual as the first library
                     (before anything that uses scipy)
                     and make sure that avbin is installed.
Traceback (most recent call last):
  File "C:\Users\ivs\Desktop\Gating\gating_lastrun.py", line 184, in <module>
    incrementsLoop = data.TrialHandler(nReps=NIncrements, method='sequential', 
NameError: name 'NIncrements' is not defined
Exception TypeError: "'NoneType' object is not callable" in <bound method Server.__del__ of <pyolib.server.Server object at 0x04F57F70>> ignored


It says that NIncrements is not defined, but it is defined in the conditions file. I attach all the necessary files to reproduce this problem.

Do you have any idea how this could be solved? (Or, ideally, how this could be programmed more elegantly)? I'd be very grateful for any advice.

Best regards,
Sebastian
Gating.zip

saup...@gmail.com

unread,
May 9, 2016, 9:59:39 AM5/9/16
to psychopy-users
What I forgot to add: I'm using PsychoPy v1.83.04 on Windows 10 and I put together the experiment in the Builder.

Michael MacAskill

unread,
May 9, 2016, 5:39:30 PM5/9/16
to psychop...@googlegroups.com
Hi Sebastian,

Welcome along.

What is happening is that you are referring to the variable "NIncrements" in the nReps file of a loop, but that variable is (currently) contained within the conditions file used to define the loop. i.e. "NIncrements" doesn't yet exist at the point at which you are trying to use it.

But this is OK, because you likely have your loops kind of reversed. The *outer* loop should be the one connected to the conditions file, because it will run once per row of that file (i.e. once per trial). The *inner* loop doesn't need to connect to the conditions file at all: it already knows about the variables it contains on each trial (including "NIncrements") because it is embedded within the encompassing outer loop.

i.e. the inner loop will run multiple times per row (and per trial), so you don't want it connected to the conditions file, or it would cycle through it too quickly.

Make sense?

Regards,

Michael

PS In the sound file field, you probably need a $ sign prefix, like this:

$eval(AudioFile)[incrementsLoop.thisN]
--
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

saup...@gmail.com

unread,
May 13, 2016, 5:02:14 PM5/13/16
to psychopy-users
Dear Michael,

thanks a lot for the quick reply. Your suggestions make a lot of sense. However, when I change everything accordingly and re-open PsychoPy, the experiment is broken. That is: The flow is deleted, all the routines are still there but in the flow there is only the first routine that I put there (instructions).

Failed to load C:\Users\ivs\Desktop\PsychoPy stuff\Gating\gating.psyexp. Please send the following to the PsychoPy user list
Traceback (most recent call last):

 
File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy-1.83.04-py2.7.egg\psychopy\app\builder\builder.py", line 4266, in fileOpen
   
self.exp.loadFromXML(filename)
 
File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy-1.83.04-py2.7.egg\psychopy\app\builder\experiment.py", line 471, in loadFromXML
   
exec('param.val=%s' %(param.val))#e.g. param.val=[{'ori':0},{'ori':3}]
 
File "<string>", line 1, in <module>
NameError: name 'nan' is not defined

I have no idea where the 'nan' comes from, ist also not in the script when I compile it and search for 'nan' there. The same happens when I open the experiment on a Mac, so it doesn't seem to be a Windows problem.

I've encountered another problem -- or maybe they are even related: When I try to add the Excel condition file to the outer loop I get the error "NameError: name 'audio' is not defined". I guess 'audio' in the error message refers to the subfolder that contains the stimuli.  However, when I add a CSV version of this, I don't get that error and I also can't see what might be wrong with the Excel file.

Do you or does anyone on the list know what the problem(s) could be here?

Thanks a lot for your help in advance!
-- Sebastian
gating.zip

saup...@gmail.com

unread,
May 13, 2016, 5:09:48 PM5/13/16
to psychopy-users
I attached the wrong files. Here are the right ones that give this 'nan' error.
gating.zip

Michael MacAskill

unread,
May 15, 2016, 7:16:51 PM5/15/16
to psychop...@googlegroups.com
Dear Sebastian,

The issue here is that '.CSV' stands for "comma-separated values". Your .csv file contains cells that contain content like this:

[audio/birdmanhead_0.wav,audio/birdmanhead_1.wav,audio/birdmanhead_2.wav]

i.e. they contain commas, so when being imported, it seems like there are more than your three specified columns (i.e. the cell above looks like it actually contains values for three cells rather than one). This means that the .csv importer gets confused, as some rows will have different numbers of columns, with some cells appearing blank, with no header name.

The importer we use should be more robust to this (blank cells leads to 'nan' values, meaning 'not a number'). This bug has been noted here but not yet addressed:
<https://github.com/psychopy/psychopy/issues/1147>
i.e. you should get a more obvious error, and not lose the apparent structure in your file (the loops are still there, but Builder isn't displaying them).

But a quick work-around for you here is to simply wrap those cells in quotes, so that the commas get ignored, e.g.
"[audio/birdmanhead_0.wav,audio/birdmanhead_1.wav,audio/birdmanhead_2.wav]"

Or alternatively use an xlsx file instead of csv.

I've attached repaired .csv and Builder .psyexp files for you.

Regards,

Michael
> --
> You received this message because you are subscribed to the Google Groups "psychopy-users" group.
> 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/msgid/psychopy-users/5fed3576-38aa-436d-93e4-efef89990f51%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
> <gating.zip>
gating copy.psyexp
gating_conditions2.csv

saup...@gmail.com

unread,
May 19, 2016, 4:51:45 AM5/19/16
to psychopy-users
Dear Michael,

thank you very much for your reply. The CSV issue is evident and I should have seen this, too. The issue that the components were not shown in the flow any longer is also gone now.

Unfortunately, the script still doesn't run as intended, there is still a problem with the eval() expression that selects the actual audio file to be played in every repeat of the inner loop.

When I use $eval(AudioFiles)[incrementsLoop.thisN], I get this error message:

#### Running: C:\Users\ivs\Desktop\PsychoPy stuff\Gating\gating_lastrun.py #####

Unexpected error loading library avbin:
Traceback (most recent call last):

 
File "C:\Users\ivs\Desktop\PsychoPy stuff\Gating\gating_lastrun.py", line 211, in <module>
    sound_0
.setSound(eval(AudioFiles)[incrementsLoop.thisN], secs=-1)

 
File "<string>", line 1, in <module>
NameError: name 'audio' is not defined


When I use eval(AudioFiles)[incrementsLoop.thisN], I get this one:

#### Running: C:\Users\ivs\Desktop\PsychoPy stuff\Gating\gating_lastrun.py #####

Unexpected error loading library avbin:
Traceback (most recent call last):

 
File "C:\Users\ivs\Desktop\PsychoPy stuff\Gating\gating_lastrun.py", line 211, in <module>
    sound_0
.setSound(u'eval(AudioFiles)[incrementsLoop.thisN]', secs=-1)
 
File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy-1.83.04-py2.7.egg\psychopy\sound.py", line 146, in setSound
   
raise ValueError, "setSound: could not find a sound file named " + value
ValueError: setSound: could not find a sound file named eval(AudioFiles)[incrementsLoop.thisN]

I see that the problem with the second one is that PsychoPy thinks that "eval(AudioFiles)[incrementsLoop.thisN]" is the string that names the audio file. However, I don't understand what the problem with the first one could be. Is there maybe something wrong with "[incrementsLoop.thisN]"? I took this from an answer to a similar problem that you posted on stackoverflow (http://stackoverflow.com/questions/32255291/variable-trial-conditions-in-psychopy).

I also used the CSV conditions file because when I try to import the Excel file, I get the following error:

Traceback (most recent call last):

 
File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy-1.83.04-py2.7.egg\psychopy\app\builder\builder.py", line 3109, in onBrowseTrialsFile
    returnFieldNames
=True)
 
File "C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy-1.83.04-py2.7.egg\psychopy\data.py", line 2043, in importConditions
    val
= eval(val)

 
File "<string>", line 1, in <module>
NameError: name 'audio' is not defined

I guess there is also something wrong with the XLSX file, but I can't see what it is.

I apologise for these many questions; however this helps me a lot to learn about PsychoPy.

Regards,
Sebastian






gating.zip

Michael MacAskill

unread,
May 19, 2016, 5:54:24 PM5/19/16
to psychop...@googlegroups.com
Hi Sebastian,

I've lost track of this. To avoid digging through all the previous e-mails, could you give the details of just this particular problem, i.e. what should:

> eval(AudioFiles)[incrementsLoop.thisN]

evaluate to?

What is "AudioFiles"? What is "audio"?

Cheers,

Michael
> --
> You received this message because you are subscribed to the Google Groups "psychopy-users" group.
> 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/msgid/psychopy-users/370aae57-63ee-41c6-b2fd-36ac2b4d84bf%40googlegroups.com.

saup...@gmail.com

unread,
May 24, 2016, 3:24:03 AM5/24/16
to psychopy-users
Sure. The purpose of the experiment is to play a series of audio files that are increments of sentences, i.e. each time the participants hear one word more or so. Because the sentences (= items) are of different lengths, there are also different numbers of audio files to play for each sentence.

There are two loops. The outer one, (trialLoop) is connected to the conditions file and the inner one (incrementsLoop) plays the audio files. The conditions file has a variable NIncrements that specifies how often the inner loop should run. The expression eval(AudioFiles)[incrementsLoop.thisN] selects the current audio file to-be-played from the conditions file. The names of the audio files are stored in a list in the variable AudioFiles in the condition file.

What "audio" is I don't know. The routine is called audio0 and when I search the script for "audio" I only find instances of "AudioFiles" and "audio0". Is maybe the problem that the routine is called "audio0"?

I hope this is sufficiently clear. :)

Thanks a lot for the help!

Regards,
Sebastian
Reply all
Reply to author
Forward
0 new messages