Eyetracker data

Hi everyone,

I’m conducting an experiment with sound detection and an eyetracker. I tried to open the hdf5 using the given code there: Communicating with an Eyetracker — PsychoPy v2023.1.1

but it cannot read it. I downloaded the packages, gave the correct pathway to find the file but I received an error:

id = filename.split(“/”)[1].split(“_”)[0]
IndexError: list index out of range

do you know how to fix it?

Can you give an example of a filename? My guess is that the filename you are using is missing either the “/” symbol or the “_” symbol, so “split” is returning an empty list and you get an “out of range” error.

I renamed the file because it contained “.” But indeed I had no “_” or “/”.

I tried to change this part. It is maybe wrong but I re do it like this, putting the hdf5 file in the same file than the code.

import h5py
import pandas as pd

filename = “mgeog.hdf5”
id = filename
with h5py.File(filename, “r”) as f:

# get the list of eyetracker measures available in the hdf5
eyetracker_measures = list(f['data_collection']['events']['eyetracker'])

for measure in eyetracker_measures:
    print('Extracting events of type: ', measure)
    data_collection = list(f['data_collection']['events']['eyetracker'][measure])
    if len(data_collection)>0:
        column_headers = data_collection[0].dtype.descr
        cols = []
        data_dict = {}
        for ch in column_headers:
            cols.append(ch[0])
            data_dict[ch[0]] = []

        for row in data_collection:
            for i, col in enumerate(cols):
                data_dict[col].append(row[i])
        pd_data = pd.DataFrame.from_dict(data_dict)
        pd_data.to_csv(id+'_'+measure+'.csv', index = False)
    else:
        print('No data for type', measure, ' moving on')

and the error message I receive is:

AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\site-packages\h5py_hl\files.py", line 231, in make_fid
fid = h5f.open(name, flags, fapl=fapl)
File “h5py_objects.pyx”, line 54, in h5py._objects.with_phil.wrapper
File “h5py_objects.pyx”, line 55, in h5py._objects.with_phil.wrapper
File “h5py\h5f.pyx”, line 106, in h5py.h5f.open
FileNotFoundError: [Errno 2] Unable to open file (unable to open file: name = ‘mgeog.hdf5’, errno = 2, error message = ‘No such file or directory’, flags = 0, o_flags = 0)

Does it mean it is looking for the hdf5 in the file where the package are installed? (Sorry I am very far away from an expert with coding…I might have installed pandas and h5py not correctly… ?

It means that the hdf5 file isn’t where the script is looking, anyways.

Generally speaking, if you’re running this in PsychoPy the ‘active directory’ is usually the folder that the script is saved in. So if the hdf5 file is not in that folder, you would get this error. If you’re running this from system Python rather than PsychoPy that’s not necessarily the case.

The best solution would be to get the complete path of the file you’re trying to open. You’re on Windows from the look of things, so if you open up the folder in Explorer, the complete path should appear in the address bar and you can just copy and paste it into your code (it’ll look something like “C:\Users\you\Documents\experiment\mgeog.hdf5”). That just side-steps any issues with whatever the ‘active directory’ is, but it means that the code will only really work on your particular computer.