Utility (utils) module

PyMIALSRTK utils functions.

pymialsrtk.interfaces.utils.get_emission_car_miles_equivalent(emissions)[source]

Return the equivalent of CO2 emissions [Kg] in terms of kms traveled by an average car.

References

https://github.com/mlco2/codecarbon/blob/c6aebb9681186a71573748e381b6a3c9731de2d3/codecarbon/viz/data.py#L53

pymialsrtk.interfaces.utils.get_emission_tv_time_equivalent(emissions)[source]

Return the equivalent of CO2 emissions [Kg] in terms of kms traveled by an average car.

References

https://github.com/mlco2/codecarbon/blob/c6aebb9681186a71573748e381b6a3c9731de2d3/codecarbon/viz/data.py#L66

pymialsrtk.interfaces.utils.reorder_by_run_ids(p_files, p_order)[source]

Function used to reorder images by their run-id IDS tag.

The images are sorted according to the input parameters. If more images are available, they remaining are sorted in scending order.

Parameters
  • p_files (list of string) – List of image paths - containing a ‘run-’ id tag, to be reordered

  • p_order (list of int) – List of expecting run id order.

Examples

>>> in_files = ['sub-01_run-2_T2w.nii.gz', 'sub-01_run-5_T2w.nii.gz', 'sub-01_run-3_T2w.nii.gz', 'sub-01_run-1_T2w.nii.gz']
>>> my_order = [1,5,3]
>>> reorder_by_run_ids(in_files, my_order)
pymialsrtk.interfaces.utils.run(command, env=None, cwd=None)[source]

Function calls by each MIALSRTK interface.

It runs the command specified as input via subprocess.run().

Parameters
  • command (string) – String containing the command to be executed (required)

  • env (os.environ) – Specify a custom os.environ

  • cwd (Directory) – Specify a custom current working directory

Examples

>>> cmd = 'btkNLMDenoising -i "/path/to/in_file" -o "/path/to/out_file" -b 0.1'
>>> run(cmd)
pymialsrtk.interfaces.utils.sort_ascending(p_files)[source]

Function used to sort images at the input of a nipype node.

Parameters

p_files (list) – List of image paths to be sorted in ascending order

Examples

>>> in_files = ['sub-01_run-2_T2w.nii.gz', 'sub-01_run-5_T2w.nii.gz', 'sub-01_run-3_T2w.nii.gz', 'sub-01_run-1_T2w.nii.gz']
>>> sort_ascending(in_files)