load
load
¶
Unified data loading interface for osipy.
This module provides a universal load_perfusion() function that
auto-detects file format and loads perfusion data from DICOM, NIfTI,
or BIDS sources.
load_perfusion
¶
load_perfusion(
path,
modality=None,
format="auto",
subject=None,
session=None,
interactive=True,
use_dcm2niix=True,
sidecar_json=None,
**kwargs,
)
Universal perfusion data loader with format auto-detection.
This is the primary entry point for loading perfusion imaging data. It automatically detects the file format and delegates to the appropriate loader.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
Path to data. Can be: - NIfTI file (.nii or .nii.gz) - DICOM directory or file - BIDS dataset directory
TYPE:
|
modality
|
Perfusion modality (DCE, DSC, ASL, IVIM). If None, attempts to infer from data or defaults to DCE.
TYPE:
|
format
|
Data format. If 'auto', format is detected from path. |
subject
|
Subject ID for BIDS loading (without 'sub-' prefix). Required when format='bids'.
TYPE:
|
session
|
Session ID for BIDS loading (without 'ses-' prefix).
TYPE:
|
interactive
|
Whether to prompt for missing required parameters.
TYPE:
|
use_dcm2niix
|
Whether to use dcm2niix for DICOM conversion when available. Falls back to direct DICOM loading if dcm2niix not found.
TYPE:
|
sidecar_json
|
Optional path to BIDS-style sidecar JSON with metadata. Useful when loading NIfTI files without embedded metadata.
TYPE:
|
**kwargs
|
Additional arguments passed to format-specific loaders.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
PerfusionDataset
|
Loaded imaging data with metadata. |
| RAISES | DESCRIPTION |
|---|---|
FileNotFoundError
|
If path does not exist. |
IOError
|
If format cannot be determined or data cannot be loaded. |
MetadataError
|
If required metadata is missing and interactive=False. |
Examples:
Load NIfTI file:
>>> from osipy.common.io import load_perfusion
>>> dataset = load_perfusion("data/asl.nii.gz", modality="ASL")
Load DICOM directory:
Load from BIDS dataset:
>>> dataset = load_perfusion(
... "bids_dataset/",
... format="bids",
... subject="01",
... modality="ASL",
... )
Load NIfTI with sidecar JSON: