Enrichment¶
enrich_channels_tsv_with_aux(rec_bids_path, aux_info)
¶
Update the recording's channels.tsv file using auxiliary channel specifications.
Reads the existing channel table from disk and applies metadata for auxiliary channels (e.g., ECG, EOG, or TRIG). This is primarily used to correct generic 'MISC' types and provide specific units and descriptions that MNE-BIDS does not automatically detect.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rec_bids_path
|
BIDSPath
|
The MNE-BIDS path object used to locate the specific channels.tsv file. |
required |
aux_info
|
dict[str, AuxChanSpec]
|
A mapping of channel names to their auxiliary specifications. |
required |
Returns:
| Type | Description |
|---|---|
None
|
Reads from and writes to the channels.tsv file on disk. |
Source code in src/rs_bidsify/enrichment.py
enrich_dataset_description(metadata, out_root_path)
¶
Update the top-level BIDS dataset description file.
Identifies the dataset metadata from the provided model and writes it
to the dataset_description.json file at the output root. This ensures
the project-wide metadata matches the supplied specification.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metadata
|
DatasetMetadata
|
The global metadata model containing dataset details like Name, BIDSVersion, and Authors. |
required |
out_root_path
|
Path
|
The root directory of the BIDS dataset where the description file is located. |
required |
Returns:
| Type | Description |
|---|---|
None
|
Writes or overwrites the |
Source code in src/rs_bidsify/enrichment.py
enrich_eeg_sidecar(rec_bids_path, dataset_spec, add_extras=True)
¶
Enrich the BIDS EEG sidecar with metadata not captured by standard MNE-BIDS.
Orchestrates the extraction of reference/ground channels, filter specs, hardware info, and institutional details into an entries dictionary. This dictionary is then written to the existing JSON sidecar file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rec_bids_path
|
BIDSPath
|
The MNE-BIDS path object pointing to the recording's sidecar file. |
required |
dataset_spec
|
DescriptionSpec
|
The comprehensive dataset specification containing acquisition details. |
required |
add_extras
|
bool
|
If True, includes supplemental environmental and recording conditions (e.g., lighting, impedance) in the sidecar. |
True
|
Returns:
| Type | Description |
|---|---|
None
|
Writes the accumulated metadata to the JSON sidecar file on disk. |
Source code in src/rs_bidsify/enrichment.py
enrich_mne_object(eeg_data, dataset_spec)
¶
Update MNE Raw object metadata with experimental and acquisition details.
Orchestrates the enrichment of the recording by applying line frequency, auxiliary channel types, electrode montages, and event markers. This ensures the MNE object is fully specified before being saved via MNE-BIDS.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
eeg_data
|
BaseRaw
|
The MNE Raw object to be enriched. |
required |
dataset_spec
|
DescriptionSpec
|
The comprehensive dataset specification containing acquisition and event details. |
required |
Returns:
| Type | Description |
|---|---|
None
|
Updates the |
Source code in src/rs_bidsify/enrichment.py
get_filters(filter_list, filter_type)
¶
Extract filters of a specific type from a list of specifications.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filter_list
|
list[FilterSpec]
|
The list of filters to search through. |
required |
filter_type
|
FilterTypeOptions
|
The category of filter to retrieve (e.g., HARDWARE or SOFTWARE). |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
A mapping of filter names to their descriptive information. |
Source code in src/rs_bidsify/enrichment.py
map_spec_to_bids(source_obj, mapping, updates)
¶
Map attributes from a metadata model to BIDS-compliant sidecar keys.
Extracts specific values from a source specification object based on a provided mapping dictionary. It filters for non-null values and prepares them for inclusion in the BIDS JSON sidecar.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source_obj
|
Any
|
The metadata model (typically a Pydantic object) containing the data. |
required |
mapping
|
dict[str, str]
|
A dictionary where keys are the target BIDS fields and values are
the attribute names in the |
required |
updates
|
dict[str, Any]
|
The dictionary containing pending updates for the BIDS JSON sidecar. |
required |
Returns:
| Type | Description |
|---|---|
None
|
Updates the |
Source code in src/rs_bidsify/enrichment.py
set_aux_channel_types(eeg_data, aux_chans)
¶
Assign specific MNE channel types to auxiliary channels in the recording.
Converts auxiliary channel specifications from metadata into an MNE-compatible type map. It identifies which of the specified channels exist in the current recording and updates their types in-place.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
eeg_data
|
BaseRaw
|
The MNE Raw object whose channel types need to be updated. |
required |
aux_chans
|
dict[str, AuxChanSpec]
|
A mapping of channel names to their specifications, including the expected MNE channel type. |
required |
Returns:
| Type | Description |
|---|---|
None
|
Updates the |
Source code in src/rs_bidsify/enrichment.py
set_channel_case(eeg_data, eeg_spec)
¶
Standardise the casing of EEG channel names to match a reference montage.
Utilises the pre-validated montage configuration from the EEG specification to perform a case-insensitive match, renaming channels in the MNE Raw object to align exactly with the standard montage capitalisation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
eeg_data
|
BaseRaw
|
The MNE Raw object whose channel names will be updated. |
required |
eeg_spec
|
EEGChanSpec
|
The EEG channel specification containing the reference montage. |
required |
Returns:
| Type | Description |
|---|---|
None
|
The |
Source code in src/rs_bidsify/enrichment.py
set_channels_tsv(channels, channel_tsv)
¶
Update the channel metadata table with BIDS-specific details.
Synchronises the tabular channel data with provided specifications. It prioritises updating 'MISC' types to specific BIDS types, adding channel descriptions, and filling in missing unit information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
channels
|
dict[str, AuxChanSpec]
|
A mapping of channel names to their detailed specifications. |
required |
channel_tsv
|
DataFrame
|
The pandas DataFrame representing the contents of the channels.tsv file, indexed by channel name. |
required |
Returns:
| Type | Description |
|---|---|
None
|
Updates the |
Source code in src/rs_bidsify/enrichment.py
set_device_info(entries_dict, acquisition_spec)
¶
Map hardware and acquisition software details to BIDS metadata.
Identifies the amplifier model and software versions from the acquisition specification and queues them for the sidecar update.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entries_dict
|
dict[str, Any]
|
The dictionary containing pending updates for the BIDS JSON sidecar. |
required |
acquisition_spec
|
AcquisitionSpecs
|
The specification containing amplifier and software details. |
required |
Returns:
| Type | Description |
|---|---|
None
|
Updates the |
Source code in src/rs_bidsify/enrichment.py
set_electrode_montage(eeg_data, eeg_spec)
¶
Apply a physical electrode coordinate system (montage) to the EEG data.
Utilises the pre-validated montage configuration from the EEG specification to assign 3D sensor locations to the MNE Raw object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
eeg_data
|
BaseRaw
|
The MNE Raw object to which the montage will be applied. |
required |
eeg_spec
|
EEGChanSpec
|
The EEG channel specification containing the resolved Montage model. |
required |
Returns:
| Type | Description |
|---|---|
None
|
The |
Raises:
| Type | Description |
|---|---|
Exception
|
Re-raises any exception encountered during montage application, typically due to channel name mismatches between the data and montage. |
Source code in src/rs_bidsify/enrichment.py
set_events(eeg_data, event_info)
¶
Map raw EEG trigger descriptions to BIDS-compliant event labels.
Synchronises recording annotations with user metadata. Only triggers found in both the file and the metadata are renamed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
eeg_data
|
BaseRaw
|
The MNE Raw object containing raw annotations. |
required |
event_info
|
dict[str, str]
|
A mapping of {raw_trigger_name: bids_event_label} form the metadata. |
required |
Returns:
| Type | Description |
|---|---|
None
|
Updates the |
Notes
This function uses strict symmetry. It will log a warning if: 1. A trigger defined in your metadata is missing from the EEG file. 2. A trigger found in the EEG file is missing from your metadata.
Source code in src/rs_bidsify/enrichment.py
set_extras(entries_dict, extra_spec)
¶
Map supplemental environmental and recording details to BIDS metadata.
Identifies non-standard BIDS fields—such as impedance thresholds, room shielding, and lighting—from the extra specification and queues them for the sidecar update.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entries_dict
|
dict[str, Any]
|
The dictionary containing pending updates for the BIDS JSON sidecar. |
required |
extra_spec
|
ExtraSpec
|
The specification containing environmental and setup details. |
required |
Returns:
| Type | Description |
|---|---|
None
|
Updates the |
Source code in src/rs_bidsify/enrichment.py
set_filters(entries_dict, filters, bids_key)
¶
Update the sidecar dictionary with identified filters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entries_dict
|
dict[str, Any]
|
The dictionary used for the final JSON update. |
required |
filters
|
dict[str, Any]
|
The filtered mapping of filter names and info to be added. |
required |
bids_key
|
str
|
The specific BIDS field name to update. |
required |
Returns:
| Type | Description |
|---|---|
None
|
Updates the |
Source code in src/rs_bidsify/enrichment.py
set_ground_chan(entries_dict, eeg_chan_spec)
¶
Map the EEG ground channel information to the BIDS metadata.
Identifies the ground channel from the EEG specification and queues it for the sidecar update under the 'EEGGround' key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entries_dict
|
dict[str, Any]
|
The dictionary containing pending updates for the BIDS JSON sidecar. |
required |
eeg_chan_spec
|
EEGChanSpec
|
The channel specification containing the ground channel details. |
required |
Returns:
| Type | Description |
|---|---|
None
|
Updates the |
Source code in src/rs_bidsify/enrichment.py
set_hardware_filters(entries_dict, filter_list)
¶
Identify and queue hardware filters for the BIDS sidecar update.
Filters the provided list for hardware-specific entries and adds them to the entries dictionary under the 'HardwareFilters' key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entries_dict
|
dict[str, Any]
|
The dictionary containing pending updates for the BIDS JSON sidecar. |
required |
filter_list
|
list[FilterSpec]
|
A collection of filter specifications containing both hardware and software filters. |
required |
Returns:
| Type | Description |
|---|---|
None
|
Updates the |
Source code in src/rs_bidsify/enrichment.py
set_institution_info(entries_dict, metadata)
¶
Map institutional and departmental details to BIDS metadata.
Identifies the institution name and department from the dataset metadata and queues them for the sidecar update.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entries_dict
|
dict[str, Any]
|
The dictionary containing pending updates for the BIDS JSON sidecar. |
required |
metadata
|
DatasetMetadata
|
The global dataset metadata containing institutional information. |
required |
Returns:
| Type | Description |
|---|---|
None
|
Updates the |
Source code in src/rs_bidsify/enrichment.py
set_line_frequency(eeg_data, acqusition_spec)
¶
Set the power line frequency in the MNE Raw object info.
Updates the line_freq attribute of the recording metadata based on
the provided acquisition specifications. This value is essential for
artifact removal and BIDS sidecar generation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
eeg_data
|
BaseRaw
|
The MNE Raw object to be updated. |
required |
acqusition_spec
|
AcquisitionSpecs
|
Specification object containing the |
required |
Returns:
| Type | Description |
|---|---|
None
|
Updates the |
Source code in src/rs_bidsify/enrichment.py
set_reference_chan(entries_dict, eeg_chan_spec)
¶
Map the EEG reference channel information to the BIDS metadata.
Identifies the reference channel from the EEG specification and queues it for the sidecar update under the 'EEGReference' key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entries_dict
|
dict[str, Any]
|
The dictionary containing pending updates for the BIDS JSON sidecar. |
required |
eeg_chan_spec
|
EEGChanSpec
|
The channel specification containing the reference channel details. |
required |
Returns:
| Type | Description |
|---|---|
None
|
Updates the |
Source code in src/rs_bidsify/enrichment.py
set_software_filters(entries_dict, filter_list)
¶
Identify and queue software filters for the BIDS sidecar update.
Filters the provided list for software-specific entries and adds them to the entries dictionary under the 'SoftwareFilters' key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entries_dict
|
dict[str, Any]
|
The dictionary containing pending updates for the BIDS JSON sidecar. |
required |
filter_list
|
list[FilterSpec]
|
A collection of filter specifications containing both hardware and software filters. |
required |
Returns:
| Type | Description |
|---|---|
None
|
Updates the |
Source code in src/rs_bidsify/enrichment.py
set_subject_info(eeg_data, subject_model)
¶
Populate the MNE Raw object with participant demographic information.
Updates the info['subject_info'] dictionary using data from the
SubjectMetadata model. This handles cases where subject information
is entirely missing or needs to be merged with existing entries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
eeg_data
|
BaseRaw
|
The MNE Raw object to be updated. |
required |
subject_model
|
SubjectMetadata
|
The model containing subject details, providing an MNE-compatible
dictionary via |
required |
Returns:
| Type | Description |
|---|---|
None
|
Updates the |