Saving event_id attribute in raw object

Hi, so I have a raw object that I’ve read in from an mff and preprocessed. After saving the object using the save() function and reading it back out, the event_id parameter is no longer present. Any idea why this is the case? Thanks.

1 Like

Could you share a minimal example of the code you’re using? Thanks

Attaching a screenshot here, thanks!

Hi axel,

can you share some example code using one of MNE’s example datasets? i.e. if you share some pre-formatted text starting with these lines:

import mne

fpath = mne.datasets.testing.data_path()
fname = fpath / "EGI" / "test_egi.mff"
raw = mne.io.read_raw_egi(fname)
# ...
# the rest of your code that produces the issue

This way anyone here can copy and paste your code into their own python interpretor and help you solve the issue. It will also help us determine if the issue you are describing can be replicated with MNE’s own test files.

I think the issue is that the EGI reader adds a non-standard event_id attribute to the Raw object, which isn’t preserved when writing to disk. This is really not great behavior.

It is mentioned in the Notes section of the reader function:

The event_id assignment equals np.arange(n_events) + 1. The resulting event_id mapping is stored as attribute to the resulting raw object but will be ignored when saving to a fiff.

So there is an easy way to manually reconstruct the values.

I still believe we shouldn’t add an attribute which silently gets lost during saving in the first place. At least there should be a warning when saving. @larsoner WDYT about modifying the save() method of RawEgi to emit a warning that the attribute will be lost, plus code that explains how to reconstruct it after reading?

2 Likes

That would be a good idea. One option would be to JSON serialize the event_id and store it in raw.info["description"] for example.

An even better long-term solution would be for us to move to using Annotations for these events instead, then there’s no need for event_id or creating a synthetic event channel at all, as raw.annotations.description would contain the DIN values.

I opened API: Use annotations for read_raw_egi events rather than synthetic channel · Issue #12262 · mne-tools/mne-python · GitHub to continue discussion

Hi, I’m having the same issue here. Has this been resolved/worked around? Running the MNE 1.7.0. Thanks!

No it hasn’t been fixed yet, we’d welcome a pull request from someone to fix it!

1 Like

And for what it’s worth I started a pull request here, to implement this suggested fix:

But unfortunately I really haven’t had the time to finish it. Anyone is welcome to work off that branch if it is helpful, if they get to it before me.

1 Like

Will look into it, thanks for the update @scott-huberty and @larsoner!