dicom2nifti
tit.pre.dicom2nifti ¶
Source-image ingestion with BIDS-compliant naming.
Converts each modality found under sourcedata/sub-{id}/ into a
BIDS-named NIfTI (sub-{id}_{suffix}.nii.gz). DICOM series are
converted with dcm2niix; a modality folder that already holds a
NIfTI is copied into place instead.
Public API¶
run_dicom_to_nifti
Ingest every supported modality for a subject.
MODALITIES
Supported modalities and their BIDS datatype directories.
bids_outputs
The files a conversion of one modality wrote.
pe_direction_label
The BIDS dir- label of a phase-encoding direction in a NIfTI.
See Also¶
tit.pre.structural.run_pipeline : Full preprocessing pipeline.
bids_outputs ¶
Files a conversion of modality wrote into output_dir.
sub-{id}_{suffix} and sub-{id}_dir-{label}_{suffix} with their
sidecars, NIfTIs first.
Source code in tit/pre/dicom2nifti.py
pe_direction_label ¶
BIDS dir- label (AP, PA, LR, RL, SI, IS) for a phase-encoding direction.
PhaseEncodingDirection names a voxel axis of nifti and travels from index
0 to the last index unless it ends in -. The label is the world direction
of that travel, taken from the NIfTI's sform and rounded to the closest
cardinal axis, as BIDS asks of AP/PA-style labels. None when the
direction or the sform is missing -- a label is never guessed.
Source code in tit/pre/dicom2nifti.py
converted_nifti ¶
The NIfTI an earlier ingestion of modality left in output_dir, or None.
Both extensions count: we always write .nii.gz, but a hand-placed
.nii is the same BIDS entity. dir- variants count as well.
Source code in tit/pre/dicom2nifti.py
run_dicom_to_nifti ¶
run_dicom_to_nifti(project_dir: str, subject_id: str, *, logger, runner: CommandRunner | None = None, skip_existing: bool = False) -> None
Ingest a subject's source images into BIDS-named NIfTI files.
Looks for a T1w, T2w, ct, dwi and fmap folder under
sourcedata/sub-{subject_id}/ (folder names are matched
case-insensitively) and ingests each one that exists. Anatomical images
and CT go to the subject's anat/ folder, diffusion images to dwi/
(with their .bval/.bvec sidecars), and the DWI's reverse
phase-encoding series to fmap/sub-{id}_dir-{label}_epi.nii.gz with an
IntendedFor naming the DWI. Two diffusion series in dwi with
different phase encoding become sub-{id}_dir-{label}_dwi. The label
(AP, PA, ...) comes from :func:pe_direction_label.
Each modality folder is searched recursively. Supported archives
(.zip, .tar, .tar.gz, .tgz) are safely extracted to
extracted_archives/ first. DICOM files (.dcm/.dicom, or any
file carrying the DICOM Part 10 DICM prefix, such as .IMA or
extensionless exports) are then converted with dcm2niix; if the folder
holds no DICOMs but does hold a NIfTI, that file is copied into place
instead (compressing a bare .nii on the way). Dotfiles are ignored
throughout.
CT is written as anat/sub-{id}_ct.nii.gz. This is a local convention,
not BIDS -- see :data:MODALITIES.
Parameters¶
project_dir : str
BIDS project root directory.
subject_id : str
Subject identifier without the sub- prefix.
logger : logging.Logger
Logger for progress messages.
runner : CommandRunner or None, optional
Subprocess runner for streaming output.
skip_existing : bool, optional
Leave a modality whose NIfTI already exists as it is and ingest the
others, instead of raising.
Raises¶
PreprocessError If an output NIfTI already exists for a modality (unless skip_existing), or if modality folders hold files and nothing at all could be ingested from them.
See Also¶
run_pipeline : Full preprocessing pipeline. MODALITIES : Supported modalities and their BIDS datatype directories.
Source code in tit/pre/dicom2nifti.py
701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 | |