Search code examples
pythonyamlpsychopy

How to dynamically rename the hdf5 file from psychopy's iohub


I'm using the Psychopy 1.82.01 Coder and its iohub functionality (on Ubuntu 14.04 LTS). It is working but I was wondering if there is a way to dynamically rename the hdf5 file it produces during an experiment (such that in the end, I know which participant it belongs to and two participants will get two files without overwriting one of them). It seems to me that the filename is determined in this file: https://github.com/psychopy/psychopy/blob/df68d434973817f92e5df78786da313b35322ae8/psychopy/iohub/default_config.yaml But is there a way to change this dynamically?


Solution

  • If you want to create a different hdf5 file for each experiment run, then the options depend on how you are starting the ioHub process. Assuming you are using the psychopy.iohub.launchHubServer() function to start ioHub, then you can pass the 'experiment_code' kwarg to the function and that will be used as the hdf5 file name.

    For example, if you created a script with the following code and ran it:

    import psychopy.iohub as iohub
    
    io = iohub.launchHubServer(experiment_code="exp_sess_1")
    
    # your experiment code here ....
    # ...
    
    io.quit()
    

    An ioHub hdf5 file called 'exp_sess_1.hdf5' will be created in the same folder as the script file.

    As a side note, you do not have to save each experiment sessions data into a separate hdf5 file. The ioHub hdf5 file structure is designed to save multiple participants / sessions data in a single file. Each time the experiment is run, a unique session code is required, and the data from each run is saved in the hdf5 file with a session id that is associated with the session code.