Skip to content

Commit e0ae31c

Browse files
emdupreGaelVaroquaux
authored andcommitted
[ENH] Initial visual reports (nilearn#2019)
* Add externals directory for tempita * Add html report template * wip: initial commit of NiftiMasker report * Embed images in browser * Minor CSS updates * Add parameters table, non-responsive * Add tooltip for docstring * ENH: Avoid the use of iframes in the notebook (nicer layout) * MISC: cleaner inheritance * Remove ReportMixin class * Patch merge conflict * Create reporting module * Move computation to reporting method of masker * Call local style sheets * New nose-exclude dependency * Correct handling of 3D images * Revert nose-excludes, unpackage externals * Re-introduce ReportMixin * Re-package externals, add nose plugin to ignore * temporarily remove non-functioning nose plugin * Define __test__ attr to skip nosetest * Fix doc error, ignore linting in tempita * Remove externals from coverage * Unpackage pure style sheets * Remove externals from coverage reporting * Add pure attribution, license * Ask codecov directly (nicely) * Initial tests for reporting * Explicitly cast pathlib to str * Add overlay on hover * patch handling of single display images * Try to be careful about closing things... * fix: patch CI failure, add new text if hover * Address @jeromedockes review * Update images files to svg * omit externals from coverage * Move HTMLDocument to reporting * Add warning re missing MPL import, fix check_html calls * Move rm_file.py into reporting module * Fix check_html again * Move HTMLDocument to its own module * Adding additional tests * Retrigger Travis * Fix flake8 errors... the joys of switching text editors * Update examples to reference generate_report method * Change language from HTML to report, add comment on use * Update plot_nifti_simple example * Add code comment to plot_nifti_simple * Add in screenshots to showcase reporting * Adjust scaling * embed html reports * Address review comments * Fix iframe fenching * Update path to static HTML * Set height auto * Testing raw html directive * Break plot_mixed_gambles death spiral * Initial commit of MNE report scraper * Patch _ReportScraper * Use iframe rather than html page * define image_scrapers in sphinx conf * Update nilearn/reporting/sphinx_report.py Co-Authored-By: Eric Larson <[email protected]> * Use get_iframe method * Re-introduce whitespace in _SCRAPER_TEXT * Re-trigger CI * fix report in sphinx * Fix sphinx_report Indentation is also necessary * STY: fix CSS * Better example * FIX: avoid displaying reports twice * STY: more compact view Without this, the font is too big compared to the font of the examples * ENH: sphinx-gallery capture with repr_html Also works for interactive plots such as view_img * Update nilearn/reporting/sphinx_report.py Co-Authored-By: Elizabeth DuPre <[email protected]> * fix: correct dataset fetching * Add niftimasker report screenshots for rst * tst: initial tests for sphinx HTMLDocument embedding * fix: patch location of overlay * fix tst: do not rely on pytest fixture * tst: ensure tmpdir is closed after testing * fix: plot_nifti_simple fetcher * STY: fix whitespace in embedeed reports The CSS specified by the unclosing page (the nilearn website) was getting in the way. * STY: more styling to isolate from encompasing CSS * STY: enclose reports with a border * STY: tweak to limit scrollbars * CSS to get a better box This design makes the report really look like a box with a title. * STY: change colormap on masker report * STY: smaller reports in docs * STY: deal gracefully with details overflow * FIX: remove duplicate CSS rule * STY: fix scrolling in jupyter * Address @jeromedockes review * STY: make reports work in vscode Two problems arose: - Default theme is dark - The width was set wrong * Add example with resampling to plot_mask_computation * sty: update private attr in reporting * Differentiate warns for not fit, no reporting * fix: patch text in plot_mask_computation * sty: linting changes * fix: remove scaling to avoid jumping in page * sty: make contour thicker for contrast * Revert "fix: remove scaling to avoid jumping in page" This reverts commit 250e995. * fix: typo in sphinx_report * fix: remove overlay for saving svg images * Update nilearn/reporting/sphinx_report.py Co-Authored-By: Gael Varoquaux <[email protected]> * fix: update and extend test_html_report * fix: remove leftover nosetests attribute * Address @jeromedockes review * Re-introduce mask_img_ in examples * Generalize warnings in reporting * Add whats_new entry for generate_report * fix: patch whats_new entry * sty: Update display of plot_roi figs for NiftiMasker docs
1 parent 66d01ef commit e0ae31c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2699
-631
lines changed

.coveragerc

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[run]
22
branch = True
33
parallel = True
4-
4+
omit =
5+
*/nilearn/externals/*

Makefile

-1
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,3 @@ doc:
6363
.PHONY : pdf
6464
pdf:
6565
make -C doc pdf
66-

codecov.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ignore:
2+
- "*externals/.*" # ignore folders and all its contents

doc/conf.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,11 @@
281281

282282
_python_doc_base = 'http://docs.python.org/3.6'
283283

284+
# Scraper, copied from https://github.com/mne-tools/mne-python/
285+
from nilearn.reporting import _ReportScraper
286+
report_scraper = _ReportScraper()
287+
scrapers = ('matplotlib', report_scraper)
288+
284289
# Example configuration for intersphinx: refer to the Python standard library.
285290
intersphinx_mapping = {
286291
'python': (_python_doc_base, None),
@@ -302,6 +307,7 @@
302307
'backreferences_dir': os.path.join('modules', 'generated'),
303308
'reference_url': {'nilearn': None},
304309
'junit': '../test-results/sphinx-gallery/junit.xml',
310+
'image_scrapers': scrapers,
305311
}
306312

307313
# Get rid of spurious warnings due to some interaction between
@@ -310,7 +316,6 @@
310316
# details
311317
numpydoc_show_class_members = False
312318

313-
314319
def touch_example_backreferences(app, what, name, obj, options, lines):
315320
# generate empty examples files, so that we don't get
316321
# inclusion errors if there are no examples for a class / module
@@ -327,3 +332,4 @@ def touch_example_backreferences(app, what, name, obj, options, lines):
327332
def setup(app):
328333
app.add_javascript('copybutton.js')
329334
app.connect('autodoc-process-docstring', touch_example_backreferences)
335+
report_scraper.app = app

doc/images/niftimasker_report.png

94.9 KB
Loading
91.4 KB
Loading

doc/manipulating_images/masker_objects.rst

+23-9
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,25 @@ mask computation parameters.
136136
The mask can be retrieved and visualized from the `mask_img_` attribute
137137
of the masker:
138138

139+
.. literalinclude:: ../../examples/04_manipulating_images/plot_mask_computation.py
140+
:start-after: # A NiftiMasker with the default strategy
141+
:end-before: # Plot the generated mask using the .generate_report method
142+
143+
.. figure:: ../auto_examples/04_manipulating_images/images/sphx_glr_plot_mask_computation_002.png
144+
:target: ../auto_examples/04_manipulating_images/plot_mask_computation.html
145+
:align: center
146+
:scale: 40
147+
148+
Alternatively, the mask can be visualized using the `generate_report`
149+
method of the masker. The generated report can be viewed in a Jupyter notebook,
150+
opened in a new browser tab using `report.open_in_browser()`,
151+
or saved as a portable HTML file `report.save_as_html(output_filepath)`.
152+
139153
.. literalinclude:: ../../examples/04_manipulating_images/plot_mask_computation.py
140154
:start-after: # We need to specify an 'epi' mask_strategy, as this is raw EPI data
141155
:end-before: # Generate mask with strong opening
142156

143-
144-
.. figure:: ../auto_examples/04_manipulating_images/images/sphx_glr_plot_mask_computation_004.png
157+
.. figure:: /images/niftimasker_report.png
145158
:target: ../auto_examples/04_manipulating_images/plot_mask_computation.html
146159
:scale: 50%
147160

@@ -163,7 +176,7 @@ Controling these arguments set the fine aspects of the mask. See the
163176
functions documentation, or :doc:`the NiftiMasker example
164177
<../auto_examples/04_manipulating_images/plot_mask_computation>`.
165178

166-
.. figure:: ../auto_examples/04_manipulating_images/images/sphx_glr_plot_mask_computation_005.png
179+
.. figure:: /images/niftimasker_report_params.png
167180
:target: ../auto_examples/04_manipulating_images/plot_mask_computation.html
168181
:scale: 50%
169182

@@ -180,9 +193,10 @@ preparation::
180193
>>> masker # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
181194
NiftiMasker(detrend=False, dtype=None, high_pass=None, low_pass=None,
182195
mask_args=None, mask_img=None, mask_strategy='background',
183-
memory=Memory(...), memory_level=1, sample_mask=None,
184-
sessions=None, smoothing_fwhm=None, standardize=False, t_r=None,
185-
target_affine=None, target_shape=None, verbose=0)
196+
memory=Memory(...), memory_level=1, reports=True,
197+
sample_mask=None, sessions=None, smoothing_fwhm=None,
198+
standardize=False, t_r=None, target_affine=None, target_shape=None,
199+
verbose=0)
186200

187201
.. note::
188202

@@ -234,15 +248,15 @@ Temporal Filtering and confound removal
234248
properties, before conversion to voxel signals.
235249

236250
- **Standardization**. Parameter ``standardize``: Signals can be
237-
standardized (scaled to unit variance).
251+
standardized (scaled to unit variance).
238252

239253
- **Frequency filtering**. Low-pass and high-pass filters can be used to
240254
remove artifacts. Parameters: ``high_pass`` and ``low_pass``, specified
241255
in Hz (note that you must specific the sampling rate in seconds with
242256
the ``t_r`` parameter: ``loss_pass=.5, t_r=2.1``).
243257

244258
- **Confound removal**. Two ways of removing confounds are provided: simple
245-
detrending or using prespecified confounds, such as behavioral or movement
259+
detrending or using prespecified confounds, such as behavioral or movement
246260
information.
247261

248262
* Linear trends can be removed by activating the `detrend` parameter.
@@ -251,7 +265,7 @@ properties, before conversion to voxel signals.
251265
signal of interest (e.g., the neural correlates of cognitive tasks).
252266
It is not activated by default in :class:`NiftiMasker` but is recommended
253267
in almost all scenarios.
254-
268+
255269
* More complex confounds, measured during the acquision, can be removed
256270
by passing them to :meth:`NiftiMasker.transform`. If the dataset
257271
provides a confounds file, just pass its path to the masker.

doc/themes/nilearn/static/nature.css_t

+19
Original file line numberDiff line numberDiff line change
@@ -1689,3 +1689,22 @@ ul#tab li div.contents p{
16891689
p.sphx-glr-horizontal {
16901690
margin-top: 2em;
16911691
}
1692+
1693+
1694+
/* Sphinx-gallery Report embedding */
1695+
div.sg-report {
1696+
padding: 0pt;
1697+
transform: scale(.95);
1698+
}
1699+
1700+
div.sg-report iframe {
1701+
display: block;
1702+
border-style: none;
1703+
transform: scale(.85);
1704+
height: 470px;
1705+
margin-left: -12%; /* Negative because of .8 scaling */
1706+
margin-top: -4%;
1707+
padding: 0pt;
1708+
margin-bottom: 0pt;
1709+
width: 126%; /* More than 100% because of .8 scaling */
1710+
}

0 commit comments

Comments
 (0)