Skip to content
This repository has been archived by the owner on Dec 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #189 from jhlegarreta/CallNireportsDWIPlot
Browse files Browse the repository at this point in the history
ENH: Call the DWI plot method from nireports
  • Loading branch information
effigies authored May 16, 2024
2 parents a931c20 + beb232b commit be66f4d
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 36 deletions.
2 changes: 1 addition & 1 deletion src/eddymotion/data/dmri.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
35 changes: 0 additions & 35 deletions src/eddymotion/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}`.
Expand Down

0 comments on commit be66f4d

Please sign in to comment.