add custom columns to tsv files

For a large data reorganization project we’re hoping to “bidsify” our existing EEG data.

We have rich metadata that would fit nicely within the BIDS structure as extra (custom) columns in various tsv files. With code inspection, trial-and-error (and online suggestions) we’ve made some progress deciphering where in the raw and/or raw.info objects we can supply additional info such that it ends up in the right tsv file under the intended column name, but it’s still far from complete (and feels very hackish). At the same time, the mne-bids pipeline initializes several tsv columns that we do NOT want (e.g., participants.tsv → weight and height; channels.tsv → status).

Question: how do we get fine-grained control over what ends up in each of the tsv files described below? Where do we supply values for extra columns, and how to prevent the creation of undesired columns? (Below, I’ll add what we think we already know.)

  1. participants.tsv: following this suggestion (https://mne.discourse.group/t/storing-data-on-participant-groups-in-bids-compliant-file-structure/6647?replies_to_post_number=2) it appears that extra columns can be set using raw.info[“subject_info”][“myVar”] = someValue. Can undesired columns also be deleted by simply removing subfields from [“subject_info”]?

  2. sessions.tsv: we want to include session-related variables (e.g. conditions and such), but no idea where to supply this information to the info object, raw object, or an mne-bids function

  3. scans.tsv: we want to add additional scan/recording-related variables (e.g., recording duration), but again no idea where to supply this information

  4. channels.tsv: we have several extra channel-related variables to include (e.g, description, polarity), while also wanting to remove unnecessary (for us) standard columns

  5. electrodes.tsv: here we take care of x/y/z coordinates using montage = mne.channels.make_dig_montage() followed by raw.set_montage(montage). works, but again unclear how to add additional columns if desired

  6. events.tsv: think we’ve figured this out by calling write_raw_bids() with appropriate arguments to events, event_metadata and extra_columns_descriptions

Apologies if this is all documented somewhere: we just can’t find it.