-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: rewrite test to use fixtures and new data
- Loading branch information
Showing
2 changed files
with
18 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*- | ||
# vi: set ft=python sts=4 ts=4 sw=4 et: | ||
# | ||
# Copyright 2023 The NiPreps Developers <[email protected]> | ||
# Copyright 2024 The NiPreps Developers <[email protected]> | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
|
@@ -20,26 +20,30 @@ | |
# | ||
# https://www.nipreps.org/community/licensing/ | ||
# | ||
from pathlib import Path | ||
"""Test DWI reportlets.""" | ||
|
||
import pytest | ||
|
||
import numpy as np | ||
from matplotlib import pyplot as plt | ||
from dipy.io import read_bvals_bvecs | ||
from dipy.core.gradients import gradient_table | ||
|
||
from nireports.reportlets.modality.dwi import plot_gradients | ||
|
||
|
||
def test_plot_gradients(tmp_path): | ||
@pytest.mark.parametrize( | ||
'dwi_btable', | ||
['ds000114_singleshell', 'hcph_multishell', 'ds004737_dsi'], | ||
) | ||
def test_plot_gradients(tmp_path, testdata_path, dwi_btable, outdir): | ||
"""Check the plot of DWI gradients.""" | ||
|
||
bvecs = np.loadtxt(testdata_path / f'{dwi_btable}.bvec').T | ||
bvals = np.loadtxt(testdata_path / f'{dwi_btable}.bval') | ||
|
||
fbval = "./mriqc/data/testdata/hcp_bvals" | ||
fbvec = "./mriqc/data/testdata/hcp_bvecs" | ||
_bvals, _bvecs = read_bvals_bvecs(fbval, fbvec) | ||
gtab = gradient_table(_bvals, _bvecs) | ||
bvecs = gtab.bvecs[~gtab.b0s_mask] | ||
bvals = gtab.bvals[~gtab.b0s_mask] | ||
b0s_mask = bvals < 50 | ||
|
||
gradients = np.vstack([bvecs.T, bvals]) | ||
gradients = np.vstack([bvecs[:, ~b0s_mask], bvals[~b0s_mask]]) | ||
_ = plot_gradients(gradients) | ||
|
||
plt.savefig(Path(tmp_path) / "gradients.png") | ||
if outdir is not None: | ||
plt.savefig(outdir / f'{dwi_btable}.svg', bbox_inches='tight') |