How to save the .hdf5 file with eyetrakcing when using PyschoPy builder?

OS (e.g. Win10): Win11
PsychoPy version (e.g. 1.84.x): 2022.1.1
Standard Standalone? (y/n) If not then what?: yes

Hi, I am testing my eyetracking experiment using PyschoPy builder. I want save the ROI data as well as the detail eye samples with .hdf5 file. I have set ‘Save hdf5 file’ in ‘Experiment settings->Data->’, but I still could not see the .hdf5 file in the data file. I also test this using the demo eyetracking file eyetracking.psyexp, still could not get the .hdf5 file. Is there something I missed? How to solve this issue?

Thank you in advance for your help!

Bo

Hi, did You resolve your problem and found your files? I’m currently facing the same problem - I can’t find the .hdf5 file, despite having the box “Save hdf5 file” checked.

You need to add Eyetracker Record components to start and stop recording. I would put a start recording component at the beginning of your block and a stop recording component at the end of your block. If you want information about events in the hdf5, you’ll need code to send ioserver messages, e.g.,

# Begin routine 
ioServer.sendMessageEvent(text=f"start_TRIAL-{trialNum_cumul}_EVENT-image_CONDITION-{imageCond}") # start of the trial

# End routine
ioServer.sendMessageEvent(text=f"end_TRIAL-{trialNum_cumul}_EVENT-image_CONDITION-{imageCond}") # start of the trial

In the above example, everything in {} are variables. Without the messageEvents your hdf5 won’t have any information about the events and you’ll have to manually add them. If anyone needs a script to do this I am happy to share the code.

1 Like

Hi!

If you could share the script with me I would greatly appreciate it!

I am trying to implement this code but I get the error: NameError: name ‘trialNum_cumul’ is not defined - I am under the impression that I do not fully understand what that code is doing and, hence, I am unsure of what to set between the brackets :frowning:

Sounds like you don’t have the ‘trialNum_cumul’ variable. You should initialize the variable in a Begin Experiment code section, i.e., trialNum_cumul = 0, and then iterate the counter at the end of the trial in a End Routine code section, i.e., trialNum_cumul += 1. If you aren’t familiar with coding a basic counter variable such as this I would suggest going back to the Documentation (Builder — PsychoPy v2023.1.2). There is a variable that automatically keeps track of the current loop trial number, e.g., trials.thisTrialN, where ‘trials’ is the name of the trial loop.

The imageCond variable contains the name of the current condition which you can set in a condition file or with code.

1 Like

Thank you for all of your useful replies in this post and others! I wanted to ask – when you add in the code you mention above, does it add in a new column into the eyetracking data within the hdf5 file? Basically, I am wondering what the output of the hdf5 is supposed to now look like with that added trial information.
Lastly, do you have any other code recommendations to insert into the builder so that the trial information is added to the hdf5 eyetracking information? I implemented yours above into my current experiment with the trialnum_cumul variable added into the builder + my own imageCond added in, but I did not see any changes in my hdf5 file (when viewing from hdfview).

Any help/advice you or others could offer would be great, thank you!

The event information is added to the hdf in data_collection/events/experiment/MessageEvent. You can use the R code here to parse the events and align them with the eyetracking events.

From there, I would recommend the eyetrackingR package for further processing gaze data or puppilometryR for pupil data.

Dear Joseph,

this is incredibly useful, thank you! I only just recently fully understood the hierarchical structure of hdf5 files, so I understand now why that information would not be able to be saved in the events/eyetracking part of the hdf5 (which I previously was extracting using a python code and turning into a csv). I really appreciate your help!