Skip to content

Commit

Permalink
Merge pull request #160 from jhlegarreta/FixPlotStagittalWarning
Browse files Browse the repository at this point in the history
ENH: Fix mosaic plot `plot_sagittal` parameter warning
  • Loading branch information
effigies authored Jan 11, 2025
2 parents a6bcd48 + a7c643d commit eb3832c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
4 changes: 3 additions & 1 deletion nireports/reportlets/mosaic.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,9 @@ def plot_mosaic(

if plot_sagittal and views[1] is None and views[0] != "sagittal":
warnings.warn(
"Argument ``plot_sagittal`` for plot_mosaic() should not be used.", stacklevel=2
"Argument ``plot_sagittal`` for plot_mosaic() should not be used.",
category=UserWarning,
stacklevel=2,
)
views = (views[0], "sagittal", None)

Expand Down
29 changes: 15 additions & 14 deletions nireports/tests/test_reportlets.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
#
"""Test reportlets module."""

import contextlib
import os
from functools import partial
from itertools import permutations
from pathlib import Path

Expand Down Expand Up @@ -343,21 +343,22 @@ def test_mriqc_plot_mosaic(tmp_path, test_data_package, outdir, views, plot_sagi

fname = f"mosaic_{'_'.join(v or 'none' for v in views)}_{plot_sagittal:d}.svg"

testfunc = partial(
plot_mosaic,
get("MNI152NLin6Asym", resolution=2, desc="LR", suffix="T1w"),
plot_sagittal=plot_sagittal,
views=views,
out_file=(outdir / fname) if outdir is not None else None,
title=f"A mosaic plotting example: views={views}, plot_sagittal={plot_sagittal}",
maxrows=5,
)

if views[0] is None or ((views[1] is None) and (views[2] is not None)):
with pytest.raises(RuntimeError):
testfunc()
context = pytest.raises(RuntimeError)
elif plot_sagittal and views[1] is None and views[0] != "sagittal":
context = pytest.warns(UserWarning, match=r".*plot_sagittal.*should not be used")
else:
testfunc()
context = contextlib.nullcontext()

with context:
plot_mosaic(
get("MNI152NLin6Asym", resolution=2, desc="LR", suffix="T1w"),
plot_sagittal=plot_sagittal,
views=views,
out_file=(outdir / fname) if outdir is not None else None,
title=f"A mosaic plotting example: views={views}, plot_sagittal={plot_sagittal}",
maxrows=5,
)


def test_mriqc_plot_mosaic_2(tmp_path, test_data_package, outdir):
Expand Down

0 comments on commit eb3832c

Please sign in to comment.