Problems with anonymize_dataset and events.tsv

  • MNE version: 0.24.1
  • operating system: Windows 10
  • MNE-BIDS version: 0.10


I have recently started my journey with mne-bids and have already come quite far.
Unfortunately, I cant solve this problem on my own and I am asking for help.
I prepared a bids-dataset and wanted to anonymize it with the function anonymize_dataset.
The anonymization failed due to an AssertionError when comparing the initial events.tsv and the anonymized version: assert events_tsv_in['trial_type'] == events_tsv_out['trial_type'] .

For the initial events.tsv, I passed events_data and event_id to write_raw_bids:

events = mne.find_events(raw,stim_channel='STI101')
events = mne.pick_events(events, include=1)
event_id =  {'click': 1} 


The written events.tsv file includes all the defined events but no annotations added by the acquisition system to the FIFF files.
The event value correponds to the value of the sum channel STI101 recorded from the neuronag meg.

:point_down: original events.tsv

onset duration trial_type value sample
131.465 116.0 click 1 131465
131.847 0.0 click 1 131847
132.207 0.0 click 1 132207


The anonymized events.tsv looks like this and includes the annotations recorded in the FIFF file.
Due to the presence of the annotations (BAD_ACQ_SKIP), the event value of click has also been increased from 1 to 2 which is unwanted. Therefore, the comparison obviously fails.
:point_down: anonymized events.tsv

onset duration trial_type value sample
2.0 116.0 BAD_ACQ_SKIP 1 2000
2.0 116.0 BAD_ACQ_SKIP 1 2000
131.465 116.0 click 2 131465
131.847 0.0 click 2 131847
132.207 0.0 click 2 132207

Is there a way to bypass the AssertionError or anything I can do to prevent anonymize_dataset
from generating the above events.tsv?
Another idea would be to modify the events_data and events_id to incorporate the annotations too when passed to write_raw_bids. But in that case, the event value 1 is already occupied by BAD_ACQ_SKIP and I cant use it anymore.

Thanks guys

Best regards

Hey @TicTacTill thanks for the report. (just fyi: I fixed some syntax errors with your markdown tables and added the mne-bids tag to your question, feel free to check these edits for next time)

This looks like it might be a bug. Could you please try to replicate your issue with one of the datasets shipped by MNE (e.g., data_path = mne.datasets.testing.data_path()) and open an issue on GitHub - mne-tools/mne-bids: MNE-BIDS is a Python package that allows you to read and write BIDS-compatible datasets with the help of MNE-Python. ? That is, supply a minimal working example? That’d be great!