Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MRG] Glass brain visualisation #245

Merged
merged 60 commits into from
Dec 4, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
5856e7c
First commit of glass brain related scripts
lesteve Sep 8, 2014
e17cf36
Added a README.md + simple bash script to generate the json files
lesteve Sep 8, 2014
15c7236
Removed svg folder
lesteve Sep 8, 2014
6c66244
Tiny markdown improvement
lesteve Sep 9, 2014
ef0687c
First stab at implementing high-level function in img_plotting for gl…
lesteve Sep 26, 2014
2fbcdfe
Remove stale comment
lesteve Sep 26, 2014
724a4c4
Add demo for glass brain visualisation
lesteve Sep 26, 2014
16d0f80
Rename align_svg.py to get the Travis tests to run
lesteve Sep 26, 2014
90b7322
Additional hack to get the Travis tests to run
lesteve Sep 26, 2014
e578705
Move glass_brain_scripts inside plotting
lesteve Sep 26, 2014
185404b
glass_brain_scripts has been moved inside plotting. Also use generic …
lesteve Sep 26, 2014
f493f27
MAINT: remove unneeded svg_bak folder
lesteve Sep 26, 2014
e5df5b6
Brain schematics inverts its colors with a black background
lesteve Sep 29, 2014
0dbdfc8
Add svg bounds into the json document and update brain_plotter accord…
lesteve Sep 29, 2014
8b8b22d
Revert addition of object bounds margin and only use it when plotting…
lesteve Sep 29, 2014
ffaa660
Rename glass_brain_scripts to glass_brain and brain_plotter to brain_…
lesteve Oct 7, 2014
29af2c3
Move a few files to nilearn/plotting/glass_brain/scripts
lesteve Oct 7, 2014
b69ef47
First stab at tidying up slicers.py and img_plotting.py
lesteve Oct 7, 2014
24a5838
Add optional alpha argument to plot_glass_brain.
lesteve Oct 7, 2014
1c25b85
Reuse _plot_img_with_bg in plot_glass_brain
lesteve Oct 8, 2014
2d57957
Fix wrong class variable name
lesteve Oct 8, 2014
d409809
Move slice finding code to BaseStackedSlicer.find_cut_coords
lesteve Oct 8, 2014
24e7bea
Flatten the glass brain related folders
lesteve Oct 8, 2014
4b4c4c7
Refactor nilearn.plotting.glass_brain to use functions
lesteve Oct 9, 2014
00cd6ad
Move the brain schematic plotting to the Axes rather than the display
lesteve Oct 10, 2014
ad2dc03
Update plot_align_svg.py now that add_brain_schematics has been remov…
lesteve Oct 10, 2014
f5ec85b
Fix bug for display_mode != 'ortho'
lesteve Oct 10, 2014
aca9483
Minor renaming/tidy-up
lesteve Oct 10, 2014
4ed433f
Rename slicers.py -> displays.py
lesteve Oct 10, 2014
610ef8a
PEP8 fix since since I touched this line
lesteve Oct 10, 2014
4a90f46
Add tests for plot_glass_brain.
lesteve Oct 13, 2014
583784d
Remove colorbar from plot_glass_brain
lesteve Oct 16, 2014
1720900
Add plot_glass_brain to nilearn.plotting
lesteve Oct 17, 2014
a355f5a
Add glass brain plot to plot_demo_plotting.py
lesteve Oct 17, 2014
5ad6ff4
Add plot_glass_brain to documentation.
lesteve Oct 17, 2014
a5f4fb5
Fix typo tran*s*form_2d
lesteve Oct 20, 2014
92c5f8c
Use max rather than sum along an axis
lesteve Nov 5, 2014
5e3cd5a
vmin and vmax are determined by the 2d data min and max
lesteve Nov 13, 2014
5aa0a6a
Add transparent color maps using the full alpha range
lesteve Nov 13, 2014
31ce2c9
Removal of redundant if statement
lesteve Nov 18, 2014
6cada3a
The color should stay constant for transparent colormap
lesteve Nov 20, 2014
7d17f98
Use t-maps rather than contrasts in plot_glass_brain.py
lesteve Nov 25, 2014
d4d51e4
Use max(abs(data)) for 2d projection rather than max(data)
lesteve Nov 27, 2014
f5ef98c
Change default plot_glass_brain colormap
lesteve Nov 27, 2014
66dfaa4
Simplified glass brain SVGs
lesteve Nov 28, 2014
9f011d7
Remove invisible path
lesteve Nov 28, 2014
4e1a37b
Thiner lines in the glass brain SVGs
lesteve Nov 28, 2014
927fa06
Use auto threshold for glass brain
lesteve Nov 28, 2014
c2a6bf9
Tweak glass brain example in plot_demo_plotting.py
lesteve Nov 28, 2014
7bcf1a2
Add inferior temporal sulcus
lesteve Dec 2, 2014
8a42985
Rename some lingering slicer to display
lesteve Dec 3, 2014
9c8f0b6
Fix max instead of min typo in auto vmin logic
lesteve Dec 3, 2014
f37072b
Cosmits
lesteve Dec 3, 2014
3e25fe6
Add module docstrings
lesteve Dec 3, 2014
d971917
Document more parameters in _plot_img_with_bg
lesteve Dec 3, 2014
71c8111
Added OrthoProjector smoke test
lesteve Dec 3, 2014
4db0995
Add anatomy in plot_align_svg.py
lesteve Dec 3, 2014
bc75c30
Explicitly say that input data needs to be in MNI space
lesteve Dec 4, 2014
a58cc15
Use alpha=0.7 by default for the brain schematics
lesteve Dec 4, 2014
88f7036
Remove plot_glass_brain.py
lesteve Dec 4, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
82 changes: 46 additions & 36 deletions doc/building_blocks/plotting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,34 +32,44 @@ different heuristics to find cutting coordinates.
:target: ../auto_examples/plot_demo_plotting.html
:scale: 50

.. |plot_glass_brain| image:: ../auto_examples/images/plot_demo_plotting_5.png
:target: ../auto_examples/plot_demo_plotting.html
:scale: 50

.. A temporary hack to avoid a sphinx bug
.. |hack| raw:: html

<br>

================= =========================================================
================= =========================================================
|plot_anat| :func:`plot_anat`
|hack|
Plotting an anatomical image

|plot_epi| :func:`plot_epi`
|hack|
Plotting an EPI, or T2* image
=================== =========================================================
=================== =========================================================
|plot_anat| :func:`plot_anat`
|hack|
Plotting an anatomical image

|plot_stat_map| :func:`plot_stat_map`
|hack|
Plotting a statistical map, like a T-map, a Z-map, or
an ICA, with an optional background
|plot_epi| :func:`plot_epi`
|hack|
Plotting an EPI, or T2* image

|plot_roi| :func:`plot_roi`
|hack|
Plotting ROIs, or a mask, with an optional background
|plot_stat_map| :func:`plot_stat_map`
|hack|
Plotting a statistical map, like a T-map, a Z-map, or
an ICA, with an optional background

|plot_roi| :func:`plot_roi`
|hack|
Plotting ROIs, or a mask, with an optional background

|plot_glass_brain| :func:`plot_glass_brain`
|hack|
Glass brain visualisation

**plot_img** :func:`plot_img`
|hack|
General-purpose function, with no specific presets
=================== =========================================================

**plot_img** :func:`plot_img`
|hack|
General-purpose function, with no specific presets
================= =========================================================

.. warning:: **Opening too many figures without closing**

Expand All @@ -77,35 +87,35 @@ different heuristics to find cutting coordinates.
Different display modes
========================

.. |plot_ortho| image:: ../auto_examples/images/plot_demo_plotting_5.png
.. |plot_ortho| image:: ../auto_examples/images/plot_demo_plotting_6.png
:target: ../auto_examples/plot_demo_plotting.html
:scale: 50

.. |plot_z_many| image:: ../auto_examples/images/plot_demo_plotting_6.png
.. |plot_z_many| image:: ../auto_examples/images/plot_demo_plotting_7.png
:target: ../auto_examples/plot_demo_plotting.html
:scale: 50

.. |plot_x| image:: ../auto_examples/images/plot_demo_plotting_7.png
.. |plot_x| image:: ../auto_examples/images/plot_demo_plotting_8.png
:target: ../auto_examples/plot_demo_plotting.html
:scale: 50

.. |plot_x_small| image:: ../auto_examples/images/plot_demo_plotting_8.png
.. |plot_x_small| image:: ../auto_examples/images/plot_demo_plotting_9.png
:target: ../auto_examples/plot_demo_plotting.html
:scale: 50

.. |plot_z_small| image:: ../auto_examples/images/plot_demo_plotting_9.png
.. |plot_z_small| image:: ../auto_examples/images/plot_demo_plotting_10.png
:target: ../auto_examples/plot_demo_plotting.html
:scale: 50

.. |plot_xz| image:: ../auto_examples/images/plot_demo_plotting_10.png
.. |plot_xz| image:: ../auto_examples/images/plot_demo_plotting_11.png
:target: ../auto_examples/plot_demo_plotting.html
:scale: 50

.. |plot_yx| image:: ../auto_examples/images/plot_demo_plotting_11.png
.. |plot_yx| image:: ../auto_examples/images/plot_demo_plotting_12.png
:target: ../auto_examples/plot_demo_plotting.html
:scale: 50

.. |plot_yz| image:: ../auto_examples/images/plot_demo_plotting_12.png
.. |plot_yz| image:: ../auto_examples/images/plot_demo_plotting_13.png
:target: ../auto_examples/plot_demo_plotting.html
:scale: 50

Expand Down Expand Up @@ -158,38 +168,38 @@ Adding overlays, edges and contours
====================================

To add overlays, contours, or edges, use the return value of the plotting
functions. Indeed, these return a slicer object, such as the
:class:`nilearn.plotting.slicers.OrthoSlicer`. This object represents the
functions. Indeed, these return a display object, such as the
:class:`nilearn.plotting.displays.OrthoSlicer`. This object represents the
plot, and has methods to add overlays, contours or edge maps::

slicer = plotting.plot_epi(...)
display = plotting.plot_epi(...)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for renaming slicer to display in the docs!


.. |plot_edges| image:: ../auto_examples/images/plot_demo_plotting_13.png
.. |plot_edges| image:: ../auto_examples/images/plot_demo_plotting_14.png
:target: ../auto_examples/plot_demo_plotting.html
:scale: 50

.. |plot_contours| image:: ../auto_examples/images/plot_demo_plotting_14.png
.. |plot_contours| image:: ../auto_examples/images/plot_demo_plotting_15.png
:target: ../auto_examples/plot_demo_plotting.html
:scale: 50

================= =========================================================
================= =========================================================
|plot_edges| `slicer.add_edges(img)`
|plot_edges| `display.add_edges(img)`
|hack|
Add a plot of the edges of `img`, where edges are
extracted using a Canny edge-detection routine. This
is typically useful to check registration. Note that
`img` should have some visible sharp edges. Typically
an EPI img does not, but a T1 does.

|plot_contours| `slicer.add_contours(img, levels=[.5], colors='r')`
|plot_contours| `display.add_contours(img, levels=[.5], colors='r')`
|hack|
Add a plot of the contours of `img`, where contours
are computed for constant values, specified in
'levels'. This is typically useful to outline a mask,
or ROI on top of another map.

**add_overlay** `slicer.add_overlay(img, cmap=plotting.cm.purple_green, threshold=3)`
**add_overlay** `display.add_overlay(img, cmap=plotting.cm.purple_green, threshold=3)`
|hack|
Add a new overlay on the existing figure

Expand All @@ -209,7 +219,7 @@ function returns None.

|

The slicer object returned by the plotting function has a savefig method
The display object returned by the plotting function has a savefig method
that can be used to save the plot to an image file::

>>> from nilearn import plotting
Expand Down
2 changes: 1 addition & 1 deletion doc/modules/reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ uses.

**Classes**:

.. currentmodule:: nilearn.plotting.slicers
.. currentmodule:: nilearn.plotting.displays

.. autosummary::
:toctree: generated/
Expand Down
5 changes: 3 additions & 2 deletions nilearn/plotting/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ def _set_mpl_backend():

from . import cm
from .img_plotting import plot_img, plot_anat, plot_epi, \
plot_roi, plot_stat_map
plot_roi, plot_stat_map, plot_glass_brain
from .find_cuts import find_xyz_cut_coords

__all__ = ['cm', 'plot_img', 'plot_anat', 'plot_epi',
'plot_roi', 'plot_stat_map', 'find_xyz_cut_coords']
'plot_roi', 'plot_stat_map', 'plot_glass_brain',
'find_xyz_cut_coords']
9 changes: 6 additions & 3 deletions nilearn/plotting/cm.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def _concat_cmap(cmap1, cmap2):
return cdict


def alpha_cmap(color, name=''):
def alpha_cmap(color, name='', alpha_min=0.5, alpha_max=1.):
""" Return a colormap with the given color, and alpha going from
zero to 1.

Expand All @@ -104,13 +104,13 @@ def alpha_cmap(color, name=''):
red, green, blue = _colors.colorConverter.to_rgb(color)
if name == '' and hasattr(color, 'startswith'):
name = color
cmapspec = [(red, green, blue, 0.),
cmapspec = [(red, green, blue, 1.),
(red, green, blue, 1.),
]
cmap = _colors.LinearSegmentedColormap.from_list(
'%s_transparent' % name, cmapspec, _cm.LUTSIZE)
cmap._init()
cmap._lut[:, -1] = _np.linspace(.5, 1.0, cmap._lut.shape[0])
cmap._lut[:, -1] = _np.linspace(alpha_min, alpha_max, cmap._lut.shape[0])
cmap._lut[-1, -1] = 0
return cmap

Expand Down Expand Up @@ -170,6 +170,9 @@ def alpha_cmap(color, name=''):
((0, 0, 1), 'green'),
):
_cmap_d['%s_transparent' % name] = alpha_cmap(color, name=name)
_cmap_d['%s_transparent_full_alpha_range' % name] = alpha_cmap(
color, alpha_min=0,
alpha_max=1, name=name)


locals().update(_cmap_d)
Expand Down