scilpy.utils package
scilpy.utils.filenames module
- scilpy.utils.filenames.add_filename_suffix(filename, suffix)[source]
This function adds a suffix to the filename, keeping the extension. For example, if filename is test.nii.gz and suffix is “new”, the returned name will be test_new.nii.gz
- Parameters:
filename (str) – The full filename, including extension
suffix (str) – The suffix to add to the filename
- Return type:
The completed file name.
scilpy.utils.metrics_tools module
- scilpy.utils.metrics_tools.compute_lesion_stats(map_data, lesion_atlas, single_label=True, voxel_sizes=[1.0, 1.0, 1.0], min_lesion_vol=7, precomputed_lesion_labels=None)[source]
Returns information related to lesion inside of a binary mask or voxel labels map (bundle, for tractometry).
- Parameters:
map_data (np.ndarray) – Either a binary mask (uint8) or a voxel labels map (int16).
lesion_atlas (np.ndarray (3)) – Labelled atlas of lesion. Should be int16.
single_label (boolean) – If true, does not add an extra layer for number of labels.
voxel_sizes (np.ndarray (3)) – If not specified, returns voxel count (instead of volume)
min_lesion_vol (float) – Minimum lesion volume in mm3 (default: 7, cross-shape).
precomputed_lesion_labels (np.ndarray (N)) – For connectivity analysis, when the unique lesion labels are known, provided a pre-computed list of labels save computation.
- Returns:
lesion_load_dict – For each label, volume and lesion count
- Return type:
dict
- scilpy.utils.metrics_tools.get_bundle_metrics_mean_std(streamlines, metrics_files, distance_values, correlation_values, density_weighting=True)[source]
Returns the mean value of each metric for the whole bundle, only considering voxels that are crossed by streamlines. The mean values are weighted by the number of streamlines crossing a voxel by default. If false, every voxel traversed by a streamline has the same weight.
- Parameters:
streamlines (list of numpy.ndarray) – Input streamlines under which to compute stats.
metrics_files (sequence) – list of nibabel objects representing the metrics files
density_weighting (bool) – weigh by the mean by the density of streamlines going through the voxel
- Returns:
stats – list of tuples where the first element of the tuple is the mean of a metric, and the second element is the standard deviation, for each metric.
- Return type:
list
- scilpy.utils.metrics_tools.get_bundle_metrics_mean_std_per_point(streamlines, bundle_name, metrics, labels, distance_values=None, correlation_values=None, density_weighting=False)[source]
Compute the mean and std PER POiNT of the bundle for every given metric.
- Parameters:
streamlines (list of numpy.ndarray) – Input streamlines under which to compute stats.
bundle_name (str) – Name of the bundle. Will be used as a key in the dictionary.
metrics (sequence) – list of nibabel objects representing the metrics files
labels (np.ndarray) – List of labels obtained with scil_label_and_distance_maps.py
distance_values (np.ndarray) – List of distances obtained with scil_compute_bundle_voxel_label_map.py
correlation_values (np.ndarray) – List of correlations obtained with scil_compute_bundle_voxel_label_map.py
density_weighting (bool) – If true, weight statistics by the number of streamlines passing through each voxel. [False]
- Return type:
stats
- scilpy.utils.metrics_tools.get_bundle_metrics_profiles(sft, metrics_files)[source]
Returns the profile of each metric along each streamline from a sft. This is used to create tract profiles.
- Parameters:
sft (StatefulTractogram) – Input bundle under which to compute profile.
metrics_files (sequence) – list of nibabel objects representing the metrics files
- Returns:
profiles_values – list of profiles for each streamline, per metric given
- Return type:
list
- scilpy.utils.metrics_tools.plot_metrics_stats(means, stds, title=None, xlabel=None, ylabel=None, figlabel=None, fill_color=None, display_means=False)[source]
Plots the mean of a metric along n points with the standard deviation.
- Parameters:
means (Numpy 1D (or 2D) array of size n) – Mean of the metric along n points.
stds (Numpy 1D (or 2D) array of size n) – Standard deviation of the metric along n points.
title (string) – Title of the figure.
xlabel (string) – Label of the X axis.
ylabel (string) – Label of the Y axis (suggestion: the metric name).
figlabel (string) – Label of the figure (only metadata in the figure object returned).
fill_color (string) – Hexadecimal RGB color filling the region between mean ± std. The hexadecimal RGB color should be formatted as #RRGGBB
display_means (bool) – Display the subjects means as semi-transparent line
- Return type:
The figure object.
- scilpy.utils.metrics_tools.weighted_mean_std(weights, data)[source]
Returns the weighted mean and standard deviation of the data.
- Parameters:
weights (ndarray) – a ndarray containing the weighting factor
data (ndarray) – the ndarray containing the data for which the stats are desired
- Returns:
stats – a tuple containing the mean and standard deviation of the data
- Return type:
tuple