Utilities¶
Module contents¶
General app utilities.
Submodules¶
django_mri.utils.bids module¶
Definition of the Bids
class.
-
class
django_mri.utils.bids.
Bids
(scan)¶ Bases:
object
A class to compose BIDS-appropriate paths for usage by dcm2niix In short, standard template for BIDS-appropriate path is: sub-<label>/<data_type>/sub-<label>_<modality_label>
References
-
DATASET_DESCRIPTION_FILE_NAME
= 'dataset_description.json'¶
-
PARTICIPANTS_FILE_NAME
= 'participants.tsv'¶
-
calculate_age
(born: datetime.date) → float¶ Returns age by date of birth.
Parameters: born (datetime.date) – Subject’s birth date Returns: Subject’s age Return type: float
-
clean_unwanted_files
(bids_path: pathlib.Path)¶ Clean irrelevant .bvec and .bval files; Some versions of dcm2niix produce .bvec and .bval for fieldmap images as well as dwi images. Since BIDS specifications do now allow such files under “fmap” data-type, this method deletes them from the relevant directory.
Parameters: bids_path (Path) – Path to the BIDS-compatible directory
-
compose_bids_path
()¶ Uses parameters extracted by {self.get_data} to compose a BIDS- compatible file path
Returns: Full path to a BIDS-compatible file, according to scan’s parameters. Return type: pathlib.Path
-
fix_functional_json
(bids_path: pathlib.Path)¶ Add required “TaskName” field to functional scan, as stated in BIDS stucture.
Parameters: bids_path (Path) – Path to the BIDS-compatible directory References
-
generate_bidsignore
(parent: pathlib.Path)¶ Some acquisitions do not conform to BIDS specification (mainly localizers), so we generate a .bidsignore file, pointing to them.
Parameters: parent (Path) – BIDS-compatible directory, underwhich there are “sub-x” directories References
-
generate_readme
(parent: pathlib.Path)¶ It is recommended by BIDS specifications to have a README file at the base of our project, so we create a blank one for further usage.
Parameters: parent (Path) – BIDS-compatible directory, underwhich there are “sub-x” directories
-
get_data
()¶ Extracts relevant parameters for BIDS-compatible naming.
Returns: - parent (Path) – Parent BIDS directory, under which there will be “sub-x” directories
- data_type (str) – sub-directory under “sub-x”. either “anat”,”func”,”fmap” or “dwi”
- modality_label (str) – modality label as described in BIDS specifications. either “dwi”, “epi”,”T1w”,”FLAIR”,”bold” or “localizer”
- task (Union[str, None]) – task name for functional scans. “rest” or None
- pe_dir (Union[str, None]) – PhaseEncodingDirection for DWI-related images or fieldmap-related images. Either “AP”,”PA” or None
-
get_subject_data
()¶ Extract relevant Scan-related subject’s parameters, as stated by BIDS structure.
Returns: subject’s relevant parameters, sorted by “participant_id”, “handedness”,”age” and “sex” fields Return type: subject_dict[dict]
-
set_description_json
(parent: pathlib.Path)¶ Generates required “dataset_description.json” file, as stated by BIDS structure.
Parameters: parent (Path) – BIDS-compatible directory, underwhich there are “sub-x” directories References
-
set_participant_tsv_and_json
(parent: pathlib.Path, subject_dict: dict)¶ Generates recommended “participants.tsv” by either copying the template from TEMPLATES_DiR or editing an existing one under {parent} directory.
Parameters: - parent (Path) – BIDS-compatible directory, underwhich there are “sub-x” directories
- subject_dict (dict) – Subject’s parameters dictionary, containing “participant_id”, “handedness”,”age”,”sex” fields
References
-
django_mri.utils.compression module¶
Definition of the compress()
and
uncompress()
utility functions.
-
django_mri.utils.compression.
compress
(source: pathlib.Path, destination: pathlib.Path = None, keep_source: bool = True) → pathlib.Path¶ Compresses the provided source file.
Parameters: - source (Path) – File to compress
- destination (Path, optional) – Compressed output file path, by default None
- keep_source (bool, optional) – Whether to keep the source file or not, by default True
Returns: Output file path
Return type: Path
-
django_mri.utils.compression.
uncompress
(source: pathlib.Path, destination: pathlib.Path = None, keep_source: bool = True) → pathlib.Path¶ Uncompresses the provided (compressed) source file.
Parameters: - source (Path) – File to uncompress
- destination (Path, optional) – Uncompressed output file path, by default None
- keep_source (bool, optional) – Whether to keep the source file or not, by default True
Returns: Output file path
Return type: Path
django_mri.utils.messages module¶
A module storing strings used to display messages.
django_mri.utils.scan_type module¶
Definition of the django_mri.utils.scan_type.ScanType
Enum.
django_mri.utils.utils module¶
General app utilites.
-
django_mri.utils.utils.
DEFAULT_DICOM_DIR_NAME
= 'DICOM'¶ The name of the subdirectory under the MRI data root in which DICOM files will be saved.
-
django_mri.utils.utils.
DEFAULT_MRI_DIR_NAME
= 'MRI'¶ The name of the subdirectory under MEDIA_ROOT in which MRI data will be saved.
-
django_mri.utils.utils.
DEFAULT_STUDY_GROUP_MODEL
= 'research.Group'¶ Default identifier for a study group model scans should be related to.
-
django_mri.utils.utils.
DEFAULT_SUBJECT_MODEL
= 'research.Subject'¶ Default identifier for a subject model scans should be related to.
-
django_mri.utils.utils.
get_dicom_root
() → pathlib.Path¶ Returns the path of the directory in which DICOM data should be saved.
-
django_mri.utils.utils.
get_group_model
()¶ Returns the study group model MRI scans should be related to.
Returns: Study group model Return type: django.db.models.Model
-
django_mri.utils.utils.
get_mri_root
() → pathlib.Path¶ Returns the path of the directory in which MRI data should be saved.
-
django_mri.utils.utils.
get_subject_model
()¶ Returns the subject model MRI scans should be related to.
Returns: Subject model Return type: django.db.models.Model