psychopy.org | Reference | Downloads | Github

Psychopy TrialHandler "customisation"

I’m trying to put together an experiment for use outside and ultimately inside the MR scanner.

I’ve thrown something together with the builder, and to get things started inserted a loop, with the conditions being read in from a .xlsx file. This part is working as expected. Unfortunately, the randomisation options can’t handle the weird trial selection scheme that we’re using, so I started to put something together by hand in python.

I now need to shoehorn this code into my builder “skeleton”. The question I have is sort of generic, in that psychopy keeps track of the experiment using a trial handler, which reads in the .xlsx file and would normally contain the names of the images to be presented. However, I need to specify my own image files and randomisation, which I think is best done dynamically with python. Is there a way to fool the TrialHandler into thinking it has control, when in fact it doesn’t?

At the moment I have 160 trials defined by my own randomisation, and have generated a “spoof” .xlsx file with 160 entries, so that two match…but this doesn’t seem very elegant. I guess this is mostly down to my lack of familiarity with the TrialHandler…

One of the reasons why I want to keep experiment/trial handlers running is because I need to know RT - and which option was chosen…

Hope this makes sense, any advice/suggestions would be much appreciated.

Jon

Why not just save your custom-defined trials to a .csv file and use that as the conditions file for the loop?

Yep - you’re right - I was toying with the idea of doing that, but then wondered if I could change the TrialHandler data structure directly instead? I think your way will be much simpler! Thanks…

Sorry, I didn’t realise you were coding the experiment rather than using Builder. Yes, in code, you can certainly just craft a trialList variable to pass to the TrialHandler when it is created, without needing to go to disk, as in the API here:

http://www.psychopy.org/api/data.html#psychopy.data.TrialHandler

The trialList should be a list of dicts.