cmtklib.util module
Module that defines CMTK Utility functions.
- class cmtklib.util.BColors[source]
Bases:
object
Utility class for color unicode.
- BOLD = '\x1b[1m'
- ENDC = '\x1b[0m'
- FAIL = '\x1b[91m'
- HEADER = '\x1b[95m'
- OKBLUE = '\x1b[94m'
- OKGREEN = '\x1b[92m'
- UNDERLINE = '\x1b[4m'
- WARNING = '\x1b[93m'
- cmtklib.util.check_directory_exists(mandatory_dir)[source]
Makes sure the mandatory directory exists.
- Raises
FileNotFoundError – Raised when the directory is not found.
- cmtklib.util.convert_list_to_tuple(lists)[source]
Convert list of files to tuple of files.
(Duplicated with preprocessing, could be moved to utils in the future)
- Parameters
lists ([bvecs, bvals]) – List of files containing bvecs and bvals
- Returns
out_tuple – Tuple of files containing bvecs and bvals
- Return type
(bvecs, bvals)
- cmtklib.util.extract_freesurfer_subject_dir(reconall_report, local_output_dir=None, debug=False)[source]
Extract Freesurfer subject directory from the report created by Nipype Freesurfer Recon-all node.
- cmtklib.util.extract_reconall_base_dir(file)[source]
Extract Recon-all base directory from a file.
- Parameters
file (File) – File generated by Recon-all
- Returns
out_path – Recon-all base directory
- Return type
string
- cmtklib.util.get_basename(path)[source]
Return
os.path.basename()
of apath
.- Parameters
path (os.path) – Path to extract the containing directory
- Returns
path – Path to the containing directory
- Return type
os.path
- cmtklib.util.get_freesurfer_subject_id(file)[source]
Extract Freesurfer subject ID from file generated by recon-all.
- cmtklib.util.get_node_dictionary_outputs(node_report, local_output_dir=None, debug=False)[source]
Read the Nipype node report and return a dictionary of node outputs.
- cmtklib.util.get_pipeline_dictionary_outputs(datasink_report, local_output_dir=None, debug=False)[source]
Read the Nipype datasink report and return a dictionary of pipeline outputs.
- cmtklib.util.isavailable(file)[source]
Check if file is available and return the file if it is.
Used for debugging.
- Parameters
file (File) – Input file
- Returns
file – Output file
- Return type
File
- cmtklib.util.length(xyz, along=False)[source]
Euclidean length of track line.
- Parameters
xyz (array-like shape (N,3)) – array representing x,y,z of N points in a track
along (bool, optional) – If True, return array giving cumulative length along track, otherwise (default) return scalar giving total length.
- Returns
L – scalar in case of
along
== False, giving total length, array ifalong
== True, giving cumulative lengths.- Return type
scalar or array shape (N-1,)
Examples
>>> xyz = np.array([[1,1,1],[2,3,4],[0,0,0]]) >>> expected_lens = np.sqrt([1+2**2+3**2, 2**2+3**2+4**2]) >>> length(xyz) == expected_lens.sum() True >>> len_along = length(xyz, along=True) >>> np.allclose(len_along, expected_lens.cumsum()) True >>> length([]) 0 >>> length([[1, 2, 3]]) 0 >>> length([], along=True) array([0])
- cmtklib.util.magn(xyz, n=1)[source]
Returns the vector magnitude
- Parameters
xyz (vector) – Input vector
n (int) – Tile by
n
ifn>1
before return
- cmtklib.util.mean_curvature(xyz)[source]
Calculates the mean curvature of a curve.
- Parameters
xyz (array-like shape (N,3)) – array representing x,y,z of N points in a curve
- Returns
m – float representing the mean curvature
- Return type
Examples
Create a straight line and a semi-circle and print their mean curvatures
>>> from dipy.tracking import metrics as tm >>> import numpy as np >>> x=np.linspace(0,1,100) >>> y=0*x >>> z=0*x >>> xyz=np.vstack((x,y,z)).T >>> m=tm.mean_curvature(xyz) # mean curvature straight line >>> theta=np.pi*np.linspace(0,1,100) >>> x=np.cos(theta) >>> y=np.sin(theta) >>> z=0*x >>> xyz=np.vstack((x,y,z)).T >>> m=tm.mean_curvature(xyz) # mean curvature for semi-circle
- cmtklib.util.print_blue(message)[source]
Print blue-colored message
- Parameters
message (string) – The string of the message to be printed
- cmtklib.util.print_error(message)[source]
Print red-colored error message
- Parameters
message (string) – The string of the message to be printed
- cmtklib.util.print_warning(message)[source]
Print yellow-colored warning message
- Parameters
message (string) – The string of the message to be printed
- cmtklib.util.return_button_style_sheet(image, image_disabled=None, verbose=False)[source]
Return Qt style sheet for QPushButton with image
- Parameters
image (string) – Path to image to use as icon when button is enabled
image_disabled (string) – Path to image to use as icon when button is disabled
verbose (Bool) – Print the style sheet if True Default: False
- Returns
button_style_sheet – Qt style sheet for QPushButton with image
- Return type
string