brain_deer.infrastructure.bids.import_convert

Convert DICOM or flat NIfTI folders into a minimal BIDS layout.

DICOM import is pure Python (pydicom + nibabel) — no MATLAB, no Lead-DBS binaries. The default session split mirrors the common DBS clinical layout:

  • ses-preop — structural MR (T1w / T2w / FLAIR / SWI / …)

  • ses-postop — post-op CT (and CT variants via acq-)

  • One NIfTI per (session, suffix, acq) — no runaway run-* spam

  • When several series collide on the same key, keep the latest study date

Classes

ImportReviewRow

Editable mapping row shown in the review UI before commit.

Functions

guess_suffix_datatype(→ tuple[str, str])

Return (suffix, datatype_folder) from filename / DICOM / folder hints.

classify_dicom_series(→ SeriesPlan | None)

Map one DICOM series to BIDS session/suffix/acq, or None to skip.

discover_dicom_subject_folders(→ list[tuple[str, ...)

Find (subject_id, dicom_folder) pairs under a cohort or single-patient tree.

plan_dicom_import(→ list[ImportReviewRow])

Dry-run: discover subjects/series and return editable review rows (no writes).

commit_dicom_import(→ pathlib.Path)

Write reviewed rows to rawdata/ + Lead-DBS-style rawimages.json.

import_dicom_to_bids(→ pathlib.Path)

Convert DICOM series into a BIDS tree. Returns dataset root.

bidsify_flat_folder(→ pathlib.Path)

Organize loose NIfTI/TRK files into a BIDS-like tree.

Module Contents

brain_deer.infrastructure.bids.import_convert.guess_suffix_datatype(filename: str, *, modality: str = '', description: str = '', path_hint: str = '') → tuple[str, str]

Return (suffix, datatype_folder) from filename / DICOM / folder hints.

brain_deer.infrastructure.bids.import_convert.classify_dicom_series(series, *, session_mode: str = 'clinical', session_override: str | None = None) → SeriesPlan | None

Map one DICOM series to BIDS session/suffix/acq, or None to skip.

brain_deer.infrastructure.bids.import_convert.discover_dicom_subject_folders(root: str | pathlib.Path) → list[tuple[str, pathlib.Path]]

Find (subject_id, dicom_folder) pairs under a cohort or single-patient tree.

  • Cohort (e.g. HOTDBS1): each child dir is one patient → one subject.

  • Single patient folder: returns that folder alone (not one subject per date).

  • Flat DICOM dump: returns (folder_name, root).

class brain_deer.infrastructure.bids.import_convert.ImportReviewRow

Editable mapping row shown in the review UI before commit.

brain_deer.infrastructure.bids.import_convert.plan_dicom_import(dicom_dir: str | pathlib.Path, *, subject: str = 'auto', session: str = 'auto', series_indices: list[int] | None = None, session_mode: str = 'clinical') → list[ImportReviewRow]

Dry-run: discover subjects/series and return editable review rows (no writes).

brain_deer.infrastructure.bids.import_convert.commit_dicom_import(rows: list[ImportReviewRow], output_root: str | pathlib.Path, *, dataset_name: str = 'BrainDeer DICOM import', source: str | pathlib.Path | None = None, progress_callback=None) → pathlib.Path

Write reviewed rows to rawdata/ + Lead-DBS-style rawimages.json.

brain_deer.infrastructure.bids.import_convert.import_dicom_to_bids(dicom_dir: str | pathlib.Path, output_root: str | pathlib.Path, *, subject: str = 'auto', session: str = 'auto', dataset_name: str = 'BrainDeer DICOM import', series_indices: list[int] | None = None, session_mode: str = 'clinical', progress_callback=None, review_rows: list[ImportReviewRow] | None = None) → pathlib.Path

Convert DICOM series into a BIDS tree. Returns dataset root.

Pure Python — does not call MATLAB or Lead-DBS.

Pass review_rows from the mapping UI to skip re-planning; otherwise plans automatically (no interactive review — use the dialog for that).

brain_deer.infrastructure.bids.import_convert.bidsify_flat_folder(source_dir: str | pathlib.Path, output_root: str | pathlib.Path, *, subject: str = '01', session: str = '01', dataset_name: str = 'BrainDeer BIDSify import', copy_files: bool = True) → pathlib.Path

Organize loose NIfTI/TRK files into a BIDS-like tree.