Note
This page is a reference documentation. It only explains the function signature, and not how to use it. Please refer to the user guide for the big picture.
brainprep.utils.parse_bids_keys¶
- brainprep.utils.parse_bids_keys(bids_path, full_path=False, check_run=False)[source]¶
Parse BIDS entities and modality from a filename or path with validation.
This function extracts BIDS entities (e.g., subject, session, task, run) from a BIDS-compliant filename or full path. It also identifies the modality and applies default values when certain entities are missing.
When the ses entity is absent, it defaults to “01”. This provides ensures consistent downstream file handling.
When the run entity is absent, a deterministic 5-digit identifier is generated from the filename using UUID. This produces a short, stable hash so that the same filename always yields the same default run value.
- Parameters:
- bids_pathFile
The BIDS file to parse.
- full_path: bool
If True, extract entities from the full input path rather than only the filename. Default is False.
- check_run: bool
If True, checks whether the current run value appears more than once, assigns a UUID-style fallback if needed, and warns if even that fallback is not unique. Default is False.
- Returns:
- entitiesdict[str]
A dictionary containing the parsed BIDS entities and the detected modality. Missing entities such as ses and run are filled with default values.
Notes
If the BIDS file name does not contain the run key a warn message is displayed.