convert_source.imgio package¶
Submodules¶
convert_source.imgio.dcmio module¶
DICOM specific functions for convert_source. Primarily intended for converting and renaming DICOM files to BIDS NIFTI.
- exception convert_source.imgio.dcmio.DICOMerror¶
Bases:
Exception
- convert_source.imgio.dcmio.get_bwpppe(dcm_file)¶
Reads the Bandwidth Per Pixel PhaseEncode value from a DICOM header.
Note
This DICOM field is usually left blank on Philips DICOM headers.
- Parameters
dcm_file (
str
) – DICOM file.- Return type
Union
[float
,str
]- Returns
Bandwidth Per Pixel PhaseEncode value as a float, or empty string otherwise.
- convert_source.imgio.dcmio.get_mb(dcm_file)¶
Extracts multi-band acceleration factor from file description in the DICOM header for (philips MR scanners). If this information cannont be inferred from the DICOM header file description - then it is assumed to be 1.
Note
This is done via a regEx search as no DICOM tag stores this information explicitly.
- Parameters
dcm_file (
str
) – DICOM file.- Return type
int
- Returns
Multi-band acceleration factor.
- convert_source.imgio.dcmio.get_red_fact(dcm_file)¶
Extracts parallel reduction factor in-plane value (GRAPPA/SENSE) from file description in the DICOM header for Philips MR scanners. This reduction factor is assumed to be 1 if a value cannot be found from witin the DICOM header.
- Parameters
dcm_file (
str
) – DICOM file.- Return type
float
- Returns
Parallel reduction factor in-plane value (e.g. SENSE/GRAPPA factor), or 1.0 if not specified.
- convert_source.imgio.dcmio.get_scan_time(dcm_file)¶
Reads the scan time from the DICOM header.
- Parameters
dcm_file (
str
) – DICOM file.- Return type
Union
[float
,str
]- Returns
Acquisition duration (scan time, in s) as a float if it exists, or an empty string otherwise.
- convert_source.imgio.dcmio.is_valid_dcm(dcm_file, raise_exc=False, verbose=False)¶
Checks for a valid DICOM file by inspecting the conversion type label in the DICOM file header. This field should be blank. If this label is populated, then it is likely a secondary capture image and thus is not likely to contain meaningful image information.
- Parameters
dcm_file (
str
) – DICOM file.raise_exc (
Optional
[bool
]) – Raises exception in the case that execution needs to be halted.verbose (
Optional
[bool
]) – Enable verbosity.
- Return type
bool
- Returns
True if DICOM file is not a secondary capture (or does not have text in the conversion type label field), and False otherwise.
- Raises
DICOMerror – Error that arises if the DICOM in question is not a valid DICOM, and the ‘raise_exc’ option is set to True.
convert_source.imgio.niio module¶
NIFTI specific functions for convert_source. Primarily intended for renaming NIFTI to be BIDS compliant.
- convert_source.imgio.niio.get_data_params(file, json_file='')¶
Creates a dictionary of key mapped parameter items that are often not written to the BIDS JSON sidecar when converting Philips DICOM and PAR REC files.
- Parameters
file (
str
) – Filepath to raw image data file (DICOM or PAR REC).json_file (
Optional
[str
]) – Corresponding JSON sidecare file.
- Return type
Dict
- Returns
Dictionary of BIDS related key mapped items/values.
- convert_source.imgio.niio.get_nii_tr(nii_file)¶
Reads the NIFTI file header and returns the repetition time (TR, sec) as a value if it is not zero, otherwise this function returns an string.
- Parameters
nii_file (
str
) – NIFTI image filename.- Return type
Union
[float
,str
]- Returns
Repetition time (TR, sec), if not zero, or an empty string otherwise.
- convert_source.imgio.niio.get_num_frames(nii_file)¶
Determines the number of frames/volumes/TRs in a NIFTI-2 file.
- Parameters
nii_file (
str
) – NIFTI image file.- Return type
int
- Returns
Number of temporal frames or volumes in NIFTI file.
convert_source.imgio.pario module¶
PAR REC specific functions for convert_source. Primarily intended for converting and renaming PAR REC files to BIDS NIFTI.
- exception convert_source.imgio.pario.PARfileReadError¶
Bases:
Exception
- convert_source.imgio.pario.get_echo_time(par_file, tmp_dir=None, raise_exc=False)¶
Reads the echo time (TE, in sec.) from a PAR header file.
Note
Echo time is obtained from the PAR file header by reading in the PAR header file as a pandas dataframe, followed by saving the resulting dataframe as a M x N | N = 35. The echo times are stored in the resulting matrix (constructed from numpy as a numpy multi-dimensional array) in row 16 (count starts at 0).
- Usage example:
>>> get_echo_time(par_file="File.PAR") 88.0
- Parameters
par_file (
str
) – PAR header file.tmp_dir (
Optional
[str
]) – Path to temporary directory.raise_exc (
Optional
[bool
]) – Raise exception in the case of multi-echo acquisitions.
- Return type
float
- Returns
Echo time as a float or
None
in the case of multi-echo data.- Raises
PARfileReadError – Exception that is raised if multi-echo PAR files are used as inputs.
- convert_source.imgio.pario.get_etl(par_file)¶
Gets EPI factor (Echo Train Length) from Philips’ PAR Header.
Note
This is done via a regEx search as the PAR header is not assumed to change significantly between scanners.
- Parameters
par_file (
str
) – PAR header file.- Return type
int
- Returns
Echo Train Length as integer.
- convert_source.imgio.pario.get_flip_angle(par_file, tmp_dir=None, raise_exc=False)¶
Reads the flip angle (in degrees) from a PAR header file.
Note
Flip angle is obtained from the PAR file header by reading in the PAR header file as a pandas dataframe, followed by saving the resulting dataframe as a M x N | N = 35. The flip angles are stored in the resulting matrix (constructed from numpy as a numpy multi-dimensional array) in row 21 (count starts at 0).
- Usage example:
>>> get_flip_angle(par_file="File.PAR") 90.0
- Parameters
par_file (
str
) – PAR header file.tmp_dir (
Optional
[str
]) – Path to temporary directory.raise_exc (
Optional
[bool
]) – Raise exception in the case of multiple flip angles are found.
- Return type
float
- Returns
Flip angle as a float or None if multiple flip angles are found.
- Raises
PARfileReadError – Exception that is raised if input PAR file contains multiple flip angles.
- convert_source.imgio.pario.get_mb(par_file)¶
Extracts multi-band acceleration factor from from Philips’ PAR Header.
Note
This is done via a regEx search as the PAR header does not normally store this value.
- Parameters
par_file (
str
) – Absolute filepath to PAR header file- Return type
int
- Returns
Multi-band acceleration factor (as an int).
- convert_source.imgio.pario.get_red_fact(par_file)¶
Extracts parallel reduction factor in-plane value (SENSE factor) from the file description in the PAR REC header for Philips MR scanners. This reduction factor is assumed to be 1 if a value cannot be found from witin the PAR REC header.
Note
This is done via a regEx search as the PAR header is not assumed to change significantly between scanners.
- Parameters
par_file (
str
) – PAR header file.- Return type
float
- Returns
Parallel reduction factor in-plane value (e.g. SENSE factor, as a float).
- convert_source.imgio.pario.get_scan_time(par_file)¶
Gets the acquisition duration (scan time, in s) from the PAR header.
Note
This is done via a regEx search as the PAR header is not assumed to change significantly between scanners.
- Parameters
par_file (
str
) – PAR header file.- Return type
Union
[float
,str
]- Returns
Acquisition duration (scan time, in s). If not in header, an empty string is returned.
- convert_source.imgio.pario.get_wfs(par_file)¶
Gets Water Fat Shift from Philips’ PAR Header.
Note
This is done via a regEx search as the PAR header is not assumed to change significantly between scanners.
- Parameters
par_file (
str
) – PAR header file.- Return type
float
- Returns
Water Fat Shift as a float.