bids
bids
¶
BIDS I/O for osipy.
This module provides functions for loading and exporting perfusion data in BIDS-compliant format, including ASL-BIDS input support.
References
BIDS Specification: https://bids-specification.readthedocs.io/ BIDS Derivatives: https://bids-specification.readthedocs.io/en/stable/derivatives/ ASL-BIDS: https://bids-specification.readthedocs.io/en/stable/modality-specific-files/magnetic-resonance-imaging-data.html#arterial-spin-labeling-perfusion-data
export_bids
¶
Export parameter maps in BIDS derivatives format.
| PARAMETER | DESCRIPTION |
|---|---|
parameter_maps
|
Parameter maps to export, keyed by parameter name.
TYPE:
|
output_dir
|
BIDS derivatives root directory.
TYPE:
|
subject_id
|
Subject identifier (without 'sub-' prefix).
TYPE:
|
session_id
|
Session identifier (without 'ses-' prefix), optional.
TYPE:
|
metadata
|
Additional metadata for sidecar JSON files.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Path
|
Path to created subject directory. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If parameter_maps is empty or subject_id is invalid. |
Examples:
load_bids
¶
Load perfusion data from a BIDS dataset.
| PARAMETER | DESCRIPTION |
|---|---|
bids_dir
|
Path to BIDS dataset root directory.
TYPE:
|
subject
|
Subject ID (without 'sub-' prefix).
TYPE:
|
modality
|
Perfusion modality to load.
TYPE:
|
session
|
Session ID (without 'ses-' prefix), optional.
TYPE:
|
run
|
Run number, optional.
TYPE:
|
interactive
|
Whether to prompt for missing required parameters.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
PerfusionDataset
|
Loaded perfusion data with metadata. |
| RAISES | DESCRIPTION |
|---|---|
FileNotFoundError
|
If BIDS directory or required files not found. |
IOError
|
If BIDS dataset structure is invalid. |
MetadataError
|
If required metadata is missing and interactive=False. |
Examples:
load_bids_with_m0
¶
Load ASL data with separate M0 calibration scan from BIDS.
| PARAMETER | DESCRIPTION |
|---|---|
bids_dir
|
Path to BIDS dataset root directory.
TYPE:
|
subject
|
Subject ID (without 'sub-' prefix).
TYPE:
|
session
|
Session ID (without 'ses-' prefix), optional.
TYPE:
|
run
|
Run number, optional.
TYPE:
|
interactive
|
Whether to prompt for missing required parameters.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[PerfusionDataset, PerfusionDataset | None]
|
Tuple of (ASL data, M0 calibration data). M0 is None if not found. |
Examples:
>>> asl_data, m0_data = load_bids_with_m0("bids_dataset/", "01")
>>> if m0_data is not None:
... print(f"M0 shape: {m0_data.shape}")
Notes
BIDS ASL M0 scans can be:
- Separate file: *_m0scan.nii.gz
- Included in ASL timeseries (indicated by M0Type in sidecar)
load_asl_context
¶
Load ASL context (control/label order) from BIDS.
| PARAMETER | DESCRIPTION |
|---|---|
bids_dir
|
Path to BIDS dataset root directory.
TYPE:
|
subject
|
Subject ID (without 'sub-' prefix).
TYPE:
|
session
|
Session ID, optional.
TYPE:
|
run
|
Run number, optional.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[str]
|
List of volume types: 'control', 'label', 'm0scan', 'cbf', 'deltam'. |
Examples:
>>> context = load_asl_context("bids_dataset/", "01")
>>> print(context[:4])
['control', 'label', 'control', 'label']
Notes
The aslcontext.tsv file is required by BIDS ASL and indicates the type of each volume in the ASL timeseries.
is_bids_dataset
¶
Check if a path is a valid BIDS dataset.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
Path to check.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if path appears to be a BIDS dataset. |
get_bids_subjects
¶
Get list of subjects in a BIDS dataset.
| PARAMETER | DESCRIPTION |
|---|---|
bids_dir
|
Path to BIDS dataset root.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[str]
|
List of subject IDs (without 'sub-' prefix). |