mne_bids.write_raw_bids

mne_bids.write_raw_bids(raw, bids_basename, bids_root, events_data=None, event_id=None, anonymize=None, overwrite=False, verbose=True)[source]

Save raw data to a BIDS-compliant folder structure.

Warning

  • The original file is simply copied over if the original file format is BIDS-supported for that modality. Otherwise, this function will convert to a BIDS-supported file format while warning the user. For EEG and iEEG data, conversion will be to BrainVision format, for MEG conversion will be to FIF.

  • mne-bids will infer the manufacturer information from the file extension. If your file format is non-standard for the manufacturer, please update the manufacturer field in the sidecars manually.

Parameters
rawinstance of mne.io.Raw

The raw data. It must be an instance of mne.Raw. The data should not be loaded from disk, i.e., raw.preload must be False.

bids_basenamestr

The base filename of the BIDS compatible files. Typically, this can be generated using make_bids_basename. Example: sub-01_ses-01_task-testing_acq-01_run-01. This will write the following files in the correct subfolder of the bids_root:

sub-01_ses-01_task-testing_acq-01_run-01_meg.fif
sub-01_ses-01_task-testing_acq-01_run-01_meg.json
sub-01_ses-01_task-testing_acq-01_run-01_channels.tsv
sub-01_ses-01_task-testing_acq-01_run-01_coordsystem.json

and the following one if events_data is not None:

sub-01_ses-01_task-testing_acq-01_run-01_events.tsv

and add a line to the following files:

participants.tsv
scans.tsv

Note that the modality ‘meg’ is automatically inferred from the raw object and extension ‘.fif’ is copied from raw.filenames.

bids_rootstr | pathlib.Path

The path of the root of the BIDS compatible folder. The session and subject specific folders will be populated automatically by parsing bids_basename.

events_datastr | pathlib.Path | array | None

The events file. If a string or a Path object, specifies the path of the events file. If an array, the MNE events array (shape n_events, 3). If None, events will be inferred from the stim channel using mne.find_events.

event_iddict | None

The event id dict used to create a ‘trial_type’ column in events.tsv

anonymizedict | None

If None is provided (default) no anonymization is performed. If a dictionary is passed, data will be anonymized; identifying data structures such as study date and time will be changed. daysback is a required argument and keep_his is optional, these arguments are passed to mne.io.anonymize_info().

daysbackint

Number of days to move back the date. To keep relative dates for a subject use the same daysback. According to BIDS specifications, the number of days back must be great enough that the date is before 1925.

keep_hisbool

If True info[‘subject_info’][‘his_id’] of subject_info will NOT be overwritten. Defaults to False.

overwritebool

Whether to overwrite existing files or data in files. Defaults to False. If overwrite is True, any existing files with the same BIDS parameters will be overwritten with the exception of the participants.tsv and scans.tsv files. For these files, parts of pre-existing data that match the current data will be replaced. If overwrite is False, no existing data will be overwritten or replaced.

verbosebool

If verbose is True, this will print a snippet of the sidecar files. If False, no content will be printed.

Returns
bids_rootstr

The path of the root of the BIDS compatible folder.

Notes

For the participants.tsv file, the raw.info[‘subject_info’] should be updated and raw.info[‘meas_date’] should not be None to compute the age of the participant correctly.