Skip to content

Commit

Permalink
Add DoF map to IBMA report (#854)
Browse files Browse the repository at this point in the history
* Add DoF Map to IBMA report

* Update figures.py

* Update test_reports.py

* Update test_reports.py
  • Loading branch information
JulioAPeraza committed Jan 9, 2024
1 parent efae75e commit 6315367
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 16 deletions.
20 changes: 14 additions & 6 deletions nimare/reports/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

from nimare.meta.cbma.base import CBMAEstimator, PairwiseCBMAEstimator
from nimare.reports.figures import (
_plot_dof_map,
_plot_relcov_map,
_plot_ridgeplot,
gen_table,
Expand Down Expand Up @@ -478,12 +479,19 @@ def __init__(
ids_ = self.results.estimator.inputs_["id"]
x_label = "Z" if key_maps == "z_maps" else "Beta"

_plot_relcov_map(
maps_arr,
self.results.estimator.masker,
self.results.estimator.inputs_["aggressive_mask"],
self.fig_dir / f"preliminary_dset-{dset_i+1}_figure-relcov.png",
)
if self.results.estimator.aggressive_mask:
_plot_relcov_map(
maps_arr,
self.results.estimator.masker,
self.results.estimator.inputs_["aggressive_mask"],
self.fig_dir / f"preliminary_dset-{dset_i+1}_figure-relcov.png",
)
else:
dof_map = self.results.get_map("dof")
_plot_dof_map(
dof_map,
self.fig_dir / f"preliminary_dset-{dset_i+1}_figure-dof.png",
)

_plot_ridgeplot(
maps_arr,
Expand Down
2 changes: 2 additions & 0 deletions nimare/reports/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ sections:
iframe: True
- bids: {value: preliminary, dset: 1, suffix: figure-relcov}
title: Relative Coverage Map
- bids: {value: preliminary, dset: 1, suffix: figure-dof}
title: DoF Map
- bids: {value: preliminary, dset: 1, suffix: figure-ridgeplot}
title: Ridge Plot
- bids: {value: preliminary, dset: 1, suffix: figure-similarity}
Expand Down
28 changes: 28 additions & 0 deletions nimare/reports/figures.py
Original file line number Diff line number Diff line change
Expand Up @@ -488,3 +488,31 @@ def _plot_relcov_map(maps_arr, masker, aggressive_mask, out_filename):
)
fig.savefig(out_filename, dpi=300)
fig.close()


def _plot_dof_map(dof_map, out_filename):
"""Plot DoF map.
.. versionadded:: 0.2.1
"""
_check_extention(out_filename, [".png", ".pdf", ".svg"])

epsilon = 1e-05

# Plot coverage map
template = datasets.load_mni152_template(resolution=1)
fig = plot_img(
dof_map,
bg_img=template,
black_bg=False,
draw_cross=False,
threshold=epsilon,
alpha=0.7,
colorbar=True,
cmap="YlOrRd",
vmin=0,
display_mode="mosaic",
)
fig.savefig(out_filename, dpi=300)
fig.close()
31 changes: 21 additions & 10 deletions nimare/tests/test_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from nimare.correct import FWECorrector
from nimare.diagnostics import FocusCounter, Jackknife
from nimare.meta.cbma import ALESubtraction
from nimare.meta.ibma import Stouffers
from nimare.reports.base import run_reports
from nimare.workflows import CBMAWorkflow, IBMAWorkflow, PairwiseCBMAWorkflow

Expand All @@ -27,13 +28,11 @@
FocusCounter(voxel_thresh=0.01, display_second_group=True),
"pairwise_cbma",
),
("stouffers", "fdr", "jackknife", "ibma"),
],
)
def test_reports_function_smoke(
tmp_path_factory,
testdata_cbma_full,
testdata_ibma,
estimator,
corrector,
diagnostics,
Expand Down Expand Up @@ -63,14 +62,26 @@ def test_reports_function_smoke(
)
results = workflow.fit(dset1, dset2)

elif meta_type == "ibma":
workflow = IBMAWorkflow(
estimator=estimator,
corrector=corrector,
diagnostics=diagnostics,
output_dir=tmpdir,
)
results = workflow.fit(testdata_ibma)
run_reports(results, tmpdir)

filename = "report.html"
outpath = op.join(tmpdir, filename)
assert op.isfile(outpath)


@pytest.mark.parametrize("aggressive_mask", [True, False], ids=["aggressive", "liberal"])
def test_reports_ibma_smoke(tmp_path_factory, testdata_ibma, aggressive_mask):
"""Smoke test for IBMA reports."""
tmpdir = tmp_path_factory.mktemp("test_reports_ibma_smoke")

workflow = IBMAWorkflow(
estimator=Stouffers(aggressive_mask=aggressive_mask),
corrector="fdr",
diagnostics="jackknife",
voxel_thresh=3.2,
output_dir=tmpdir,
)
results = workflow.fit(testdata_ibma)

run_reports(results, tmpdir)

Expand Down

0 comments on commit 6315367

Please sign in to comment.