aeye-lab / pymovements

A python package for processing eye movement data
https://pymovements.readthedocs.io
MIT License
61 stars 11 forks source link

Allow custom patterns for extracting logged metadata from ASC files #758

Open saeub opened 2 months ago

saeub commented 2 months ago

Description of the problem

Currently, the from_asc() only supports custom regex patterns via the patterns argument, which adds the captured values to columns in the dataframe. It would be useful if we could also extract session-level metadata (e.g., the stimulus randomization order, which we log in the ASC file).

Description of a solution

  1. Add another argument to from_asc() (e.g., metadata_patterns) that accepts custom regular expressions. The captured values should be added to the metadata dictionary returned by parse_eyelink().
  2. Return the metadata dictionary from from_asc().

Sample Code

>>> data, metadata = pm.gaze.from_asc("foo.asc", metadata_patterns=[r"stimulus order: (?P<stimulus_order>.+)"])
>>> metadata
{"stimulus_order": "order1", ...}

The code should probably either warn the user in case there are multiple logged messages that match the pattern, or collect all of them in a list (e.g., {"stimulus_order": ["order1", "order2"], ...})

SiQube commented 2 months ago

related to #510