psychopy.org | Reference | Downloads | Github

Saving xy-coordinates of eyetracker to outfile with iohub

I am doing an experiment on reading. Participants need to focus on a fixation dot for 800 ms, then a word is shown in the periphery (onset of stimulus presentation = start time). Upon recognition, participants press spacebar, the word stimulus dissappears and participant reads the word out loud. The difference between the timepoint of pressing the spacebar and start time is the reaction time for recognition.

I am using an Eyelink 1000 for measuring the 800ms fixation.
This is the code I use for connecting with the eyelink 1000, in a file called input.py, defining all input:

if self.input_type is EYETRACKER:
    
            iohub_tracker_class_path = 'eyetracker.hw.sr_research.eyelink.EyeTracker'
            eyetracker_config = dict()
            eyetracker_config['name'] = 'tracker'
            eyetracker_config['model_name'] = 'EYELINK 1000 DESKTOP'
            eyetracker_config['runtime_settings'] = dict(sampling_rate=1000,
                                                    track_eyes='RIGHT')

            io = launchHubServer(**{iohub_tracker_class_path: eyetracker_config})
     
            # Get some iohub devices for future access.
            self.tracker = io.devices.tracker
         
            # run eyetracker calibration
            r = tracker.runSetupProcedure()

In a seperate study.py file I have my experiment routine. There I write an outfile containing condition, stimulus word and reaction time.

def exit_experiment():
    
    with open( os.path.join( os.getcwd(), 'results_' + datetime.datetime.now().strftime( '%Y%m%d_%H%M' ) + '.csv' ), 'w+' ) as outfile:
        
        outfile.write( 'test_type,word,reaction_time\n' )
        
        for result in results:
            outfile.write( ','.join( result ) + '\n' ) 

However, addtionally to condition, stimulus word and reaction time, I would like to save all the x,y coordinates of a participant’s gaze between start time and reaction time of a certain trial as well.

So, these are my questions:

  1. Can ioHub save x y coordinates of a participants gaze?
    Because now, the coordinates aren’t saved at all.
  • If so, how can I implement this in my code?
  • If so, where can I define the location of the saved file?
  1. Can these x,y coordinates easily be coupled to the corresponding word stimulus?
  2. Is it possible to only save the x, y coordinates between stimulus onset and reaction time?

I hope these questions aren’t too silly, but it’s the first time I am using an eyetracker.
Thank you for your feedback.

Koen

Hi Koen,

I think if you specify an experiment_code in the call to launchHubServer(), then ioHub will save all data for you in an HDF file, using that code as the base for the filename. The data will be stored at 1000 Hz. You can start and stop recording at specified points using eyetracker.setRecordingState(True).

If you want to collect the data yourself, you can do that in PsychoPy by storing the current gaze position, but usually that will limit you to the frame rate of the screen, so will typically be at just 60 Hz.

http://www.isolver-solutions.com/iohubdocs/iohub/api_and_manual/iohub_process/launchHubServer.html

Thank you a lot, Michael. Data is stored now in a hdf5-file indeed. However, is there any way how I can couple the saved x y coordinates to my stimuli afterwards? Do you have any advice on how this is usually done?

Best regards,
Koen

Sorry, can you re-express that a bit more precisely?

Definitely. The gaze coordinates are written to this hdf5 file. During my experiment words are presented. Is there a way to link the x y coordinates in the hdf5 file to the time period during which a certain word stimulus is shown in my experiment? I hope that this is more clear. It is important for me to know where the participant was looking during the whole exposure time of a word stimulus. So, I would like to know the x y coordinates of the gaze during the duration of a stimulus. Also, I need to be able to identify the word, because if during the presentation of a word a participant’s gaze is too much out of a certain region, the trial needs to be deleted.

Try this:
https://groups.google.com/d/msg/psychopy-users/TNPaoptsMCU/ZHKAhdfcFAAJ

Note that ioHub needs to know the names of variables in advance (unlike when using the TrialHandler in PsychoPy, where we can add data to new variables at any time). So if you want to store, say, the time of onset of a stimulus, put an empty column in your conditions file, just containing the name of the variable in the top row. Then you can add a value to that variable on each trial and it will get stored in the HDF file.

Also note Sol Simpson’s next message in that thread, where he talks about directly inserting messages in the HDF file like this:

# send iohub an experiment message event
# that will have a timestamp equal to the current 
# psychopy.core.getTime()
io.sendMessageEvent("STIM ONSET")
 
# If you want to use the exact time that
# the call to flip returned as the msg time:
io.sendMessageEvent("STIM ONSET", sec_time=flip_time)