psychopy.org | Reference | Downloads | Github

Problem with IoHub datastore while using ioHubExperimentRuntime class

Hello,

I am having trouble with understanding/implementing the ‘addRowToConditionVariableTable(data)’ method
under the ‘IoHubConnection’ class.

Basically, my experiment loops through 4 trials and presents images that either contain a target object, or do not, and then measuring the subject’s confidence level as to whether the object was present or not in the image.

my experiment uses the ioHub framework by extending the ioHubExperimentRuntime class and implementing the run() method.

The logic flow of my experiment process:
conditionsToBeSeen = [dictionaries…]
trials = data.TrialHandler(conditionsToBeSeen, 1, method = ‘random’)
self.hub.createTrialHandlerRecordTable(trials)
t = 0
for thisTrial in trials:
.
flip_time = win.flip()
thisTrial[‘session_id’] = self.hub.getSessionID()
thisTrial[‘trial_id’] = t +1
thisTrial[‘Trial_start’] = flip_time
.
.
.
.
while rating.noResponse:
rating.draw()
win.flip()
thisTrial[‘response’] = rating.getRating()
self.hub.addRowToConditionVariableTable(list(thisTrial.values()))

for display purposes, the first list below depicts a dictionary the trialHandler uses at the beginning of the experiment. Lists two-four show the trialhandler dictionary at the end of each successive loop (or trial), with the added key:value pairs.

I think the problem may have to do with the mutability of the trial handler object as the trials progress from beginning to end and I add key:value pairs to the trial handler instance.

Error messages shown below:
()

Running: C:\Users\lab-admin\Desktop\experiment1RuntimeClass\Experiment1withRuntimeClass.1.0.py

[0, u’\0_target.png’, ‘Marker’, ‘target’]

[2, 70.89741324947681, u’\2_absent.png’, ‘Shovel’, 3, 3, 8, ‘absent’]

[3, 77.6787006490631, u’\3_target.png’, ‘Trashcan’, 3, 3, 6, ‘target’]

[1, 84.62616181967314, u’\1_absent.png’, ‘Mouse’, 3, 3, 3, ‘absent’]
<type ‘exceptions.ValueError’>
ValueError(‘size of tuple must match number of fields.’,)
[’ File “C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy\iohub\datastore\init.py”, line 434, in _addRowToConditionVariableTable\n np_array= N.array([tuple(data),],dtype=self._EXP_COND_DTYPE)\n’]
<type ‘exceptions.ValueError’>
ValueError(‘size of tuple must match number of fields.’,)
[’ File “C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy\iohub\datastore\init.py”, line 434, in _addRowToConditionVariableTable\n np_array= N.array([tuple(data),],dtype=self._EXP_COND_DTYPE)\n’]
<type ‘exceptions.ValueError’>
ValueError(‘size of tuple must match number of fields.’,)
[’ File “C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy\iohub\datastore\init.py”, line 434, in _addRowToConditionVariableTable\n np_array= N.array([tuple(data),],dtype=self._EXP_COND_DTYPE)\n’]
<type ‘exceptions.ValueError’>
ValueError(‘size of tuple must match number of fields.’,)
[’ File “C:\Program Files (x86)\PsychoPy2\lib\site-packages\psychopy\iohub\datastore\init.py”, line 434, in _addRowToConditionVariableTable\n np_array= N.array([tuple(data),],dtype=self._EXP_COND_DTYPE)\n’]
ioHub Server Process Completed With Code: 0

I would appreciate any constructive feedback!

Thanks!

I struggled a bit with the post above but I suspect the problem is that the ioHub data store isn’t as flexible as the TrialHandler with adding new data fields. Basically, all the data fields you want to store need to be specified at the createTrialHandlerRecordTable() stage. You can’t add new ones later, as you can with the TrialHandler. i.e. ioHub populates the fields in its table with the initial state of the TrialHandler that gets passed to it. It doesn’t have any way of noticing subsequent changes to keys in the TrialHandler’s list of dictionaries.

To get around the issue, just populate your initial conditions with blank values for a given variable name (i.e. either use a conditions file with a header for a column which contains no values, or if using dictionaries, a key with some null or placeholder value).

Hi Michael,

I will make sure to follow the convention of surrounding python code with backticks in future posts.

I tried your method of initializing the conditions in the beginning, or before I loop through my trials. I used gibberish as the placeholder value in my key:value pairs within the dictionaries contained in the trialhandler object. Now the ioHUb datastore operates properly.

Thanks!

1 Like