Skip to content

Commit 01e28ed

Browse files
authored
Add reports module (#802)
* Add reports module * Add template * Add config file * Add generate_figues script * Add test * Update test_reports.py * Update setup.cfg * Fix lint error * Add yaml to setup file * Update setup.cfg * Update default.yml * Update setup.cfg * Add report to example gallery * check online path * Plot coordinates * Update 10_plot_cbma_workflow.py * Update 10_plot_cbma_workflow.py * Update figures.py * Update 10_plot_cbma_workflow.py * [skip ci] update figures * [skip ci] add static plot * [skip ci] update path to report * [skip ci] update path * [skip ci] explore rtd directory tree * [skip ci] high res images * [skip ci] update path to report * [skip ci] close fig after saving * [skip ci] update path * [skip ci] try another path the report.html * [skip ci] change the path again............. * [skip ci] update path * [skip ci] update path * [skip ci] add cluster table * [skip ci] add title, caption, and description * [skip ci] update example * [skip ci] increase size of heatmap * [skip ci] add ids of studies excluded to summary * [skip ci] update table style * [skip ci] add dynamic coordinates plot * [skip ci] add legend * [skip ci] embed heatmaps wit iframe * [skip ci] change names to fit new bids-like format * [skip ci] pin pandas version * [skip ci] add summary diagnostics * [skip ci] work on copy of diagnostics * [skip ci] get threshold from diagnostics * [skip ci] add all possible combinations of results * [skip ci] add message when tables and map are empty * [skip ci] add alpha to dictionary * [skip ci] add label maps * [skip ci] add tail label * [skip ci] add mask * add documentation * fix typo * add tables naming convention to output * only plot coordinates for CBMAEstimator * fix typo * improve coverage * reduce report and yml file
1 parent fccf509 commit 01e28ed

File tree

14 files changed

+1212
-44
lines changed

14 files changed

+1212
-44
lines changed

docs/api.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,20 @@ For more information about fetching data from the internet, see :ref:`fetching t
336336
workflows.macm_workflow
337337
workflows.cbma_workflow
338338

339+
:mod:`nimare.reports`: NiMARE report
340+
--------------------------------------------------
341+
342+
.. automodule:: nimare.reports
343+
:no-members:
344+
:no-inherited-members:
345+
346+
.. currentmodule:: nimare
347+
348+
.. autosummary::
349+
:toctree: generated/
350+
:template: function.rst
351+
352+
reports.run_reports
339353

340354
.. _api_base_ref:
341355

docs/outputs.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ File names
1111

1212
NiMARE-generated files, especially ones made by meta-analyses, follow a naming convention somewhat based on BIDS.
1313

14-
Here is the basic naming convention for statistical maps:
14+
Here is the basic naming convention for statistical maps and tables:
1515

1616
.. code-block:: Text
1717
18-
<value>[_desc-<label>][_level-<cluster|voxel>][_corr-<FWE|FDR>][_method-<label>][_diag-<Jackknife|FocusCounter>].nii.gz
18+
<value>[_desc-<label>][_level-<cluster|voxel>][_corr-<FWE|FDR>][_method-<label>][_diag-<Jackknife|FocusCounter>][_tail-<positive|negative>].nii.gz
19+
20+
<value>[_desc-<label>][_level-<cluster|voxel>][_corr-<FWE|FDR>][_method-<label>]_tab-<clust|counts>.tsv
1921
2022
2123
First, the ``value`` represents type of data in the map (e.g., z-statistic, t-statistic).

examples/02_meta-analyses/10_plot_cbma_workflow.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@
1212
the fundamental steps of a CBMA meta-analysis.
1313
"""
1414
import os
15-
from pprint import pprint
15+
from pathlib import Path
1616

1717
import matplotlib.pyplot as plt
1818
from nilearn.plotting import plot_stat_map
1919

2020
from nimare.dataset import Dataset
21+
from nimare.reports.base import run_reports
2122
from nimare.utils import get_resource_path
2223
from nimare.workflows import cbma_workflow
2324

@@ -75,15 +76,19 @@
7576
result.tables["z_corr-FDR_method-indep_diag-Jackknife_tab-counts"]
7677

7778
###############################################################################
78-
# Methods
79+
# Report
7980
# -----------------------------------------------------------------------------
80-
# The MetaResult object also provides boilerplate text automatically generated by NiMARE,
81-
# which is released under the `CC0 <https://creativecommons.org/publicdomain/zero/1.0/>`_ license.
82-
print("Description:")
83-
pprint(result.description_)
81+
# Finally, a NiMARE report is generated from the MetaResult.
82+
root_dir = Path(os.getcwd()).parents[1]
83+
# Use the following path to run the documentation locally:
84+
# html_dir = root_dir / "docs" / "_build" / "html" / "auto_examples" / "02_meta-analyses"
85+
html_dir = root_dir / "_readthedocs" / "html" / "auto_examples" / "02_meta-analyses"
86+
html_dir.mkdir(parents=True, exist_ok=True)
8487

85-
###############################################################################
86-
# References
87-
# ``````````````````````````````````````````````````````````````````````````````
88-
print("References:")
89-
pprint(result.bibtex_)
88+
run_reports(result, html_dir)
89+
90+
####################################
91+
# .. raw:: html
92+
#
93+
# <iframe src="./report.html" style="border:none;" seamless="seamless" width="100%"\
94+
# height="1000px"></iframe>

nimare/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
decode,
1717
io,
1818
meta,
19+
reports,
1920
resources,
2021
stats,
2122
utils,
@@ -35,6 +36,7 @@
3536
"io",
3637
"stats",
3738
"utils",
39+
"reports",
3840
"workflows",
3941
"__version__",
4042
]

nimare/diagnostics.py

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -75,30 +75,39 @@ def transform(self, result):
7575
7676
Returns
7777
-------
78-
contribution_table : :obj:`pandas.DataFrame` or None
79-
A DataFrame with information about relative contributions of each experiment to each
80-
cluster in the thresholded map.
81-
There is one row for each experiment.
82-
There is one column for each cluster, with column names being
83-
``PostiveTail``/``NegativeTail`` indicating the sign (+/-) of the cluster's
84-
statistical values, plus an integer indicating the cluster's associated value
85-
in the ``label_maps[0]``/``label_maps[1]`` output.
86-
If no clusters are found or a pairwise Estimator was used, ``None`` is returned.
87-
clusters_table : :obj:`pandas.DataFrame`
88-
A DataFrame with information about each cluster.
89-
There is one row for each cluster.
90-
The columns in this table include: ``Cluster ID`` (the cluster id, plus a letter
91-
for subpeaks only), ``X``/``Y``/``Z`` (coordinate for the center of mass),
92-
``Max Stat`` (statistical value of the peak), and ``Cluster Size (mm3)``
93-
(the size of the cluster, in cubic millimeters).
94-
If no clusters are found, this table will be empty.
95-
label_maps : :obj:`list`
96-
List of :obj:`nibabel.nifti1.Nifti1Image` objects of cluster label maps.
97-
Each cluster in the map has a single value, which corresponds to the cluster number
98-
of the column name in ``contribution_table``.
99-
If target_image has negative values after thresholding, first and second maps
100-
correspond to positive and negative tails.
101-
If no clusters are found, this list will be empty.
78+
:obj:`~nimare.results.MetaResult`
79+
Results of Diagnostics fitting.
80+
81+
Notes
82+
-----
83+
This method adds two new keys to ``maps`` and ``tables`` attributes of the
84+
MetaResult object.
85+
86+
- ``<target_image>_diag-<Jackknife|FocusCounter>_tab-counts`` :
87+
:obj:`pandas.DataFrame` or None.
88+
A DataFrame with information about relative contributions of each experiment
89+
to each cluster in the thresholded map.
90+
There is one row for each experiment.
91+
There is one column for each cluster, with column names being
92+
``PostiveTail``/``NegativeTail`` indicating the sign (+/-) of the cluster's
93+
statistical values, plus an integer indicating the cluster's associated value
94+
in the ``label_maps[0]``/``label_maps[1]`` output.
95+
If no clusters are found or a pairwise Estimator was used, ``None`` is returned.
96+
- ``<target_image>_tab-clust`` : :obj:`pandas.DataFrame`
97+
A DataFrame with information about each cluster.
98+
There is one row for each cluster.
99+
The columns in this table include: ``Cluster ID`` (the cluster id, plus a letter
100+
for subpeaks only), ``X``/``Y``/``Z`` (coordinate for the center of mass),
101+
``Max Stat`` (statistical value of the peak), and ``Cluster Size (mm3)``
102+
(the size of the cluster, in cubic millimeters).
103+
If no clusters are found, this table will be empty.
104+
- ``label_<target_image>_tail-<positive|negative>`` : :obj:`numpy.ndarray`
105+
Label maps.
106+
Each cluster in the map has a single value, which corresponds to the cluster number
107+
of the column name in ``contribution_table``.
108+
If target_image has negative values after thresholding, first and second maps
109+
correspond to positive and negative tails.
110+
If no clusters are found, this list will be empty.
102111
"""
103112
masker = result.estimator.masker
104113
diag_name = self.__class__.__name__

nimare/reports/__init__.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""Reports module."""
2+
3+
from .base import Report, run_reports
4+
from .figures import (
5+
gen_table,
6+
plot_clusters,
7+
plot_coordinates,
8+
plot_heatmap,
9+
plot_interactive_brain,
10+
plot_mask,
11+
plot_static_brain,
12+
)
13+
14+
__all__ = [
15+
"Report",
16+
"run_reports",
17+
"gen_table",
18+
"plot_clusters",
19+
"plot_coordinates",
20+
"plot_heatmap",
21+
"plot_interactive_brain",
22+
"plot_mask",
23+
"plot_static_brain",
24+
]

0 commit comments

Comments
 (0)