discovery
discovery
¶
DICOM discovery and loading.
Two primitives:
- :func:
discover_dicomwalks a directory, groups files bySeriesInstanceUID, and annotates each series with a best-effort role hint (dynamic / dynamic_frame / vfa / t1_look_locker / unknown). It never touches pixel data and logs a transparent summary of what it found and why. - :func:
load_dicom_seriesloads one :class:SeriesInfo(3D or 4D, depending on TPI structure) or stacks a list of per-timepoint series into a 4D volume with a derived time vector.
Design: discovery is observation only. Role hints are hints — callers
may ignore them and select series by any attribute on SeriesInfo.
No modality-specific behaviour is baked into loading; modality is
just carried through onto the returned :class:PerfusionDataset.
SeriesInfo
dataclass
¶
SeriesInfo(uid, study_instance_uid, files, description, series_number, dicom_modality, manufacturer, flip_angle, tr, te, field_strength, rows, columns, n_temporal_positions, n_acquisition_numbers, n_slice_locations, image_types=set(), acquisition_time=None, acquisition_time_sec=None, trigger_times=set(), trigger_time_hint=None, role_hint='unknown', group_key=None, reason='')
Metadata for one DICOM series, produced by :func:discover_dicom.
| ATTRIBUTE | DESCRIPTION |
|---|---|
uid |
SeriesInstanceUID (
TYPE:
|
study_instance_uid |
StudyInstanceUID (
TYPE:
|
files |
All files belonging to this series, sorted.
TYPE:
|
description |
SeriesDescription (
TYPE:
|
series_number |
SeriesNumber (
TYPE:
|
dicom_modality |
DICOM Modality (
TYPE:
|
manufacturer |
Manufacturer (
TYPE:
|
flip_angle |
FlipAngle (
TYPE:
|
tr, te, field_strength |
RepetitionTime, EchoTime, MagneticFieldStrength.
TYPE:
|
rows, columns |
Image matrix size (from first file).
TYPE:
|
n_temporal_positions |
Count of unique
TYPE:
|
n_acquisition_numbers |
Count of unique
TYPE:
|
n_slice_locations |
Count of unique
TYPE:
|
image_types |
Unique
TYPE:
|
acquisition_time |
First file's AcquisitionTime (
TYPE:
|
acquisition_time_sec |
Parsed
TYPE:
|
trigger_times |
Unique
TYPE:
|
trigger_time_hint |
Seconds parsed from the SeriesDescription
TYPE:
|
role_hint |
Best-effort classification. See module docstring for meanings.
TYPE:
|
group_key |
For
TYPE:
|
reason |
Human-readable justification for the
TYPE:
|
discover_dicom
¶
Walk path, group DICOM files by series, and classify each series.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
Directory (or single file) to scan.
TYPE:
|
modality
|
Reserved for future modality-specific classification tweaks. Currently ignored — the heuristics do not change by modality because the signals they rely on (TPI, FlipAngle, ImageType, description patterns) are modality-agnostic.
TYPE:
|
recursive
|
Recurse into subdirectories. Handles both flat (NKI) and nested (TCIA) layouts.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[SeriesInfo]
|
One entry per unique |
Notes
Role hints (SeriesInfo.role_hint) are advisory. Callers can — and
should — inspect SeriesInfo directly when the heuristic is wrong.
A summary of the classification is logged at INFO level.
load_dicom_series
¶
Load one or more DICOM series as a :class:PerfusionDataset.
| PARAMETER | DESCRIPTION |
|---|---|
series
|
Either a single :class:
TYPE:
|
modality
|
Attached to the returned
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
PerfusionDataset
|
For single 3D series: |
| RAISES | DESCRIPTION |
|---|---|
IOError
|
If no magnitude frames can be read. |
DataValidationError
|
If a multi-series load sees inconsistent shapes across frames, or if fewer than 2 series are passed as a list. |