How do i repeat trial? Seems like it should be an easy thing to do but I can't get it to work

I am new to psychoPy and I am so confused. This is a very simple experiment, I just need my trial to repeat six times. I inserted a routine (a 40 second video is played, beeps and an image pop out at random intervals) which displays just fine and then I insert a loop to repeat this routine six times in total. After some reading I saw that nreps is number of repeats of your conditions and not the number of repeats of my routine, hence I set this to 1. Then, from what I understood, you have to create six conditions but when I try to do this I get the following error

Traceback (most recent call last):
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\app\builder\dialogs\dlgsConditions.py", line 552, in onOK
    if not self.save():
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\app\builder\dialogs\dlgsConditions.py", line 609, in save
    pickle.dump(self.data, f)
TypeError: write() argument must be str, not bytes

I’ve also tried setting nreps to 6 and touching nothing else in the loop but that doesn’t do anything.

What am I doing wrong? It feels like this should be the easiest thing to do :confused:

Attached below is experiment file with nreps = 6

gligalab.psyexp (14.3 KB)

I’m not sure if this is the answer you are looking for, but creating blocks of trials might help you design an experiment where trials (not conditions) are set to be repeated. Please refer to this link:

Blocks of trials and counterbalancing

Thanks for responding, much appreciated. Unfortunately I’m extremely confused by the guide as it doesn’t do a great job explaining and makes jumps in what might be the knowledge level of the reader (and mine is low!). It’s also trying to create more complex methods from what I want to do. I just want my trial to repeat six times…

Dear Achilles,

create an Excelfile with one column named, for instance, moviestim. Enter a the name of your movie in the second row of this Excelfile. Edit your movie-component fantasia and set the property Movie file to $moviestim, change the setting from constant to set every repeat. In the trials loop, enter the Exelfile you created as condition file. Set Nreps to 6 and your movie will be displayed six times. You could also have six rows of movie file names in you Excelfile and set Nreps to 1.

BTW, it is advised to store your files (stimuli, Excel aso.) relative to your experiment file. You have been using absolute file names.

Best wishes Jens

1 Like

Dear Jens,

Thank you for your help and pointing me at the right direction. I’m slowly getting into the logic of Psychopy coding but it has been a struggle!

Edit your movie-component fantasia and set the property Movie file to $moviestim

Where is the property Movie file that i need to change into $moviestim ?Is that where the directory address to load up the movie? If i change it how will the programme know where to find the movie??

change the setting from constant to set every repeat

I’ve done this now

Set Nreps to 6 and your movie will be displayed six times.

I’ve done this now

enter the Exelfile you created as condition file .

I’m not really sure what to include in the condition file. The latest understanding now is that I create an excel document with the first row being the header and then in each subsequent row the name of the stimulus in the sequence that they are in my experiment builder UI, i.e., fantasia, playTone, displaychecker. Is this correct?

BTW, it is advised to store your files (stimuli, Excel aso.) relative to your experiment file. You have been using absolute file names.

I am not sure what you mean by this? Could you please explain?

Thank you for your help

Dear Achilles

Sorry, I that I was unclear in the some of my comments. You have to edit the movie-component that you have called fantasia. The movie-component has a property called Movie file. Change this to $moviestim and to set every repeat.

I have attached an example of an Excelfile.

Stimuli.xlsx (8.4 KB)

Notice, this assumes that the file Fantasia_Clip.mov is in the same directory as the experiment. The Excelfile should also be in the same directory as the experiment (*.psyexp). You could save your stimuli in an extra directory, e.g. movies. In this case change the line in your Excelfile from Fantasia_Clip.mov to movies/Fantasia_Clip.mov.

Columns that you add to your Excelfile are automatically stored in your result file. A column-header can be used as a variable your experiment.

Set the condition in your loop

grafik

nReps controls how often the movie is shown or how often your condition is repeated.

Best wished Jens

1 Like

gligalab.psyexp (14.5 KB)

I’ve followed your instructions but it results to errors trying to load up the excel file. I’ve now uploaded latest file.

Traceback (most recent call last):
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\app\builder\dialogs\__init__.py", line 1537, in viewConditions
    title=fileName, fixed=True)
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\app\builder\dialogs\dlgsConditions.py", line 159, in __init__
    _size = [len(str(self.grid[y][x])) for y in range(self.rows)]
  File "C:\Program Files\PsychoPy3\lib\site-packages\psychopy\app\builder\dialogs\dlgsConditions.py", line 159, in <listcomp>
    _size = [len(str(self.grid[y][x])) for y in range(self.rows)]
KeyError: 0

Much thanks for your help!

Hello Achilles

do you mind uploading the mov (a shortened version will probably do). and the condition-file (conditions.xlsx) you use in your experiment. Also please upload the checker.jpg.

Best wishes Jens

I’ve uploaded the files in my dropbox. Here is the link to download Dropbox - test - Simplify your life

Thansk for your help and I hope you enjoy the fantasia clip :slight_smile:

Hello Achilles,

here are the things I did.

  1. I changed the absolute path image='C:\\Users\\apavl\\Desktop\\gligalab\\checker.jpg', mask=None, to image = checker.jpg, It is most often better to use relative paths instead of absolute paths. :wink: When checker.jpg. is in the same directory as the experiment it will be found.

  2. I set the audio (Experiment Settings - Audio) to sounddevice. It might also run with pygame but it complained about the sound-parameter sec which you set to 0.2 sec.

Then the experiment ran locally, kind of. There were checkers and sounds only in first presentation but not later. I don’t know if this is intended.

Keep in mind that you rather should mp4 as a video-format for on-line experiments. Also it might be better to reduce the size of video with an extra program instead of having psychopy reducing it in size. The file gets smaller and is loaded faster.

conditions.xlsx (8.2 KB) gligalab.psyexp (14.4 KB)

Best wishes Jens

I changed the absolute path image='C:\\Users\\apavl\\Desktop\\gligalab\\checker.jpg', mask=None, to image = checker.jpg, It is most often better to use relative paths instead of absolute paths. :wink: When checker.jpg. is in the same directory as the experiment it will be found.

Great, I’ll do this from now on

I set the audio (Experiment Settings - Audio) to sounddevice . It might also run with pygame but it complained about the sound-parameter sec which you set to 0.2 sec.

I have now done this as well

Then the experiment ran locally, kind of. There were checkers and sounds only in first presentation but not later. I don’t if this is intended.

No, it is not. The nice thing is that the video is at least running more than once so that is progress! How can I repeat my audio and visual stimuli in conjunction with the video? Am I correct in thinking that I have to call them in the excel file for them to run? How would I call them? I’ve tried some combinations based on the

moviestim
Fantasia_Clip.mov

Column example in the excel document but no luck :confused:

Keep in mind that you rather should mp4 as a video-format for on-line experiments. Also it might be better to reduce the size of video with an extra program instead of having psychopy reducing it in size. The file gets smaller and is loaded faster.

Thanks will do this from now on :slight_smile:

Hello Achilles,

well, you have written quite some code to present the checker-board and the sounds. I do not know what you intend to achieve. It would help if you described what a trial would look like :wink:

Yes, you can “call” the checker-board and the sound from an Excel-file. Still this leaves the question when do you want to present them and how often?

Best wishes Jens

Hello Jens,

In the experiment the fantasia clip is played which last 40 seconds. During this time the checker pattern randomly appears for 100 ms every 2-4 seconds. In addition to the checker pattern an auditory beep appears every 6-10 seconds. Once fantasia clip finishes the trial is over. There should be 6 trial repetitions in total

Hello Achilles,

ok, you have set the clip to play for 40 seconds (duration = 40). Well, the clip is 40 seconds long but it takes some time to load it and to scale it to size. So, you might want to scale it yourself to the desired size to reduce lag and change format. The mp4-file is about half the size of the mov-file. With the duration setting of 40 seconds, the clip ended prematurely. In addition, you defined two if-constructions to end the routine. This is not necessary.

You need to reset the values of beep.playing, beep.waiting, checker.drawing and checker.waiting at the end of the routine. Your if-constructions did not seem to work in each repetition.Simply add beep.waiting = False aso. to the End Routine tab of the respective code-element.

Delete the code-part

# end the routine if the trial duration has been reached
if t > trialDuration:
    checker.drawing = False
    checker.waiting = False
    continueRoutine = False

and

# end the routine if the trial duration has been reached
if t > trialDuration:
    checker.drawing = False
    checker.waiting = False
    continueRoutine = False

The routine ends when the clip is finished and with the change to the End Routine tab, your variables are reset.

Best wishes Jens

1 Like

IT WORKED! Thank you so much for your help! Now that I get six trials I’ve got another issue that has popped up. Each time a trial runs, it replaces the recorded values of stimulus time from the previous trial. I need to have the values of each trial (checker and beep display times) saved. How would I go about doing this?

I imagine something needs to be changed in the

End routine for the checker and beep

thisExp.addData('checkerISIs', checkerISIs)
thisExp.addData('checkerOnsets', checkerOnsets)
checker.waiting = False

and in

thisExp.addData('beepISIs', beepISIs)
thisExp.addData('beepOnsets', beepOnsets)
beep.waiting = False

gligalab.psyexp (14.1 KB)

Hello Achilles,

what do you mean with stimulus time? The beepOnsets, beepISI, checkerOnsets and checkerISI are not replaced, at least not for me. This an extract from a datafile (beepOnsets only).

trial 1 [6.0160, 13.2401, 21.4648, 30.6908, 36.9137]
trial 2 [6.0213, 15.2472, 24.4734, 32.6978, 39.9214]
trial 3 [7.0229, 15.2478, 24.4737, 32.6984]
trial 4 [9.0158, 15.2391, 22.4631, 29.6865, 38.9127]
trial 5 [9.0116, 16.2354, 22.4585, 30.6829, 36.9057]
trial 6 [7.0171, 15.2416, 23.4665, 32.6926, 39.9168]

The values are similar but that is to be expected given randint(6,10) → 6,7,8,9,10

I did not touch the following

thisExp.addData('checkerISIs', checkerISIs)
thisExp.addData('checkerOnsets', checkerOnsets)

also not this

thisExp.addData('beepISIs', beepISIs)
thisExp.addData('beepOnsets', beepOnsets)

See the example Excel-File:

Achilles.csv (3.3 KB)

I save the data as *.csv not as *.xlsx-file. (Edit experiment settings, Data).

Best wishes Jens

1 Like

I fixed it by ticking ‘Is trials’ in trials properties. Yay! Thanks for all your help Jens, very much appreciated!

Hello Achilles,

that is an important tick :wink:

Best wishes Jens

1 Like