{"id":18118918,"url":"https://github.com/gmierz/pupil-lib","last_synced_at":"2025-04-14T17:11:57.375Z","repository":{"id":57455538,"uuid":"99518085","full_name":"gmierz/pupil-lib","owner":"gmierz","description":"Event extraction library for Pupil Labs eye tracker data.","archived":false,"fork":false,"pushed_at":"2019-12-23T02:44:29.000Z","size":109680,"stargazers_count":11,"open_issues_count":5,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-14T17:11:48.852Z","etag":null,"topics":["analysis","command-line","data-synchronization","epoch","event","event-based","event-related","eye-tracker","eye-tracking","lab-streaming-layer","lsl","markers","module","pupil-labs","pupillometry","python","research","tool","trial","trial-extraction"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gmierz.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-08-06T23:02:10.000Z","updated_at":"2025-01-27T23:01:48.000Z","dependencies_parsed_at":"2022-09-10T08:01:29.883Z","dependency_job_id":null,"html_url":"https://github.com/gmierz/pupil-lib","commit_stats":null,"previous_names":["gmierz/pupil-lib-python"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gmierz%2Fpupil-lib","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gmierz%2Fpupil-lib/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gmierz%2Fpupil-lib/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gmierz%2Fpupil-lib/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gmierz","download_url":"https://codeload.github.com/gmierz/pupil-lib/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248923765,"owners_count":21183953,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["analysis","command-line","data-synchronization","epoch","event","event-based","event-related","eye-tracker","eye-tracking","lab-streaming-layer","lsl","markers","module","pupil-labs","pupillometry","python","research","tool","trial","trial-extraction"],"created_at":"2024-11-01T05:14:12.491Z","updated_at":"2025-04-14T17:11:57.351Z","avatar_url":"https://github.com/gmierz.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"v1.2.0: [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.3474206.svg)](https://doi.org/10.5281/zenodo.3474206)\n[![Build Status](https://travis-ci.com/gmierz/pupil-lib.svg?branch=master)](https://travis-ci.com/gmierz/pupil-lib)\n\n# Pupil-Lib Python\n\nThis library is for processing data that is obtained from the [Pupil Labs](https://pupil-labs.com/) eye tracker working in conjunction with [Lab Streaming Layer](https://github.com/sccn/labstreaminglayer) (LSL) that retrieves the needed event markers and eye tracker data. These event markers can be created anywhere and sent over the network to the Lab Recorder. The XDF file's created can then be given to this library, with a configuration file [(a YAML or .yml file)](https://github.com/gmierz/pupil-lib-python/blob/master/pupillib/resources/test_yaml1.yml), to perform trial extraction. It can be used as a command line tool, or python module import.\n\nOnce processed by this library, the trials that are returned after extraction have zero error in their length relative to what was requested - leaving only small network latencies as the cause for errors. The data is also resampled into an evenly spaced timeseries to make processing and analysis simpler. This is particularly useful when we need to deal with un-evenly sampled data streams obtained from LSL's XDF data exports or the Pupil Labs eye tracker. These streams are also synchronized by LSL on import and have a [high level of precision](https://sccn.ucsd.edu/~mgrivich/LSL_Validation.html).\n\nAnother use of this library is the ability to convert Pupil Labs XDF files into CSV, or Matlab `.mat` files that can be processed anywhere. Data is also upsampled to 256Hz and corrected for irregular sampling rates. See [this file](https://github.com/gmierz/pupil-lib/blob/master/pupillib/example_xdf_to_csv.py) for an example.\n\nThe Matlab version is available here: https://github.com/gmierz/pupil-lib-matlab\n\nThis python version of the library will only work on Python 3+.\n\n## Academic articles using this library\n\n1. R. Butler, G.W. Mierzwinski, P.M. Bernier, M. Descoteaux, G. Gilbert, K. Whittingstall, __Neurophysiological basis of contrast dependent BOLD orientation tuning__, NeuroImage, 2019, 116323, ISSN 1053-8119, https://doi.org/10.1016/j.neuroimage.2019.116323.\n\n## Recent Changes\nThe following changes are incorporated into the PyPi `pupillib` module at version 1.2.0.\n1. Pupil LSL Relay 2.0 support.\n2. Drastic increase in the number of time series that can be obtained. See this [sample config](https://github.com/gmierz/pupil-lib/blob/436c65301cd2323a06737dc6f1694f5664378fdf/pupillib/resources/test_yaml3.yml#L24).\n\nThe following changes are incorporated into the PyPi `pupillib` module at version 1.1.0.\n1. Matlab '.mat' output is now supported! Instead of `save_csv`, use `save_mat` to store '.mat' files.\n2. Merging multiple datasets is working as expected now.\n3. Simplified rejected trial exclusion/inclusion from data. At any level of the data_container objects, set `datastore.exclude_rejects = False` to include rejected trials in the data obtained from `get_matrix` calls. Setting this flag to False also changes what is saved with the `save_csv` and `save_mat` functions since they use `get_matrix` to gather data that needs to be saved.\n4. Raw trial data that is processed by some pre/post functions is no longer overwritten by the processed data. This data now exists in the `proc` data_type rather than the `original` data type.\n5. Added --save-mat and --prefix to the optional arguments that can be used from the command line interface.\n6. `.data` can now be used to access the processed data instead of `.data_store`. `.data_store` is still available but will be removed in a future release.\n7. Documentation was updated to reflect the changes.\n8. (Under-the-hood) Logging is now a bit simpler, and not as verbose as before. With this patch, preparations are being made to remove threaded options.\n\n## Dependencies\nTo have an experiment compatible with this library the following is required:\n  1. Pupil Labs binocular eye tracker: https://pupil-labs.com/ .\n  2. Lab Streaming Library (LSL): https://github.com/sccn/labstreaminglayer . The version contained in 'liblsl-1.04.zip' in the downloads page is known to work with the Matlab marker inlet function.\n      1. To install, you will have to clone the repo locally.\n      1. For Matlab scripts, download the code in `LSL/liblsl-matlab` and `LSL/liblsl`.\n      1. Copy the files in `liblsl` into `liblsl-matlab/bin`, then add the matlab directory into the matlab path.\n      1. Now you can use it in a stimulus script.\n  3. LabRecorder: ftp://sccn.ucsd.edu/pub/software/LSL/Apps/ . This version contained in 'LabRecorder-1.12c.zip' is known to work with the Pupil Labs eye tracker and produces compatible XDF files.\n  4. Install [Pupil Labs LSL Plugin 2.0](https://github.com/labstreaminglayer/App-PupilLabs/tree/v2.0). Follow their instructions [in the readme](https://github.com/labstreaminglayer/App-PupilLabs/tree/v2.0). It should be possible to install `pylsl` with `pip install pylsl`.\n  5. (Optional - Pupil Labs LSL Plugin 2.0 now works from step 4, if there are issues with that one then try this older version). Pupil Labs LSL Plugin: https://github.com/labstreaminglayer/App-PupilLabs/releases/tag/v1.0 . Follow [their instructions](https://github.com/labstreaminglayer/App-PupilLabs/tree/v1.0) to get it working. I had to use the source code in the Lab Streaming Library repo to be able to properly produce the 'pylsl' folder. What helped the most here was running the script 'get_deps.py' which will fill the 'pylsl' folder with needed files. This can be done before or after the 'build' phase. Ignore the link at \"LSL Python bindings on the first step, it's broken and should point [here](https://github.com/labstreaminglayer/liblsl-Python/tree/v1.13.0) but it's not required.\n\n## Running a compatible experiment\n\nAny experiment must use the [Lab Recorder](https://github.com/labstreaminglayer/App-LabRecorder) to record all the data, the Pupil Labs LSL Relay Plugin (mentioned above) to send data from a Capture interface running on a network, and a Lab Streaming Layer outlet producing event markers (from any language) somewhere. See [here](https://github.com/gmierz/pupil-lib-matlab/blob/master/server_client/create_marker_outlet.m) for a Matlab example - use with `outlet.push_sample({'Marker Name'})` in a stimulus script. You can wait until it [has consumers](https://github.com/labstreaminglayer/liblsl-Matlab/blob/17c89909f8f28a1cdd96eef4a444432c4ace0753/lsl_outlet.m#L118) as well to automatically start stimuli from a Lab Recorder application.\n\nAny experiment, in general, goes as follows:\n1. Insert markers into stimulus scripts, and have it ready and waiting for consumers.\n2. Start eye trackers, and Pupil Capture and prepare - ensure that the relay plugin is on.\n3. Open Lab Recorder on a recording machine that is on to the same network the eye trackers and event markers are on.\n4. Check boxes for all data required\n    - `diameter_3d` (in mm) comes from the `Python representation`, and  `diameter` is the diameter (in pixels) uncorrected for perspective it is the only diameter available in the `Primitive data`.\n    - Always remember to have the marker one selected, or the stimulus won't start if you're waiting on consumers.\n    - If you're not sure what you need, take the python representation. It will result in large files, but it's also the only way to get perspective corrected diameters (or specific gaze data).\n5. Start Lab Recorder when you're ready to start the experiment.\n\nNote: There is no need to record from Pupil Capture, but you can if you still need to.\n\n## Usage\n\nOnce you clone this library, you should run `python setup.py install` from within the directory so that you can use it in a script anywhere.\nHere are some example commands:\n\n```\ncd ~\ngit clone https://github.com/gmierz/pupil-lib-python\ncd pupil-lib-python\npython setup.py install\n```\n\nYou can also install this through pip now:\n```\npip install pupillib\n```\n\nIf any errors are encountered during installation, try using a virtual environment (these commands differ based on the OS - [see here for more info](https://virtualenv.pypa.io/en/latest/userguide/)):\n```\npip install virtualenv\n\nvirtualenv pupillib-venv\n\npupillib-venv\\Scripts\\activate\npip install pupillib\n```\n\nAfter this, you will be able to use pupillib as a python module import or a command line tool with [YAML configurations](https://github.com/gmierz/pupil-lib-python/blob/master/pupillib/resources/test_yaml1.yml).\n\nAn easy way to get going after this is by using the script [pupillib/simple_script.py](https://github.com/gmierz/pupil-lib-python/blob/master/pupillib/simple_script.py) as an example to get what you need. Then change `yaml_path='resources/test_yaml1.yml'` to point to another YAML file (which could be the same file - copied or not) and modify the configuration to your experiment.\n\nThe markers that are recorded must have a type of 'Markers' to be processed. If the type is mixed with the name change `type` to `name` here:\nOne way is to use it is in a script with calls that resemble the `main()` function in pupil_lib.py. `yaml_path` must be defined\nin the `get_build_config(yaml_path=\u003cPATH/TO/YAML\u003e)` call. Or if you don't need much control, `script_run(yaml_path=\u003cPATH/TO/YAML\u003e)`\nin the same file can be used to do everything and return an PupilLibRunner object that contains the data in the field `.data_store`.\n\nSee `docs/data_container.md` for more information on the data container `.data_store` which holds all the data - `pupillib/simple_script.py` is a good example.\n\nYou can also use it through the command prompt as well with something like (this is the suggested method):\n\n```\npupillib --run-config C:\\Users\\Gregory\\PycharmProjects\\pupil_lib_parallel_exp\\resources\\test_yaml1.yml`\n```\n\nOr with only this to get the arguments from a YAML configuration file (defined in the docs/ folder):\n\n```\npupillib -D C:\\Recordings\\CurrentStudy\\subj4\\block__old41.xdf --data-names gaze_x gaze_y\n --trigger-pre-processing \"{name: default}\" {'name':'get_sums','config':[4]} -t S11 S12 --max-workers 1\n --tr -2 0 --logger stdout --test --testingdepth deep\n```\n\n## Data Usage\n\n`data_container.py` shows the general structure of the data once it's finished processing, with docs in `docs/data_container.md`. Generally speaking, accessing data will be similar in all cases to what is done in `simple_script.py`.\n\n## Marker creation\n\nUsing the Pupil Labs LSL plugin, you can create and send markers from a stimulus script in the same way that is [done here](https://github.com/labstreaminglayer/liblsl-Matlab/blob/17c89909f8f28a1cdd96eef4a444432c4ace0753/examples/SendStringMarkers.m).\n\nThe stream can/will be saved by the Lab Recorder software and that data can then be used for processing in this library.\n(For the stimulus scripts, they can be in any language that LSL offers so that markers can be created and sent).\n\n## Examples of data that can be retrieved\n\nThese images below are from processing a dataset where a subject was looking at these stimuli:\n\n![alt text](https://user-images.githubusercontent.com/10966989/35007458-ce26d07a-fac7-11e7-9817-1e2c3f2bfc9e.png)\n\nGaze data (gaze_x, and gaze_y fields) - data from when a world camera was not in use:\n\n![alt text](https://user-images.githubusercontent.com/10966989/35007537-f99df72e-fac7-11e7-9daa-d035ca92bd42.png)\n\nAll trials across all triggers:\n\n![alt text](https://user-images.githubusercontent.com/10966989/35007535-f97cf86c-fac7-11e7-9eab-8949a9961a7e.png)\n\nMean of all trials for each trigger overlaid:\n\n![alt text](https://user-images.githubusercontent.com/10966989/35007562-121dbcf8-fac8-11e7-9acd-c14bd579fdef.png)\n\n## Customization\n\nThis library, at it's core, only extracts trials. This is why it's main features are zero-error trial extraction, and helping with the correction of uneven sampling rates. But it uses processor files to perform any processing like percent-change calculations, and filtering. Because of this it is very simple to insert your own customized functionality before or after any part of the processing pipeline. See `pupillib/docs/pre_post_functions` for how to do this. In the near future, it will also be possible to add custom classes (extending from the processor classes) with the same decorators from a directory outside the library with an environment flag.\n\n## Testing\n\nTesting is done within the library itself, but it is only fully tested when `testing: True` is set in the `config` entry of a YAML configuration file. This makes it simpler to reproduce specific errors within a given dataset. There are also two test YAML files situated in `pupillib/resources`.\n\n## Future Additions and Fixes\n\n1. Custom class imports for processing.\n2. Stronger/better CSV exporting.\n3. Deprecation of all command line arguments except for `--run-config=\u003cPATH\u003e` for simplification purposes.\n4. More documentation of data structures at the various pre/post processing levels.\n\n## Academic Citation\n\nThere is no article to cite for this source code for the time being. However, if this code is used in any scientific publications, please consider referencing this repository by following the Zenodo badge link, and using the \"cite as\" entry from there:\n\n[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.2589448.svg)](https://doi.org/10.5281/zenodo.2589448)\n\nIf you need a newer release, you can let me know through an issue.\n\n## License - GPLV3\nThis library is licensed under GPLV3, see here for the license: https://github.com/gmierz/pupil-lib/blob/master/LICENSE\nIf another type is required please contact me so that we can discuss.\n\nFinally, as always feel free to ask any questions you may have through issues and post your issues or suggested improvements through there as well. :)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgmierz%2Fpupil-lib","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgmierz%2Fpupil-lib","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgmierz%2Fpupil-lib/lists"}