nireports.reportlets.modality.dwi module¶
Visualizations for diffusion MRI data.
- nireports.reportlets.modality.dwi.draw_circles(positions, radius, n_samples=20)[source]¶
Draw circular patches (lying on a sphere) at given positions.
Adapted from Emmanuel Caruyer’s code, which is distributed under the revised BSD License: Copyright (c) 2013-2015, Emmanuel Caruyer All rights reserved.
List of changes
Modified to take the full list of normalized bvecs and corresponding circle radii instead of taking the list of bvecs and radii for a specific shell (b-value).
- Parameters:
positions (
numpy.ndarray) – An array \(N \times 3\) of 3D cartesian positions.radius (
float) – The reference radius (or, the radius in single-shell plots)n_samples (
int) – The number of samples on the sphere.
- Returns:
circles – Circular patches.
- Return type:
- nireports.reportlets.modality.dwi.draw_points(gradients, ax, rad_min=0.3, rad_max=0.7, colormap='viridis')[source]¶
Draw the vectors on a shell.
Adapted from Emmanuel Caruyer’s code, which is distributed under the revised BSD License: Copyright (c) 2013-2015, Emmanuel Caruyer All rights reserved.
List of changes
The input is a single 2D numpy array of the gradient table in RAS+B format
The scaling of the circle radius for each bvec proportional to the inverse of the bvals. A minimum/maximal value for the radii can be specified.
Circles for each bvec are drawn at once instead of looping over the shells.
Some variables have been renamed (like vects to bvecs)
- Parameters:
gradients (
numpy.ndarray) – An (N, 4) shaped array of the gradient table in RAS+B format.ax (
matplotlib.axes.Axis) – The matplotlib axes instance to plot in.rad_min (
floatbetween 0 and 1) – Minimum radius of the circle that renders a gradient direction.rad_max (
floatbetween 0 and 1) – Maximum radius of the circle that renders a gradient direction.colormap (
str) – matplotlib colormap name.
- nireports.reportlets.modality.dwi.get_segment_labels(filepath, keywords, delimiter=' ', index_position=0, label_position=1)[source]¶
Get segment labels from file by keyword for get_segments function
- Parameters:
filepath (
string) – Path to segment label text file, such as freesurfer label filekeywords (list of
string) – List of label keywords. All labels containing the keyword will be grouped together. e.g. [“Cerebral_White_Matter”, “Cerebral_Cortex”, “Ventricle”]delimiter (
string, optional) – Delimiter between label index and label string in label file (’ ‘ for freesurfer label file)index_position (
int, optional) – Position of label index in label file (0 for freesurfer label file)label_position (
int, optional) – Position of label string in label file (1 for freesurfer label file)
- Returns:
dict
e.g. {‘Cerebral_White_Matter’ ([2, 41],) – ‘Cerebral_Cortex’: [3, 42], ‘Ventricle’: [4, 14, 15, 43, 72]}
- nireports.reportlets.modality.dwi.get_segments(segment_mask, segment_labels)[source]¶
Return segments dict for plot_carpet function
- Parameters:
segment_mask (
numpy.ndarray) – Segmentation mask of DW imaging datasegment_labels (
dict) – Dictionary of segment labels e.g. {‘Cerebral_White_Matter’: [2, 41],‘Cerebral_Cortex’: [3, 42], ‘Ventricle’: [4, 14, 15, 43, 72]}
- Returns:
segments – A mapping between segment labels (e.g., “Left Cortex”) and list of indexes in the data array.
- Return type:
- nireports.reportlets.modality.dwi.nii_to_carpetplot_data(nii, bvals=None, divide_by_b0=True, drop_b0=True, sort_by_bval=False, mask_nii=None, segment_labels=None)[source]¶
Convert nii to data matrix for carpet plot
- Parameters:
nii (Nifti1Image) – DW imaging data
bvals (
numpy.ndarray, optional) – Rounded bvalsdivide_by_b0 (
bool, optional) – Divide data by mean b0drop_b0 (
bool, optional) – Flag to drop b0 datasort_by_bval (
bool, optional) – Flag to reorder time points by bvaluemask_nii (Nifti1Image, optional) – Boolean or segmentation mask of DW imaging data
segment_labels (
dict, optional) – Dictionary of segment labels e.g. {‘Cerebral_White_Matter’: [2, 41],‘Cerebral_Cortex’: [3, 42], ‘Ventricle’: [4, 14, 15, 43, 72]}
- Returns:
data (N x T
numpy.array) – The functional data to be plotted (N sampling locations by T timepoints).segments (
dict) – A mapping between segment labels (e.g., “Left Cortex”) and list of indexes in the data array.
- nireports.reportlets.modality.dwi.plot_dwi(dataobj, affine, gradient=None, **kwargs)[source]¶
Plot orthogonal (axial, coronal, sagittal) slices of a given DWI volume. The slices displayed are determined by a tuple contained in the
cut_coordskeyword argument.- Parameters:
dataobj (
numpy.ndarray) – DWI volume data: a single 3D volume from a given gradient direction.affine (
numpy.ndarray) – Affine transformation matrix.gradient (
numpy.ndarray) – Gradient values in RAS+b format at the chosen gradient direction.kwargs (
dict) – Extra args given tonilearn.plotting.plot_anat().
- Returns:
An instance of the OrthoSlicer class. If
output_fileis defined, None is returned.- Return type:
nilearn.plotting.displays.OrthoSliceror None
- nireports.reportlets.modality.dwi.plot_gradients(gradients, title=None, ax=None, spacing=0.05, **kwargs)[source]¶
Draw the vectors on a unit sphere using a different color (as given by the
colormapproperty in the extra keywowrd arguments) for each b-value.See also
- Parameters:
gradients (
numpy.ndarray) – An (N, 4) shaped array of the gradient table in RAS+B format.title (
str) – Plot title.ax (
matplotlib.axes.Axis) – A figure’s axis to plot on.spacing (
float) – Plot spacing.kwargs (
dict) – Extra args given todraw_points().
- Returns:
ax – The figure’s axis where the data is plotted.
- Return type:
matplotlib.axes.Axis
- nireports.reportlets.modality.dwi.plot_heatmap(data, b_indices, bvals, mask, scalar, scalar_label='DWI-derived scalar (a.u.)', bins=(150, 11), imax=None, sub_size=100000, cmap='YlGn', sigma=None)[source]¶
Create heatmap plot.
- nireports.reportlets.modality.dwi.plot_tissue_values(data_file, group_name, feature, **kwargs)[source]¶
Generate a raincloud plot with the data points corresponding to the
featurevalue contained in the data file.- Parameters:
- Returns:
axes and gridspec – Plotting axes and gridspec. Returned only if
output_fileisNone.output_file (
str) – The file where the figure is saved.
- nireports.reportlets.modality.dwi.rotation_matrix(u, v)[source]¶
Calculate the rotation matrix R such that \(R \cdot \mathbf{u} = \mathbf{v}\).
Extracted from Emmanuel Caruyer’s code, which is distributed under the revised BSD License: Copyright (c) 2013-2015, Emmanuel Caruyer All rights reserved.
List of changes
Only minimal updates to leverage Numpy.
- Parameters:
u (
numpy.ndarray) – A vector.v (
numpy.ndarray) – A vector.
- Returns:
R – The rotation matrix.
- Return type: