Skip to content

Commit

Permalink
Add support for IBMA estimators with t-statistic images in Reports (#896
Browse files Browse the repository at this point in the history
)

* Add support for IBMA estimators with t-statistic images in Reports

* create mapping for the variables

Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>

* fix indentation

* run black

---------

Co-authored-by: James Kent <[email protected]>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Aug 15, 2024
1 parent 8dd152f commit c1cd2d7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
14 changes: 10 additions & 4 deletions nimare/reports/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
"method": "Method",
"alpha": "Alpha",
"prior": "Prior",
"tau2": "Between-study variance",
"use_sample_size": "Use sample size for weights",
"normalize_contrast_weights": "Normalize by the number of contrasts",
"two_sided": "Two-sided test",
Expand Down Expand Up @@ -483,10 +484,15 @@ def __init__(
)
elif meta_type == "IBMA":
# Use "z_maps", for Fishers, and Stouffers; otherwise use "beta_maps".
key_maps = "z_maps" if "z_maps" in self.results.estimator.inputs_ else "beta_maps"
INPUT_TYPE_LABELS = {"z_maps": "Z", "t_maps": "T", "beta_maps": "Beta"}
for key_maps, x_label in INPUT_TYPE_LABELS.items():
if key_maps in self.results.estimator.inputs_:
break
else:
key_maps, x_label = "beta_maps", "Beta"

maps_arr = self.results.estimator.inputs_[key_maps]
ids_ = self.results.estimator.inputs_["id"]
x_label = "Z" if key_maps == "z_maps" else "Beta"

if self.results.estimator.aggressive_mask:
_plot_relcov_map(
Expand Down Expand Up @@ -526,12 +532,12 @@ def __init__(
if self.results.estimator.aggressive_mask:
voxel_mask = self.results.estimator.inputs_["aggressive_mask"]
corr = np.corrcoef(
self.results.estimator.inputs_["z_maps"][:, voxel_mask],
self.results.estimator.inputs_[key_maps][:, voxel_mask],
rowvar=True,
)
else:
corr = np.zeros((n_studies, n_studies), dtype=float)
for bag in self.results.estimator.inputs_["data_bags"]["z_maps"]:
for bag in self.results.estimator.inputs_["data_bags"][key_maps]:
study_bag = bag["study_mask"]
corr[np.ix_(study_bag, study_bag)] = np.corrcoef(
bag["values"],
Expand Down
27 changes: 23 additions & 4 deletions nimare/tests/test_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,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.meta.ibma import FixedEffectsHedges, Stouffers
from nimare.reports.base import run_reports
from nimare.workflows import CBMAWorkflow, IBMAWorkflow, PairwiseCBMAWorkflow

Expand Down Expand Up @@ -75,17 +75,36 @@ 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")

# Generate a report with z maps as inputs
stouffers_dir = op.join(tmpdir, "stouffers")
workflow = IBMAWorkflow(
estimator=Stouffers(aggressive_mask=aggressive_mask),
corrector="fdr",
diagnostics="jackknife",
voxel_thresh=3.2,
output_dir=tmpdir,
output_dir=stouffers_dir,
)
results = workflow.fit(testdata_ibma)

run_reports(results, tmpdir)
run_reports(results, stouffers_dir)

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

# Generate a report with t maps as inputs
hedges_dir = op.join(tmpdir, "hedges")
workflow = IBMAWorkflow(
estimator=FixedEffectsHedges(aggressive_mask=aggressive_mask),
corrector="fdr",
diagnostics="jackknife",
voxel_thresh=3.2,
output_dir=hedges_dir,
)
results = workflow.fit(testdata_ibma)

run_reports(results, hedges_dir)

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

0 comments on commit c1cd2d7

Please sign in to comment.