NBS Presentation and PsychoPy not agreeing

Hi. I’m using standalone PsychoPy version 3.0.0b9 on W10, and I’m trying to re-write an experiment that I have previously made in NBS Presentation in PsychoPy.

The experiment involves, on some trials, the presentation of a stimulus that quickly blinks off at the start and returns for the remainder of the trial (about 2700 ms, but that’s not important). I achieved this before by overlaying a background-coloured square on top of the image 150 ms after the presentation onset, followed by its removal 150 ms later. In the NBS Pres. version of the task, it works fine and you clearly see the blink shortly after the image was presented. However, when I remade it in the same way in PsychoPy you can’t see any blinking at all. At first I thought I was making a mistake but was getting no error. Then when I increased the latency and duration of the background-coloured mask rectangle it was observable if I presented it for 300 ms.

My question is whether anyone knows why I would get such a discrepancy between the two versions? I’m quite sure the NBS Presentation version is correct and presenting as it should be. I am using the same laptop for both, so it can’t be a difference in hardware that makes the event display incorrectly so it is simply a difference in software. I really would like to keep the same parameters as I have in NBS Pres. Failing that, I’d at least like to figure out why there’s a difference!

Any assistance is appreciated.

Apologies, I realised what the problem was and it seems to be solved now: I was defining the onset and duration of the masking rectangle in terms of seconds (onset 0.15 s and duration 0.15 s), whereas PsychoPy prefers this as Frame N: onset frame 9 for duration of 9 frames.

I’ll leave this here for a while then maybe we can just delete this post.

You’ve probably found an important issue here. It takes time to load an image from disk and then get it ready for display. There is a quirk in the way that Builder generates the experimental script that I think can make it possible for the image to not yet be ready for display if the times are specified in seconds, but if specified in terms of frames, then there might a delay while the image is loaded but it will then be guaranteed to be displayed for the specified duration. Either way, you might not be getting the times you want.

If possible, you should be pre-loading the image, so that it is sure to ready for display at the time desired, no matter how you specify that time. e.g. you can specify that it is loaded during a fixation period, for example, prior to the onset of the stimulus. This is done by inserting a “static period” from the custom components pane, and then referring to the name of that static period as the time when the image file should be updated (i.e. it will then be available in the popup menu next to the image field, in addition to the normal “each routine”, “constant”, etc options.

i.e. you should ideally load images at a non-time critical part of your experiment, rather than assume that they will be instantly available at the time that they are needed.

Thanks for the point in the right direction, I think it actually makes a lot of sense to preload stimuli like that. I had no idea this was possible. However it doesn’t seem to work for me, so I wonder if you can help me figure out why.

I have my trial loop that contains both an ITI screen followed by a main trial screen. (I keep them as separate events within the loop, so maybe this is the issue?) Anyway, I inserted the static component during the ITI, and then set the stimulus contained in the trial screen to “set during: ITI_trial.PRELOAD”. PsychoPy now won’t run the experiment, and I get the following error:

Traceback (most recent call last):
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\app\builder\builder.py", line 2012, in runFile
    self.generateScript(fullPath)  # Build script based on current version selected
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\app\builder\builder.py", line 2237, in generateScript
    psyexpCompile.compileScript(infile=self.exp, version=None, outfile=experimentPath)
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\scripts\psyexpCompile.py", line 58, in compileScript
    script = thisExp.writeScript(outfile, target=targetOutput)
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\experiment\_experiment.py", line 140, in writeScript
    self.flow.writeBody(script)
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\experiment\flow.py", line 254, in writeBody
    entry.writeMainCode(script)
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\experiment\routine.py", line 168, in writeMainCode
    event.writeFrameCode(buff)
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\experiment\components\static\__init__.py", line 101, in writeFrameCode
    self.writeStopTestCode(buff)
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\experiment\components\static\__init__.py", line 131, in writeStopTestCode
    self.writeParamUpdates(buff)
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\experiment\components\static\__init__.py", line 159, in writeParamUpdates
    prms = self.exp.getComponentFromName(bytes(compName)).params
TypeError: string argument without an encoding
Traceback (most recent call last):
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\app\builder\builder.py", line 2012, in runFile
    self.generateScript(fullPath)  # Build script based on current version selected
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\app\builder\builder.py", line 2237, in generateScript
    psyexpCompile.compileScript(infile=self.exp, version=None, outfile=experimentPath)
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\scripts\psyexpCompile.py", line 58, in compileScript
    script = thisExp.writeScript(outfile, target=targetOutput)
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\experiment\_experiment.py", line 140, in writeScript
    self.flow.writeBody(script)
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\experiment\flow.py", line 254, in writeBody
    entry.writeMainCode(script)
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\experiment\routine.py", line 168, in writeMainCode
    event.writeFrameCode(buff)
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\experiment\components\static\__init__.py", line 101, in writeFrameCode
    self.writeStopTestCode(buff)
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\experiment\components\static\__init__.py", line 131, in writeStopTestCode
    self.writeParamUpdates(buff)
  File "C:\Program Files (x86)\PsychoPy3\lib\site-packages\psychopy\experiment\components\static\__init__.py", line 159, in writeParamUpdates
    prms = self.exp.getComponentFromName(bytes(compName)).params
TypeError: string argument without an encoding

Ooh, this looks like deep magic. I’m not used to seeing errors that arise in actually generating the experiment code, they are very rare (and indicate the problem is with PsychoPy, not you).

Hi @dvbridges do you know about this? I seem to be able to duplicate an error in compiling a .py file simply by having a static period referred to in the “update” popup menu of the image field of an image component, but the error is slightly different:

Welcome to PsychoPy3!
v3.0.0b6
Traceback (most recent call last):
  File "/Applications/PsychoPy3_PY3.app/Contents/Resources/lib/python3.6/psychopy/app/builder/builder.py", line 2198, in compileScript
    self.generateScript(fullPath)
  File "/Applications/PsychoPy3_PY3.app/Contents/Resources/lib/python3.6/psychopy/app/builder/builder.py", line 2237, in generateScript
    psyexpCompile.compileScript(infile=self.exp, version=None, outfile=experimentPath)
  File "/Applications/PsychoPy3_PY3.app/Contents/Resources/lib/python3.6/psychopy/scripts/psyexpCompile.py", line 47, in compileScript
    script = thisExp.writeScript(outfile, target=targetOutput)
  File "/Applications/PsychoPy3_PY3.app/Contents/Resources/lib/python3.6/psychopy/experiment/_experiment.py", line 144, in writeScript
    self.flow.writeBody(script)
  File "/Applications/PsychoPy3_PY3.app/Contents/Resources/lib/python3.6/psychopy/experiment/flow.py", line 252, in writeBody
    entry.writeMainCode(script)
  File "/Applications/PsychoPy3_PY3.app/Contents/Resources/lib/python3.6/psychopy/experiment/routine.py", line 168, in writeMainCode
    event.writeFrameCode(buff)
  File "/Applications/PsychoPy3_PY3.app/Contents/Resources/lib/python3.6/psychopy/experiment/components/static/__init__.py", line 101, in writeFrameCode
    self.writeStopTestCode(buff)
  File "/Applications/PsychoPy3_PY3.app/Contents/Resources/lib/python3.6/psychopy/experiment/components/static/__init__.py", line 131, in writeStopTestCode
    self.writeParamUpdates(buff)
  File "/Applications/PsychoPy3_PY3.app/Contents/Resources/lib/python3.6/psychopy/experiment/components/static/__init__.py", line 159, in writeParamUpdates
    prms = self.exp.getComponentFromName(bytes(compName)).params
TypeError: cannot convert 'Param' object to bytes

I wonder if you’ve got any clues what might be causing this. Odd that it hasn’t been reported before. Makes me worry that people aren’t using this feature as often as they should be…

Hi @Michael, looks like this was fixed very recently in https://github.com/psychopy/psychopy/pull/2124

Ok, thanks both. I updated to the latest version (3.0.0b12) but the issue persists.

Also just in the name of pointing out issues, when I delete the static component after assigning the stimulus to update according to that, I can no longer open the stimulus object to set it back to “set every repeat”.

Thanks David, nice spotting.

It looks like it’s been fixed in the Github repository but that won’t take effect until the next release. This shouldn’t be too far away, but in the meantime, you could apply this fix to your own local copy of PsychoPy. As described in the pull request here:

It’s just a change to single line of the code in this file inside your PsychoPy application:

psychopy/experiment/components/static/__init__.py

That would mean the fix would work for you locally as soon as you restart PsychoPy.