pyalfe.data_structure#
- class pyalfe.data_structure.Modality(value)[source]#
Bases:
StrEnum
An enumeration.
- T1 = 'T1'#
- T1Post = 'T1Post'#
- T2 = 'T2'#
- FLAIR = 'FLAIR'#
- SWI = 'SWI'#
- DWI = 'DWI'#
- SingleDWI = 'SingleDWI'#
- ADC = 'ADC'#
- EADC = 'EADC'#
- CBF = 'CBF'#
- ASL = 'ASL'#
- PERFUSION = 'PERFUSION'#
- class pyalfe.data_structure.Orientation(value)[source]#
Bases:
StrEnum
An enumeration.
- AXIAL = 'AXIAL'#
- SAGITTAL = 'SAGITTAL'#
- CORONAL = 'CORONAL'#
- class pyalfe.data_structure.Tissue(value)[source]#
Bases:
IntEnum
An enumeration.
- BACKGROUND = 0#
- CSF = 1#
- CORTICAL_GRAY_MATTER = 2#
- WHITE_MATTER = 3#
- DEEP_GRAY_MATTER = 4#
- BRAIN_STEM = 5#
- CEREBELLUM = 6#
- class pyalfe.data_structure.Series(series_path, instances)#
Bases:
tuple
- instances#
Alias for field number 1
- series_path#
Alias for field number 0
- class pyalfe.data_structure.PipelineDataDir[source]#
Bases:
ABC
Abstract PipelineDataDir
- get_output_image(accession, modality, image_type=None, resampling_target=None, resampling_origin=None, sub_dir_name=None, extension='.nii.gz')[source]#
- Generates the path for an output image. All the implementations
should make the parent directories if they do not exist.
- Parameters:
accession (str) – The accession or study number.
modality (Modality or str) – Image modality.
image_type (str, default=None) – Image type. For example: skullstripped.
resampling_target (Modality or str, default=None) – The target space that the image has been resampled to. For example, for a T2 image that is resampled to FLAIR, resampling target is FLAIR.
resampling_origin (Modality, str, default=None) – The origin of image before resampling. For example, if a template image is resampled to T1, the resampling origin is template.
sub_dir_name (str, default=None) – The name of the sub directory inside the modality directory in which the image is stored. If None the image is stored directory inside the modality directory.
extension (str, default='.nii.gz') – The extension of the image.
- Returns:
The path to output image.
- Return type:
str
- get_input_image(accession, modality, extension='.nii.gz')[source]#
Generates the path for an input image.
- Parameters:
accession (str) – The accession or study number.
modality (Modality or str) – Image modality.
extension (str, default='.nii.gz') – The extension of the image.
- Returns:
The path to input image.
- Return type:
str
- get_quantification_file(accession, modality, quantification_file_type, extension='.csv')[source]#
Generates the path for an output quantification file. All the implementations should make the parent directories if they do not exist.
- Parameters:
accession (str) – The accession or study number.
modality (Modality or str) – Image modality.
quantification_file_type (str, default=None) – Image type. For example: SummaryLesionMeasures.
extension (str, default='.csv') – The extension of the quantification.
- Returns:
The path to quantification file.
- Return type:
str
- class pyalfe.data_structure.DefaultALFEDataDir(output_dir, input_dir)[source]#
Bases:
PipelineDataDir
Default implementation of PipelineDataDir
- get_output_image(accession, modality, image_type=None, resampling_target=None, resampling_origin=None, sub_dir_name=None, extension='.nii.gz')[source]#
Generate the path for an output image in ALFE default dir structure format.
- Parameters:
accession (str) – The accession or study number.
modality (Modality or str) – Image modality.
image_type (str, default=None) – Image type. For example: skullstripped.
resampling_target (Modality or str, default=None) – The target space that the image has been resampled to. For example, for a T2 image that is resampled to FLAIR, resampling target is FLAIR.
resampling_origin (Modality, str, default=None) – The origin of image before resampling. For example, if a template image is resampled to T1, the resampling origin is template.
sub_dir_name (str, default=None) – The name of the sub directory inside the modality directory in which the image is stored. If None the image is stored directory inside the modality directory.
extension (str, default='.nii.gz') – The extension of the image.
- Returns:
The path to output image.
- Return type:
str
Examples
>>> from pyalfe.data_structure import DefaultALFEDataDir >>> data_dir = DefaultALFEDataDir( output_dir='/mri-data/processed', input_dir='/mri-data/input') >>> data_dir.get_output_image('34521', 'T1') '/mri-data/processed/34521/T1/34521_T1.nii.gz'
>>> data_dir.get_output_image( '34521', 'T2', image_type='skullstrippied') '/mri-data/processed/34521/T2/34521_T2_skullstrippied.nii.gz'
>>> data_dir.get_output_image( '34521', 'T1Post', resampling_target='T1Post', resampling_origin='template') '/mri-data/processed/34521/T1Post/34521_template_to_T1Post.nii.gz'
>>> data_dir.get_output_image( '34521', 'T2', image_type='abnormal_seg', sub_dir_name='abnormalmap') '/mri-data/processed/34521/T2/abnormalmap/34521_T2_abnormal_seg.nii.gz'
- get_input_image(accession, modality, extension='.nii.gz')[source]#
Generate the path for an input image in ALFE default dir structure format.
- Parameters:
accession (str) – The accession or study number.
modality (Modality or str) – Image modality.
extension (str, default='.nii.gz') – The extension of the image.
- Returns:
The path to input image.
- Return type:
str
Examples
>>> from pyalfe.data_structure import DefaultALFEDataDir >>> data_dir = DefaultALFEDataDir( output_dir='/mri-data/processed', input_dir='/mri-data/input') >>> data_dir.get_input_image('34521', 'T1') '/mri-data/input/34521/T1/T1.nii.gz'
- get_quantification_file(accession, modality, quantification_file_type, extension='.csv')[source]#
Generate the path for a quantification file in ALFE default dir structure format.
- Parameters:
accession (str) – The accession or study number.
modality (Modality or str) – Image modality.
quantification_file_type (str, default=None) – Image type. For example: SummaryLesionMeasures.
extension (str, default='.csv') – The extension of the quantification.
- Returns:
The path to quantification file.
- Return type:
str
Examples
>>> from pyalfe.data_structure import DefaultALFEDataDir >>> data_dir = DefaultALFEDataDir( output_dir='/mri-data/processed', input_dir='/mri-data/input') >>> data_dir.get_quantification_file( '34521', 'T1Post', quantification_file_type='IndividualLesionMeasures') '/mri-data/processed/34521/T1Post/quantification/34521_IndividualLesionMeasures.csv'
- class pyalfe.data_structure.BIDSDataDir(output_dir, input_dir)[source]#
Bases:
PipelineDataDir
BIDS almost-compliant implementation of PipelineDataDir
- logger = <Logger BIDSDataDir (DEBUG)>#
- modality_dict = {Modality.ADC: {'datatype': 'dwi', 'suffix': 'md'}, Modality.ASL: {'datatype': 'perf', 'suffix': 'asl'}, Modality.CBF: {'datatype': 'perf', 'suffix': 'cbf'}, Modality.FLAIR: {'datatype': 'anat', 'suffix': 'FLAIR'}, Modality.SWI: {'datatype': 'swi', 'suffix': 'swi'}, Modality.T1: {'datatype': 'anat', 'suffix': 'T1w'}, Modality.T1Post: {'ceagent': 'gadolinium', 'datatype': 'anat', 'suffix': 'T1w'}, Modality.T2: {'datatype': 'anat', 'suffix': 'T2w'}}#
- get_input_image(accession, modality, extension='.nii.gz')[source]#
Generates the path for an input image in BIDS dir structure format.
- Parameters:
accession (str) – The accession or study number.
modality (Modality or str) – Image modality.
extension (str, default='.nii.gz') – The extension of the image.
- Returns:
The path to input image.
- Return type:
str
Examples
>>> from pyalfe.data_structure import BIDSDataDir >>> data_dir = BIDSDataDir( output_dir='/mri-data/processed', input_dir='/mri-data/input') >>> data_dir.get_input_image('34521', 'T1') '/mri-data/input/sub-34521/anat/sub-34521_T1w.nii.gz'
>>> data_dir.get_input_image('34521', 'ADC') '/mri-data/input/sub-34521/derivative/dwi/sub-34521_md.nii.gz'
>>> data_dir.get_input_image('34521', 'CBF') '/mri-data/input/sub-34521/derivative/perf/sub-34521_cbf.nii.gz'
>>> data_dir.get_input_image('34521', 'SWI') '/mri-data/input/sub-34521/derivative/swi/sub-34521_swi.nii.gz'
>>> data_dir.get_input_image('34521', 'T1Post') '/mri-data/input/sub-34521/anat/sub-34521_ce-gadolinium_T1w.nii.gz'
- get_output_image(accession, modality, image_type=None, resampling_target=None, resampling_origin=None, sub_dir_name=None, extension='.nii.gz')[source]#
Generates the path for an output image in BIDS dir structure format.
- Parameters:
accession (str) – The accession or study number.
modality (Modality or str) – Image modality.
image_type (str, default=None) – Image type. For example: skullstripped.
resampling_target (Modality or str, default=None) – The target space that the image has been resampled to. For example, for a T2 image that is resampled to FLAIR, resampling target is FLAIR.
resampling_origin (Modality, str, default=None) – The origin of image before resampling. For example, if a template image is resampled to T1, the resampling origin is template.
sub_dir_name (str, default=None) – The name of the sub directory inside the modality directory in which the image is stored. If None the image is stored directory inside the modality directory.
extension (str, default='.nii.gz') – The extension of the image.
- Returns:
The path to output image.
- Return type:
str
Examples
>>> from pyalfe.data_structure import BIDSDataDir >>> data_dir = BIDSDataDir( output_dir='/mri-data/processed', input_dir='/mri-data/input') >>> data_dir.get_output_image('34521', 'T1') '/mri-data/processed/sub-34521/anat/sub-34521_T1w.nii.gz'
>>> data_dir.get_output_image('34521', 'T2', image_type='skullstrippied') '/mri-data/processed/sub-34521/anat/sub-34521_desc-skullstrippied_T2w.nii.gz'
>>> data_dir.get_output_image( '34521', 'T1Post', resampling_target='T1Post', resampling_origin='template') '/mri-data/processed/sub-34521/anat/sub-34521_ce-gadolinium_space-orig_desc-template_T1w.nii.gz'
>>> data_dir.get_output_image( '34521', 'T2', image_type='abnormal_seg', sub_dir_name='abnormalmap') '/mri-data/processed/sub-34521/anat/sub-34521_desc-abnormalseg_dseg.nii.gz'
- get_quantification_file(accession, modality, quantification_file_type, extension='.csv')[source]#
Generate the path for a quantification file in BIDS dir structure format.
- Parameters:
accession (str) – The accession or study number.
modality (Modality or str) – Image modality.
quantification_file_type (str, default=None) – Image type. For example: SummaryLesionMeasures.
extension (str, default='.csv') – The extension of the quantification.
- Returns:
The path to quantification file.
- Return type:
str
Examples
>>> from pyalfe.data_structure import BIDSDataDir >>> data_dir = BIDSDataDir( output_dir='/mri-data/processed', input_dir='/mri-data/input') >>> data_dir.get_quantification_file( '34521', 'T1Post', quantification_file_type='IndividualLesionMeasures') '/mri-data/processed/sub-34521/anat/quantification/sub-34521_ce-gadolinium_desc-T1Post_IndividualLesionMeasures.csv'
- class pyalfe.data_structure.PatientDicomDataDir(dicom_dir)[source]#
Bases:
object
This class is designed to work with directories containing raw dicom files for a patient that are organized as: dicom_dir
- └─ accession (study)
- └─ series
├─ instance_0.dcm └─ instance_1.dcm
- is_dicom_file(file)[source]#
Function to check if file is a dicom file. The first 128 bytes are preamble the next 4 bytes should contain DICM otherwise it is not a dicom file. Adapted from icometrix/dicom2nifti
- Parameters:
file (str) – file to check for the DICM header block
- Returns:
True if it is a dicom file otherwise False.
- Return type:
bool