From beb232b7f0ce4a8f0c32cf4e9db47331eaae1a27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20Haitz=20Legarreta=20Gorro=C3=B1o?= Date: Mon, 6 May 2024 19:05:48 -0400 Subject: [PATCH] ENH: Call the DWI plot method from nireports Call the DWI plot method from its new location in `nireports`. --- src/eddymotion/data/dmri.py | 2 +- src/eddymotion/viz.py | 35 ----------------------------------- 2 files changed, 1 insertion(+), 36 deletions(-) diff --git a/src/eddymotion/data/dmri.py b/src/eddymotion/data/dmri.py index 09fbe350..a28fdea0 100644 --- a/src/eddymotion/data/dmri.py +++ b/src/eddymotion/data/dmri.py @@ -160,7 +160,7 @@ def to_nifti(self, filename, **kwargs): def plot_mosaic(self, index=None, **kwargs): """Visualize one direction of the dMRI dataset.""" - from eddymotion.viz import plot_dwi + from nireports.reportlets.modality.dwi import plot_dwi return plot_dwi( self.bzero if index is None else self.dataobj[..., index], diff --git a/src/eddymotion/viz.py b/src/eddymotion/viz.py index 1354606c..23f1986f 100644 --- a/src/eddymotion/viz.py +++ b/src/eddymotion/viz.py @@ -22,45 +22,10 @@ # """Visualization utilities.""" -import nibabel as nb import numpy as np from nireports.reportlets.nuisance import plot_carpet as nw_plot_carpet -def plot_dwi(dataobj, affine, gradient=None, **kwargs): - """Plot a DW map.""" - import matplotlib.pyplot as plt - from nilearn.plotting import plot_anat - - plt.rcParams.update( - { - "text.usetex": True, - "font.family": "sans-serif", - "font.sans-serif": ["Helvetica"], - } - ) - - affine = np.diag(nb.affines.voxel_sizes(affine).tolist() + [1]) - affine[:3, 3] = -1.0 * (affine[:3, :3] @ ((np.array(dataobj.shape) - 1) * 0.5)) - - vmax = kwargs.pop("vmax", None) or np.percentile(dataobj, 98) - cut_coords = kwargs.pop("cut_coords", None) or (0, 0, 0) - - return plot_anat( - nb.Nifti1Image(dataobj, affine, None), - vmax=vmax, - cut_coords=cut_coords, - title=( - r"Reference $b$=0" - if gradient is None - else f"""\ -$b$={gradient[3].astype(int)}, \ -$\\vec{{b}}$ = ({', '.join(str(v) for v in gradient[:3])})""" - ), - **kwargs, - ) - - def rotation_matrix(u, v): r""" Calculate the rotation matrix *R* such that :math:`R \cdot \mathbf{u} = \mathbf{v}`.