mia_processes.utils package¶
Utilities and tools used across mia_processes
- Contains:
- Modules:
report.py
tools.py
Submodules¶
mia_processes.utils.report module¶
Module dedicated to report generation
- Contains:
- Class:
Report
- class mia_processes.utils.report.Report(report_file, dict4runtime, **kwargs)[source]¶
Bases:
object
Create pdf report
- In the constructor, certain kwarg keys will specialise the report:
CVR: CVR report
GE2REC: GE2REC report
IQMs_file: MRIQC individual report (with all IQMs)
mriqc_group: MRIQC report group
Perf_DSC: DSC perfusion report
- Methods:
co2_inhal_cvr_make_report
ge2rec_make_report
get_iqms_data
mriqc_anat_make_report
mriqc_func_make_report
mriqc_group_make_report
perf_dsc_make_report
mia_processes.utils.tools module¶
Module that contains multiple functions used across mia_processes
- Contains:
- Class:
PageNumCanvas
ReportLine
- Functions:
checkFileExt
del_dbFieldValue
dict4runtime_update
get_dbFieldValue
mriqc_get_all_run
mriqc_group_iqms_tsv
plot_boxplot_points
plot_qi2
plot_segmentation
plot_slice_planes
plot_realignment_parameters
set_dbFieldValue
- class mia_processes.utils.tools.PageNumCanvas(*args, **kwargs)[source]¶
Bases:
Canvas
For add “page number of total” in each footer.
- class mia_processes.utils.tools.ReportLine(width, height=0)[source]¶
Bases:
Flowable
Line flowable — draws a line in a flowable
- mia_processes.utils.tools.checkFileExt(in_file, ext_dic)[source]¶
Check file extension
- Parameters:
in_file – file name (a string)
ext_dic – dictionary of the valid extensions for the file (dictionary, ex: EXT = {‘NIFTI_GZ’: ‘nii.gz’, ‘NIFTI’: ‘nii’})
- Returns:
valid_bool: True if extension is valid (a boolean)
in_ext: file extension (a string)
file_name: file name without extension (a string)
- mia_processes.utils.tools.check_orientations(images, verbose=True)[source]¶
Check the dimensions and orientations of the images.
images: images from nibabel verbose: whether to create a verbose returned message.
- returns: status: status (True means OK)
message: string describing status (empty if OK)
- mia_processes.utils.tools.del_dbFieldValue(project, document, tags2del)[source]¶
Delete for a document, the value for a field in the db.
- Parameters:
project – the project.
document – the absolute path of the document.
tag_to_del – a list of fields where values will be deleted
- mia_processes.utils.tools.dict4runtime_update(dict4runtime, database, db_filename, *args)[source]¶
Update the dict4runtime dictionary object with tags values
- Parameters:
dict4runtime – the dict used in mia_processes bricks to pass data from the list_outputs method to the run_process_mia method
database – the database object (for example: self.project.session)
db_filename – the name of the database file from which the tag value will be retrieved
args – the tags to be recovered
- mia_processes.utils.tools.get_dbFieldValue(project, document, field)[source]¶
Return, for a document, the field value from the database.
- Parameters:
project – the project.
document – the absolute path of the document.
field – the field name.
- Returns:
the value of the field for the document in the database.
- mia_processes.utils.tools.mriqc_get_all_run(modality, project, output_directory)[source]¶
Get all raw files name with a mriqc run for one project and for one modality.
- Parameters:
modality – modality (a string, ‘bold’ or ‘anat’)
project – the project (Project Object)
output_directory – output directory where all json files are stored (a string that representing a path)
- Returns:
files_names (a list)
- mia_processes.utils.tools.mriqc_group_iqms_tsv(modality, output_directory)[source]¶
Get all IQMs from mriqc json report for one project and for one modality and put them together in one tsv file.
- Parameters:
modality – modality (a string, ‘bold’ or ‘anat’)
output_directory – output directory where all json files are stored (a string that representing a path)
- Returns:
dataframe: all IQMs in a panda dataframe
out_tsv: out tsv file (a string that representing a file)
- mia_processes.utils.tools.plot_boxplot_points(dataframe, title, ylabel, out_file=None)[source]¶
Plot boxplot with points data and save the figure in a png image
- Parameters:
dataframe – tabular data (a pandas dataframe)
title – figure title (a string)
ylabel – y axis label (a string)
out_file – out figure path (a string)
- Returns:
out_file: out figure path (a string)
- mia_processes.utils.tools.plot_qi2(x_grid, ref_pdf, fit_pdf, ref_data, cutoff_idx, out_file=None)[source]¶
bla bla
- mia_processes.utils.tools.plot_realignment_parameters(realignment_parameters, vox_size, out_file_tra, out_file_rot, figsize=(12, 5.6))[source]¶
Plot SPM realignment parameters.
- Parameters:
realignment_parameters – realignment parameters file (a string representing an existing file) or realignment parameters (a numpy.ndarray object with shape[1] == 6)
vox_size – voxel size of the data (a list of 3 float or integer)
out_file_tra – out path for the translation figure (a string representing a path file)
out_file_rot – out path for the rotation figure (a string representing a path file)
figsize – width, height of parametric maps plot, in inches (float, float)
- Returns:
qc: result of the quality check (a boolean). True: OK
- mia_processes.utils.tools.plot_segmentation(anat_file, segmentation, name, out_dir=None, **kwargs)[source]¶
Adapted from <https://github.com/nipreps/mriqc/blob/5a0f0408bd0c176dbc46088c6ffe279269180f3f/mriqc/viz/utils.py#L550>
- mia_processes.utils.tools.plot_slice_planes(data_1, data_2=None, plane='ax', fig_rows=4, fig_cols=4, slice_start=None, slice_step=None, dyn=1, cmap_1='Greys_r', vmin_1=None, vmax_1=None, cmap_2='rainbow', vmin_2=None, vmax_2=None, out_dir=None, only_noise=False, out_name=None)[source]¶
Create a PNG file with a mosaic display of volume slices.
Several images can be overlaid. data_1, the only mandatory argument, is the background image (or the only image displayed). data_2 is the image (or images) superimposed on data_1.
fig_rows, fig_cols, slice_start and slice_step are optional. If they are not known, plot_slice_planes will try to adapt as best it can to obtain an acceptable display. The default values for fig_rows, fig_cols and dyn are 4, 4 and 1 respectively.
- Parameters:
data_1 – an existing, image file (valid extensions: .nii).
data_2 – an existing, image file or a list of existing image files (valid extensions: .nii).
plane – orientation plane (ax, sag or cor)
fig_rows – the number of rows in the images panel (integer).
fig_cols – the number of columns in the images panel (integer).
slice_start – starting slice number to be displayed (integer).
slice_step – the gap between each slice to be displayed (integer).
dyn – the volume number in the space-time, for 4D (integer).
cmap_1 – the color map name (string) for data_1.
vmin_1 – the low value of the range used for data_1 display(float).
vmax_1 – the high value of the range used for data_1 display(float).
cmap_2 – the color map name (string) or a list of RGB tuple (ex. [(255, 0, 0), (0, 0, 255)]).
vmin_2 – the low value of the range used for data_2 display(float).
vmax_2 – the high value of the range used for data_2 display(float).
out_dir – the output directory where the mosaic images will be saved.
only_noise – if True, shows the noise (boolean).
out_name – the suffix added to form the output name (string).
- Note: cmap for parametric display can be, gist_rainbow, RdYlBu, Spectral,
rainbow_r, jet_r, seismic_r, bwr_r
- mia_processes.utils.tools.set_dbFieldValue(project, document, tag_to_add)[source]¶
Creates for a document, the field and the corresponding value in the db.
- Parameters:
project – the project.
document – the absolute path of the document.
tag_to_add – a dictionary with ‘default_value’, ‘description’, ‘field_type’, ‘name’, ‘origin’, ‘unit’, ‘value’, ‘visibility’ keys.