Skip to content

API: Store Eyelink "messages" (i.e. events) as unicode strings, not byte strings #19

@scott-huberty

Description

@scott-huberty

Currently, eyelinkIO will read stimulus events ("messages" in EyeLink terminology) from the EDF file and store them as byte strings (see example below). This was inherited from the original implementation in the pyeparse package.

After a chat with @teonbrooks we've concluded that we should probably just store these as regular ol' Python strings, because 1) It will make working with these events easier for user, 2) We don't need to be Python 2 compatible, and 3) I don't think memory is an issue that warrants the use of byte strings.


I think that changing this line:

dtype = [("stime", np.float64), ("msg", "|S%s" % _MAX_MSG_LEN)]
res["discrete"]["messages"] = np.empty((n_samps["messages"]), dtype=dtype)

to this should work:

dtype = [("stime", np.float64), ("msg", f"U{_MAX_MSG_LEN}")]
res["discrete"]["messages"] = np.empty((n_samps["messages"]), dtype=dtype)

Which will specify a Unicode string type while preserving the _MAX_MSG_LEN constraint that currently exists.


Example of current behavior

import eyelinkio

fname = eyelinkio.utils._get_test_fnames()[0]
edf = eyelinkio.read_edf(fname)
edf["discrete"]["messages"]
array([(  0.   , b'RECCFG CR 1000 2 1 L'), (  0.   , b'ELCLCFG MTABLER'),
       (  0.   , b'GAZE_COORDS 0.00 0.00 1919.00 1079.00'),
       (  0.   , b'THRESHOLDS L 120 255'),
       (  0.   , b'ELCL_PROC CENTROID (3)'),
       (  0.   , b'ELCL_PCR_PARAM 5 3.0'),
       (  0.   , b'!MODE RECORD CR 1000 2 1 L\n'),
       (  3.314, b'TRIALID 1'), (  6.329, b'TRIALID 2'),
       (  9.339, b'TRIALID 3'), ( 12.348, b'TRIALID 4'),
       ( 15.356, b'TRIALID 5'), ( 18.364, b'TRIALID 6'),
       ( 21.373, b'TRIALID 7'), ( 24.382, b'TRIALID 8'),
       ( 27.39 , b'TRIALID 9'), ( 30.399, b'TRIALID 10'),
       ( 33.409, b'TRIALID 11'), ( 36.418, b'TRIALID 12'),
       ( 39.426, b'TRIALID 13'), ( 42.434, b'TRIALID 14'),
       ( 45.444, b'TRIALID 15'), ( 48.453, b'TRIALID 16'),
       ( 51.461, b'TRIALID 17'), ( 54.469, b'TRIALID 18'),
       ( 57.478, b'TRIALID 19'), ( 60.485, b'TRIALID 20'),
       ( 63.493, b'TRIALID 21'), ( 66.501, b'TRIALID 22'),
       ( 69.51 , b'TRIALID 23'), ( 72.518, b'TRIALID 24'),
       ( 75.526, b'TRIALID 25'), ( 78.534, b'TRIALID 26'),
       ( 81.543, b'TRIALID 27'), ( 84.55 , b'TRIALID 28'),
       ( 87.559, b'TRIALID 29'), ( 90.567, b'TRIALID 30'),
       ( 93.575, b'TRIALID 31'), ( 96.583, b'TRIALID 32'),
       ( 99.591, b'TRIALID 33'), (102.599, b'TRIALID 34'),
       (105.608, b'TRIALID 35'), (108.615, b'TRIALID 36'),
       (111.623, b'TRIALID 37'), (114.63 , b'TRIALID 38'),
       (117.639, b'TRIALID 39'), (120.647, b'TRIALID 40'),
       (124.739, b'Ending')], dtype=[('stime', '<f8'), ('msg', 'S260')])

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions