├── .flake8 ├── .gitignore ├── .readthedocs.yml ├── .travis.yml ├── Interactive Surface Visualization Demo.ipynb ├── LICENSE.md ├── Makefile ├── README.md ├── demo_update.ipynb ├── docs ├── Makefile ├── _static │ └── niwidgets-500x500.png ├── api.rst ├── api │ ├── niwidgets.NiftiWidget.rst │ ├── niwidgets.StreamlineWidget.rst │ └── niwidgets.SurfaceWidget.rst ├── conf.py ├── img │ └── example.gif ├── index.md ├── installation.rst ├── logo.png ├── old-logo.png └── requirements.txt ├── index.ipynb ├── pyproject.toml ├── report.ipynb ├── src └── niwidgets │ ├── __init__.py │ ├── colormaps.py │ ├── controls.py │ ├── data │ ├── T1.nii.gz │ ├── cc400_roi_atlas.nii │ ├── cognitive control_pFgA_z.nii.gz │ ├── cognitive control_pFgA_z_FDR_0.01.nii.gz │ ├── example_surfaces │ │ ├── aparc.annot.ctab │ │ ├── lh.aparc.annot │ │ ├── lh.area │ │ ├── lh.curv │ │ ├── lh.inflated │ │ └── lh.thickness │ └── streamlines.trk │ ├── exampledata.py │ ├── niwidget_surface.py │ ├── niwidget_volume.py │ ├── streamlines.py │ └── version.py └── tests ├── conftest.py ├── test_surface.py └── test_volume.py /.flake8: -------------------------------------------------------------------------------- 1 | [flake8] 2 | ignore = E203, W503 3 | max-line-length = 80 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # notebooks 10 | .ipnyb_checkpoints 11 | 12 | # mac files 13 | *.DS_Store 14 | 15 | # pytest 16 | .pytest_cache 17 | 18 | # Distribution / packaging 19 | .Python 20 | env/ 21 | build/ 22 | develop-eggs/ 23 | dist/ 24 | downloads/ 25 | eggs/ 26 | .eggs/ 27 | lib/ 28 | lib64/ 29 | parts/ 30 | sdist/ 31 | var/ 32 | *.egg-info/ 33 | .installed.cfg 34 | *.egg 35 | .pytest_cache 36 | 37 | # PyInstaller 38 | # Usually these files are written by a python script from a template 39 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 40 | *.manifest 41 | *.spec 42 | 43 | # Installer logs 44 | pip-log.txt 45 | pip-delete-this-directory.txt 46 | 47 | # Unit test / coverage reports 48 | htmlcov/ 49 | .tox/ 50 | .coverage 51 | .coverage.* 52 | .cache 53 | nosetests.xml 54 | coverage.xml 55 | *,cover 56 | 57 | # Translations 58 | *.mo 59 | *.pot 60 | 61 | # Django stuff: 62 | *.log 63 | 64 | # Sphinx documentation 65 | docs/_build/ 66 | 67 | # PyBuilder 68 | target/ 69 | 70 | \.ipynb_checkpoints/ 71 | docs/_build 72 | -------------------------------------------------------------------------------- /.readthedocs.yml: -------------------------------------------------------------------------------- 1 | # .readthedocs.yml 2 | # Read the Docs configuration file 3 | # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details 4 | 5 | # Required 6 | version: 2 7 | 8 | # Build documentation in the docs/ directory with Sphinx 9 | sphinx: 10 | builder: html 11 | configuration: docs/conf.py 12 | 13 | build: 14 | image: latest 15 | 16 | # Optionally build your docs in additional formats such as PDF and ePub 17 | formats: [] 18 | 19 | # Optionally set the version of Python and requirements required to build your docs 20 | python: 21 | version: 3.7 22 | install: 23 | - requirements: docs/requirements.txt 24 | - method: pip 25 | path: . 26 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | dist: xenial 2 | language: python 3 | stages: 4 | - "Static code analysis" 5 | - test 6 | - deploy 7 | python: 8 | - "3.5" 9 | - "3.6" 10 | - "3.7" 11 | notifications: 12 | email: false 13 | install: 14 | - pip install --upgrade pip 15 | - pip install poetry 16 | - poetry install 17 | script: 18 | # run tests, and get coverage: 19 | - poetry run python -m pytest --cov=src/ 20 | # test that the notebooks all run smoothly 21 | # - find docs -name '*.ipynb' -o -name 'examples/*.ipynb' | xargs poetry run jupyter nbconvert --to notebook --execute 22 | # submit coverage report to coveralls 23 | - poetry run coveralls 24 | jobs: 25 | include: 26 | - stage: "Static code analysis" 27 | name: "black formatting test" 28 | script: 29 | - black --check src/ 30 | python: "3.7" 31 | install: 32 | - pip install -qq black 33 | - stage: "Static code analysis" 34 | name: "flake8 check" 35 | script: 36 | - flake8 src/ 37 | python: "3.7" 38 | install: 39 | - pip install -qq flake8 40 | - stage: deploy 41 | name: "Deploy to pypi" 42 | if: tag IS present 43 | script: 44 | - poetry build 45 | - poetry publish --username $PYPI_USER --password $PYPI_PASSWORD 46 | python: "3.7" 47 | -------------------------------------------------------------------------------- /Interactive Surface Visualization Demo.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Interactive Surface Visualization Demo Notebook\n", 8 | "\n", 9 | " developed by Murat Bilgel, Benjamin Ely, Melanie Ganz, Krisanne Litinas, and Andrea Shafer\n", 10 | " Heavily indebted to Satra Ghosh, Chris Holdgraf, Anisha Keshavan, and Tal Yarkoni\n", 11 | " Builds on niwidgets\n", 12 | "\n" 13 | ] 14 | }, 15 | { 16 | "cell_type": "code", 17 | "execution_count": 1, 18 | "metadata": {}, 19 | "outputs": [], 20 | "source": [ 21 | "%matplotlib inline\n", 22 | "%load_ext autoreload\n", 23 | "%autoreload 2\n", 24 | "import os\n", 25 | "import sys\n", 26 | "from niwidgets import niwidget_surface\n", 27 | "from niwidgets.exampledata import examplesurface, exampleoverlays\n", 28 | "from pathlib import Path" 29 | ] 30 | }, 31 | { 32 | "cell_type": "code", 33 | "execution_count": 4, 34 | "metadata": {}, 35 | "outputs": [ 36 | { 37 | "data": { 38 | "application/vnd.jupyter.widget-view+json": { 39 | "model_id": "4546a2e205324411baac3eb08f7bf06e", 40 | "version_major": 2, 41 | "version_minor": 0 42 | }, 43 | "text/html": [ 44 | "
Failed to display Jupyter Widget of type interactive
.
\n", 46 | " If you're reading this message in Jupyter Notebook or JupyterLab, it may mean\n", 47 | " that the widgets JavaScript is still loading. If this message persists, it\n", 48 | " likely means that the widgets JavaScript library is either not installed or\n", 49 | " not enabled. See the Jupyter\n", 50 | " Widgets Documentation for setup instructions.\n", 51 | "
\n", 52 | "\n", 53 | " If you're reading this message in another notebook frontend (for example, a static\n", 54 | " rendering on GitHub or NBViewer),\n", 55 | " it may mean that your frontend doesn't currently support widgets.\n", 56 | "
\n" 57 | ], 58 | "text/plain": [ 59 | "interactive(children=(IntSlider(value=0, description='frame', max=3), Dropdown(description='colormap', index=74, options=('viridis', 'Accent', 'Blues', 'BrBG', 'BuGn', 'BuPu', 'CMRmap', 'Dark2', 'GnBu', 'Greens', 'Greys', 'OrRd', 'Oranges', 'PRGn', 'Paired', 'Pastel1', 'Pastel2', 'PiYG', 'PuBu', 'PuBuGn', 'PuOr', 'PuRd', 'Purples', 'RdBu', 'RdGy', 'RdPu', 'RdYlBu', 'RdYlGn', 'Reds', 'Set1', 'Set2', 'Set3', 'Spectral', 'Vega10', 'Vega20', 'Vega20b', 'Vega20c', 'Wistia', 'YlGn', 'YlGnBu', 'YlOrBr', 'YlOrRd', 'afmhot', 'autumn', 'binary', 'bone', 'brg', 'bwr', 'cool', 'coolwarm', 'copper', 'cubehelix', 'flag', 'gist_earth', 'gist_gray', 'gist_heat', 'gist_ncar', 'gist_rainbow', 'gist_stern', 'gist_yarg', 'gnuplot', 'gnuplot2', 'gray', 'hot', 'hsv', 'jet', 'nipy_spectral', 'ocean', 'pink', 'prism', 'rainbow', 'seismic', 'spectral', 'spring', 'summer', 'tab10', 'tab20', 'tab20b', 'tab20c', 'terrain', 'winter'), value='summer'), Output()), _dom_classes=('widget-interact',))" 60 | ] 61 | }, 62 | "metadata": {}, 63 | "output_type": "display_data" 64 | }, 65 | { 66 | "data": { 67 | "application/vnd.jupyter.widget-view+json": { 68 | "model_id": "fddb214fc89b4e7dad8bbdc5e855d0c2", 69 | "version_major": 2, 70 | "version_minor": 0 71 | }, 72 | "text/html": [ 73 | "Failed to display Jupyter Widget of type Figure
.
\n", 75 | " If you're reading this message in Jupyter Notebook or JupyterLab, it may mean\n", 76 | " that the widgets JavaScript is still loading. If this message persists, it\n", 77 | " likely means that the widgets JavaScript library is either not installed or\n", 78 | " not enabled. See the Jupyter\n", 79 | " Widgets Documentation for setup instructions.\n", 80 | "
\n", 81 | "\n", 82 | " If you're reading this message in another notebook frontend (for example, a static\n", 83 | " rendering on GitHub or NBViewer),\n", 84 | " it may mean that your frontend doesn't currently support widgets.\n", 85 | "
\n" 86 | ], 87 | "text/plain": [ 88 | "Figure(camera_center=[0.0, 0.0, 0.0], camera_fov=1.0, height=600, matrix_projection=[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], matrix_world=[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], meshes=[Mesh(color=array([[ 0. , 0.5, 0.4],\n", 89 | " [ 0. , 0.5, 0.4],\n", 90 | " [ 0. , 0.5, 0.4],\n", 91 | " ..., \n", 92 | " [ 0. , 0.5, 0.4],\n", 93 | " [ 0. , 0.5, 0.4],\n", 94 | " [ 0. , 0.5, 0.4]]), texture=None, triangles=array([[ 0, 1, 3],\n", 95 | " [ 4, 3, 1],\n", 96 | " [ 0, 91, 1],\n", 97 | " ..., \n", 98 | " [123307, 123906, 123895],\n", 99 | " [123906, 123907, 123895],\n", 100 | " [123885, 124986, 124987]], dtype=uint32), x=array([ 18.7413578 , 18.37849426, 19.00789833, ..., 17.78539658,\n", 101 | " 17.8218174 , 17.95105362]), y=array([-127.09669495, -127.08947754, -127.14855194, ..., 96.06409454,\n", 102 | " 96.46263123, 96.3392868 ]), z=array([-48.42454529, -48.42292786, -48.9959259 , ..., 44.24810028,\n", 103 | " 44.08300781, 44.18468475]))], style={'axes': {'color': 'black', 'label': {'color': 'black'}, 'ticklabel': {'color': 'black'}, 'visible': False}, 'background-color': 'white', 'box': {'visible': False}}, tf=None, width=600, xlim=[-100.0, 100.0], ylim=[-127.3917007446289, 127.3917007446289], zlim=[-100.0, 100.0])" 104 | ] 105 | }, 106 | "metadata": {}, 107 | "output_type": "display_data" 108 | } 109 | ], 110 | "source": [ 111 | "my_widget = niwidget_surface.SurfaceWidget(examplesurface, exampleoverlays)\n", 112 | "\n", 113 | "my_widget.surface_plotter(showZeroes=True)" 114 | ] 115 | }, 116 | { 117 | "cell_type": "code", 118 | "execution_count": null, 119 | "metadata": {}, 120 | "outputs": [], 121 | "source": [] 122 | } 123 | ], 124 | "metadata": { 125 | "kernelspec": { 126 | "display_name": "Python 3", 127 | "language": "python", 128 | "name": "python3" 129 | }, 130 | "language_info": { 131 | "codemirror_mode": { 132 | "name": "ipython", 133 | "version": 3 134 | }, 135 | "file_extension": ".py", 136 | "mimetype": "text/x-python", 137 | "name": "python", 138 | "nbconvert_exporter": "python", 139 | "pygments_lexer": "ipython3", 140 | "version": "3.6.1" 141 | } 142 | }, 143 | "nbformat": 4, 144 | "nbformat_minor": 2 145 | } 146 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright 2017 Niwidgets developers 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = python -msphinx 7 | SPHINXPROJ = niwidgets 8 | SOURCEDIR = ./doc 9 | GH_PAGES_SOURCES = Makefile doc niwidgets index.ipynb 10 | BUILDDIR = doc/_build 11 | # BUILDDIR = .. 12 | 13 | # Put it first so that "make" without argument is like "make help". 14 | help: 15 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 16 | 17 | .PHONY: help Makefile 18 | 19 | # Catch-all target: route all unknown targets to Sphinx using the new 20 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 21 | %: Makefile 22 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 23 | 24 | gh-pages: 25 | git checkout gh-pages 26 | rm -rf * 27 | git checkout master $(GH_PAGES_SOURCES) 28 | git reset HEAD 29 | cp ./index.ipynb doc/examples.ipynb 30 | make html 31 | mv -fv $(BUILDDIR)/html/* ./ 32 | rm -rf $(SOURCEDIR) build 33 | > .nojekyll 34 | git add -A 35 | git commit -m "Generated gh-pages automatically." 36 | git push origin gh-pages 37 | git checkout master 38 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Neuroimaging Widgets (`niwidgets`) 2 | 3 | This repository is supposed to provide easy and general wrappers to display 4 | interactive widgets that visualise standard-format neuroimaging data, using new 5 | functions and standard functions from other libraries. It looks like this: 6 | 7 |  8 | 9 | Install via: 10 | 11 | ``` 12 | pip install niwidgets 13 | ``` 14 | 15 | Or, to get the most up-to-date development version from github: 16 | 17 | ``` 18 | pip install git+git://github.com/nipy/niwidgets/ 19 | ``` 20 | 21 | It requires nibabel and nilearn: 22 | 23 | ``` 24 | pip install nibabel nilearn 25 | ``` 26 | 27 | Check out the examples using the code in this notebook here: 28 | https://github.com/nipy/niwidgets/blob/master/index.ipynb (you need to run the 29 | notebook on your local machine to use the interactive features). 30 | 31 | or using binder here: 32 | https://mybinder.org/v2/gh/nipy/niwidgets/master?filepath=index.ipynb 33 | 34 | ### Usage: 35 | 36 | There are currently three supported widgets: 37 | 38 | 1. Volume widgets. This widget is primarily designed to mimic existing tools 39 | such asFailed to display Jupyter Widget of type interactive
.
\n", 54 | " If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean\n", 55 | " that the widgets JavaScript is still loading. If this message persists, it\n", 56 | " likely means that the widgets JavaScript library is either not installed or\n", 57 | " not enabled. See the Jupyter\n", 58 | " Widgets Documentation for setup instructions.\n", 59 | "
\n", 60 | "\n", 61 | " If you're reading this message in another frontend (for example, a static\n", 62 | " rendering on GitHub or NBViewer),\n", 63 | " it may mean that your frontend doesn't currently support widgets.\n", 64 | "
\n" 65 | ], 66 | "text/plain": [ 67 | "interactive(children=(IntSlider(value=45, continuous_update=False, description='x', max=90), IntSlider(value=54, continuous_update=False, description='y', max=108), IntSlider(value=45, continuous_update=False, description='z', max=90), Dropdown(description='Colormap:', index=73, options=('Accent', 'Blues', 'BrBG', 'BuGn', 'BuPu', 'CMRmap', 'Dark2', 'GnBu', 'Greens', 'Greys', 'OrRd', 'Oranges', 'PRGn', 'Paired', 'Pastel1', 'Pastel2', 'PiYG', 'PuBu', 'PuBuGn', 'PuOr', 'PuRd', 'Purples', 'RdBu', 'RdGy', 'RdPu', 'RdYlBu', 'RdYlGn', 'Reds', 'Set1', 'Set2', 'Set3', 'Spectral', 'Vega10', 'Vega20', 'Vega20b', 'Vega20c', 'Wistia', 'YlGn', 'YlGnBu', 'YlOrBr', 'YlOrRd', 'afmhot', 'autumn', 'binary', 'bone', 'brg', 'bwr', 'cool', 'coolwarm', 'copper', 'cubehelix', 'flag', 'gist_earth', 'gist_gray', 'gist_heat', 'gist_ncar', 'gist_rainbow', 'gist_stern', 'gist_yarg', 'gnuplot', 'gnuplot2', 'gray', 'hot', 'hsv', 'jet', 'nipy_spectral', 'ocean', 'pink', 'prism', 'rainbow', 'seismic', 'spectral', 'spring', 'summer', 'tab10', 'tab20', 'tab20b', 'tab20c', 'terrain', 'winter'), value='summer'), Output()), _dom_classes=('widget-interact',))" 68 | ] 69 | }, 70 | "metadata": {}, 71 | "output_type": "display_data" 72 | } 73 | ], 74 | "source": [ 75 | "# Let's try a simple parcellation map from a standard atlas\n", 76 | "from niwidgets import NiftiWidget\n", 77 | "from niwidgets import examplet1\n", 78 | "\n", 79 | "test_widget = NiftiWidget(examplet1)\n", 80 | "test_widget.nifti_plotter()" 81 | ] 82 | }, 83 | { 84 | "cell_type": "markdown", 85 | "metadata": {}, 86 | "source": [ 87 | "## Use plotting functions from `nilearn`\n", 88 | "\n", 89 | "`niwidgets` also lets you turn standard plots from the nilearn package into widgets. You can use any of them, and provide your own keyword arguments to set the slider options (if no key word argument is provided defaults are used).\n", 90 | "\n", 91 | "In particular, `niwidgets` should allow you to pick a colormap interactively for almost any plot type\n", 92 | "\n", 93 | "### `plot_epi`\n", 94 | "\n", 95 | "Plotting the same image but with the `nilearn` function `plot_epi`, we get this:\n" 96 | ] 97 | }, 98 | { 99 | "cell_type": "code", 100 | "execution_count": 4, 101 | "metadata": { 102 | "scrolled": false 103 | }, 104 | "outputs": [ 105 | { 106 | "data": { 107 | "text/plain": [ 108 | "Failed to display Jupyter Widget of type interactive
.
\n", 124 | " If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean\n", 125 | " that the widgets JavaScript is still loading. If this message persists, it\n", 126 | " likely means that the widgets JavaScript library is either not installed or\n", 127 | " not enabled. See the Jupyter\n", 128 | " Widgets Documentation for setup instructions.\n", 129 | "
\n", 130 | "\n", 131 | " If you're reading this message in another frontend (for example, a static\n", 132 | " rendering on GitHub or NBViewer),\n", 133 | " it may mean that your frontend doesn't currently support widgets.\n", 134 | "
\n" 135 | ], 136 | "text/plain": [ 137 | "interactive(children=(Dropdown(description='display_mode', options=('ortho', 'x', 'y', 'z', 'yx', 'xz', 'yz'), value='ortho'), Dropdown(description='Colormap:', index=73, options=('Accent', 'Blues', 'BrBG', 'BuGn', 'BuPu', 'CMRmap', 'Dark2', 'GnBu', 'Greens', 'Greys', 'OrRd', 'Oranges', 'PRGn', 'Paired', 'Pastel1', 'Pastel2', 'PiYG', 'PuBu', 'PuBuGn', 'PuOr', 'PuRd', 'Purples', 'RdBu', 'RdGy', 'RdPu', 'RdYlBu', 'RdYlGn', 'Reds', 'Set1', 'Set2', 'Set3', 'Spectral', 'Vega10', 'Vega20', 'Vega20b', 'Vega20c', 'Wistia', 'YlGn', 'YlGnBu', 'YlOrBr', 'YlOrRd', 'afmhot', 'autumn', 'binary', 'bone', 'brg', 'bwr', 'cool', 'coolwarm', 'copper', 'cubehelix', 'flag', 'gist_earth', 'gist_gray', 'gist_heat', 'gist_ncar', 'gist_rainbow', 'gist_stern', 'gist_yarg', 'gnuplot', 'gnuplot2', 'gray', 'hot', 'hsv', 'jet', 'nipy_spectral', 'ocean', 'pink', 'prism', 'rainbow', 'seismic', 'spectral', 'spring', 'summer', 'tab10', 'tab20', 'tab20b', 'tab20c', 'terrain', 'winter'), value='summer'), IntSlider(value=0, continuous_update=False, description='x', max=90, min=-90), IntSlider(value=0, continuous_update=False, description='y', max=90, min=-90), IntSlider(value=0, continuous_update=False, description='z', max=90, min=-90), Output()), _dom_classes=('widget-interact',))" 138 | ] 139 | }, 140 | "metadata": {}, 141 | "output_type": "display_data" 142 | } 143 | ], 144 | "source": [ 145 | "import nilearn.plotting as nip\n", 146 | "\n", 147 | "test_widget.nifti_plotter(plotting_func=nip.plot_epi, display_mode=['ortho', 'x', 'y', 'z', 'yx', 'xz', 'yz'])" 148 | ] 149 | }, 150 | { 151 | "cell_type": "markdown", 152 | "metadata": {}, 153 | "source": [ 154 | "### `plot_glass_brain`\n", 155 | "\n", 156 | "This is an example of a glass brain plot with a standard visual perception activation map from neurosynth (this also ships as an example with `niwidgets`:" 157 | ] 158 | }, 159 | { 160 | "cell_type": "code", 161 | "execution_count": 5, 162 | "metadata": {}, 163 | "outputs": [ 164 | { 165 | "data": { 166 | "text/plain": [ 167 | "Failed to display Jupyter Widget of type interactive
.
\n", 183 | " If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean\n", 184 | " that the widgets JavaScript is still loading. If this message persists, it\n", 185 | " likely means that the widgets JavaScript library is either not installed or\n", 186 | " not enabled. See the Jupyter\n", 187 | " Widgets Documentation for setup instructions.\n", 188 | "
\n", 189 | "\n", 190 | " If you're reading this message in another frontend (for example, a static\n", 191 | " rendering on GitHub or NBViewer),\n", 192 | " it may mean that your frontend doesn't currently support widgets.\n", 193 | "
\n" 194 | ], 195 | "text/plain": [ 196 | "interactive(children=(FloatSlider(value=5.0, description='threshold', max=10.0, step=0.01), Dropdown(description='display_mode', options=('ortho', 'xz'), value='ortho'), Dropdown(description='Colormap:', index=73, options=('Accent', 'Blues', 'BrBG', 'BuGn', 'BuPu', 'CMRmap', 'Dark2', 'GnBu', 'Greens', 'Greys', 'OrRd', 'Oranges', 'PRGn', 'Paired', 'Pastel1', 'Pastel2', 'PiYG', 'PuBu', 'PuBuGn', 'PuOr', 'PuRd', 'Purples', 'RdBu', 'RdGy', 'RdPu', 'RdYlBu', 'RdYlGn', 'Reds', 'Set1', 'Set2', 'Set3', 'Spectral', 'Vega10', 'Vega20', 'Vega20b', 'Vega20c', 'Wistia', 'YlGn', 'YlGnBu', 'YlOrBr', 'YlOrRd', 'afmhot', 'autumn', 'binary', 'bone', 'brg', 'bwr', 'cool', 'coolwarm', 'copper', 'cubehelix', 'flag', 'gist_earth', 'gist_gray', 'gist_heat', 'gist_ncar', 'gist_rainbow', 'gist_stern', 'gist_yarg', 'gnuplot', 'gnuplot2', 'gray', 'hot', 'hsv', 'jet', 'nipy_spectral', 'ocean', 'pink', 'prism', 'rainbow', 'seismic', 'spectral', 'spring', 'summer', 'tab10', 'tab20', 'tab20b', 'tab20c', 'terrain', 'winter'), value='summer'), Output()), _dom_classes=('widget-interact',))" 197 | ] 198 | }, 199 | "metadata": {}, 200 | "output_type": "display_data" 201 | } 202 | ], 203 | "source": [ 204 | "from niwidgets import examplezmap\n", 205 | "import nilearn.plotting as nip\n", 206 | "test = NiftiWidget(examplezmap)\n", 207 | "test.nifti_plotter(plotting_func=nip.plot_glass_brain, threshold=(0.0, 10.0, 0.01),\n", 208 | " display_mode=['ortho','xz'])" 209 | ] 210 | }, 211 | { 212 | "cell_type": "markdown", 213 | "metadata": {}, 214 | "source": [ 215 | "### `plot_img`\n", 216 | "\n", 217 | "Another image slicer type plot from the nilearn package, this time with an example atlas (the CC400 atlas), and setting the colormap:" 218 | ] 219 | }, 220 | { 221 | "cell_type": "code", 222 | "execution_count": 6, 223 | "metadata": {}, 224 | "outputs": [ 225 | { 226 | "data": { 227 | "text/plain": [ 228 | "Failed to display Jupyter Widget of type interactive
.
\n", 244 | " If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean\n", 245 | " that the widgets JavaScript is still loading. If this message persists, it\n", 246 | " likely means that the widgets JavaScript library is either not installed or\n", 247 | " not enabled. See the Jupyter\n", 248 | " Widgets Documentation for setup instructions.\n", 249 | "
\n", 250 | "\n", 251 | " If you're reading this message in another frontend (for example, a static\n", 252 | " rendering on GitHub or NBViewer),\n", 253 | " it may mean that your frontend doesn't currently support widgets.\n", 254 | "
\n" 255 | ], 256 | "text/plain": [ 257 | "interactive(children=(Dropdown(description='display_mode', options=('ortho', 'x', 'y', 'z'), value='ortho'), IntSlider(value=0, continuous_update=False, description='x', max=90, min=-90), IntSlider(value=0, continuous_update=False, description='y', max=90, min=-90), IntSlider(value=0, continuous_update=False, description='z', max=90, min=-90), Output()), _dom_classes=('widget-interact',))" 258 | ] 259 | }, 260 | "metadata": {}, 261 | "output_type": "display_data" 262 | } 263 | ], 264 | "source": [ 265 | "from niwidgets import NiftiWidget\n", 266 | "from niwidgets import exampleatlas\n", 267 | "atlas_widget = NiftiWidget(exampleatlas)\n", 268 | "atlas_widget.nifti_plotter(plotting_func=nip.plot_img, display_mode=['ortho', 'x', 'y', 'z'], colormap='hot')" 269 | ] 270 | }, 271 | { 272 | "cell_type": "markdown", 273 | "metadata": {}, 274 | "source": [ 275 | "# Surface data\n", 276 | "\n", 277 | "If you have surface data, you can import the `SurfaceWidget` and use it in a similar fashion to the `NiftiWidget`. Import and define it in the same way:" 278 | ] 279 | }, 280 | { 281 | "cell_type": "code", 282 | "execution_count": 7, 283 | "metadata": {}, 284 | "outputs": [ 285 | { 286 | "data": { 287 | "application/vnd.jupyter.widget-view+json": { 288 | "model_id": "51cfd92f17df4fc786205ee1beae45d3", 289 | "version_major": 2, 290 | "version_minor": 0 291 | }, 292 | "text/html": [ 293 | "Failed to display Jupyter Widget of type interactive
.
\n", 295 | " If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean\n", 296 | " that the widgets JavaScript is still loading. If this message persists, it\n", 297 | " likely means that the widgets JavaScript library is either not installed or\n", 298 | " not enabled. See the Jupyter\n", 299 | " Widgets Documentation for setup instructions.\n", 300 | "
\n", 301 | "\n", 302 | " If you're reading this message in another frontend (for example, a static\n", 303 | " rendering on GitHub or NBViewer),\n", 304 | " it may mean that your frontend doesn't currently support widgets.\n", 305 | "
\n" 306 | ], 307 | "text/plain": [ 308 | "interactive(children=(Dropdown(description='Colormap:', index=73, options=('Accent', 'Blues', 'BrBG', 'BuGn', 'BuPu', 'CMRmap', 'Dark2', 'GnBu', 'Greens', 'Greys', 'OrRd', 'Oranges', 'PRGn', 'Paired', 'Pastel1', 'Pastel2', 'PiYG', 'PuBu', 'PuBuGn', 'PuOr', 'PuRd', 'Purples', 'RdBu', 'RdGy', 'RdPu', 'RdYlBu', 'RdYlGn', 'Reds', 'Set1', 'Set2', 'Set3', 'Spectral', 'Vega10', 'Vega20', 'Vega20b', 'Vega20c', 'Wistia', 'YlGn', 'YlGnBu', 'YlOrBr', 'YlOrRd', 'afmhot', 'autumn', 'binary', 'bone', 'brg', 'bwr', 'cool', 'coolwarm', 'copper', 'cubehelix', 'flag', 'gist_earth', 'gist_gray', 'gist_heat', 'gist_ncar', 'gist_rainbow', 'gist_stern', 'gist_yarg', 'gnuplot', 'gnuplot2', 'gray', 'hot', 'hsv', 'jet', 'nipy_spectral', 'ocean', 'pink', 'prism', 'rainbow', 'seismic', 'spectral', 'spring', 'summer', 'tab10', 'tab20', 'tab20b', 'tab20c', 'terrain', 'winter'), value='summer'), Output()), _dom_classes=('widget-interact',))" 309 | ] 310 | }, 311 | "metadata": {}, 312 | "output_type": "display_data" 313 | }, 314 | { 315 | "data": { 316 | "application/vnd.jupyter.widget-view+json": { 317 | "model_id": "2624832a01314342a1366587a73d2508", 318 | "version_major": 2, 319 | "version_minor": 0 320 | }, 321 | "text/html": [ 322 | "Failed to display Jupyter Widget of type Figure
.
\n", 324 | " If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean\n", 325 | " that the widgets JavaScript is still loading. If this message persists, it\n", 326 | " likely means that the widgets JavaScript library is either not installed or\n", 327 | " not enabled. See the Jupyter\n", 328 | " Widgets Documentation for setup instructions.\n", 329 | "
\n", 330 | "\n", 331 | " If you're reading this message in another frontend (for example, a static\n", 332 | " rendering on GitHub or NBViewer),\n", 333 | " it may mean that your frontend doesn't currently support widgets.\n", 334 | "
\n" 335 | ], 336 | "text/plain": [ 337 | "Figure(camera_center=[0.0, 0.0, 0.0], camera_fov=1.0, height=600, matrix_projection=[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], matrix_world=[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], meshes=[Mesh(color=array([[1., 1., 1.],\n", 338 | " [1., 1., 1.],\n", 339 | " [1., 1., 1.],\n", 340 | " ...,\n", 341 | " [1., 1., 1.],\n", 342 | " [1., 1., 1.],\n", 343 | " [1., 1., 1.]]), texture=None, triangles=array([[ 0, 1, 3],\n", 344 | " [ 4, 3, 1],\n", 345 | " [ 0, 91, 1],\n", 346 | " ...,\n", 347 | " [123307, 123906, 123895],\n", 348 | " [123906, 123907, 123895],\n", 349 | " [123885, 124986, 124987]], dtype=uint32), x=array([18.7413578 , 18.37849426, 19.00789833, ..., 17.78539658,\n", 350 | " 17.8218174 , 17.95105362]), y=array([-127.09669495, -127.08947754, -127.14855194, ..., 96.06409454,\n", 351 | " 96.46263123, 96.3392868 ]), z=array([-48.42454529, -48.42292786, -48.9959259 , ..., 44.24810028,\n", 352 | " 44.08300781, 44.18468475]))], style={'axes': {'color': 'black', 'label': {'color': 'black'}, 'ticklabel': {'color': 'black'}, 'visible': False}, 'background-color': 'white', 'box': {'visible': False}}, tf=None, width=600, xlim=[-100.0, 100.0], ylim=[-127.3917007446289, 127.3917007446289], zlim=[-100.0, 100.0])" 353 | ] 354 | }, 355 | "metadata": {}, 356 | "output_type": "display_data" 357 | } 358 | ], 359 | "source": [ 360 | "from niwidgets import SurfaceWidget\n", 361 | "from niwidgets.exampledata import examplesurface\n", 362 | "\n", 363 | "surface_widget = SurfaceWidget(examplesurface)\n", 364 | "surface_widget.surface_plotter()" 365 | ] 366 | }, 367 | { 368 | "cell_type": "markdown", 369 | "metadata": {}, 370 | "source": [ 371 | "If you want to plot additional data as overlays, you can pass those as either loaded `GiftiImages` (loaded using nibabel), or as file paths to a `.annot`, `.thickness`, `.curv`, `.sulc`, or `.gii` file.\n", 372 | "\n", 373 | "If you pass them in a dictionary (see e.g. `niwidgets.exampledata.exampleoverlays`), the keys of the dictionary are used for the Options in a dropdown menu:" 374 | ] 375 | }, 376 | { 377 | "cell_type": "code", 378 | "execution_count": 8, 379 | "metadata": { 380 | "scrolled": false 381 | }, 382 | "outputs": [ 383 | { 384 | "data": { 385 | "application/vnd.jupyter.widget-view+json": { 386 | "model_id": "6b090722cb50426fbaaecce2a3da82f3", 387 | "version_major": 2, 388 | "version_minor": 0 389 | }, 390 | "text/html": [ 391 | "Failed to display Jupyter Widget of type interactive
.
\n", 393 | " If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean\n", 394 | " that the widgets JavaScript is still loading. If this message persists, it\n", 395 | " likely means that the widgets JavaScript library is either not installed or\n", 396 | " not enabled. See the Jupyter\n", 397 | " Widgets Documentation for setup instructions.\n", 398 | "
\n", 399 | "\n", 400 | " If you're reading this message in another frontend (for example, a static\n", 401 | " rendering on GitHub or NBViewer),\n", 402 | " it may mean that your frontend doesn't currently support widgets.\n", 403 | "
\n" 404 | ], 405 | "text/plain": [ 406 | "interactive(children=(Dropdown(description='Overlay:', options=('Area', 'Curvature', 'Thickness', 'Annotation'), value='Area'), Dropdown(description='Colormap:', index=73, options=('Accent', 'Blues', 'BrBG', 'BuGn', 'BuPu', 'CMRmap', 'Dark2', 'GnBu', 'Greens', 'Greys', 'OrRd', 'Oranges', 'PRGn', 'Paired', 'Pastel1', 'Pastel2', 'PiYG', 'PuBu', 'PuBuGn', 'PuOr', 'PuRd', 'Purples', 'RdBu', 'RdGy', 'RdPu', 'RdYlBu', 'RdYlGn', 'Reds', 'Set1', 'Set2', 'Set3', 'Spectral', 'Vega10', 'Vega20', 'Vega20b', 'Vega20c', 'Wistia', 'YlGn', 'YlGnBu', 'YlOrBr', 'YlOrRd', 'afmhot', 'autumn', 'binary', 'bone', 'brg', 'bwr', 'cool', 'coolwarm', 'copper', 'cubehelix', 'flag', 'gist_earth', 'gist_gray', 'gist_heat', 'gist_ncar', 'gist_rainbow', 'gist_stern', 'gist_yarg', 'gnuplot', 'gnuplot2', 'gray', 'hot', 'hsv', 'jet', 'nipy_spectral', 'ocean', 'pink', 'prism', 'rainbow', 'seismic', 'spectral', 'spring', 'summer', 'tab10', 'tab20', 'tab20b', 'tab20c', 'terrain', 'winter'), value='summer'), Output()), _dom_classes=('widget-interact',))" 407 | ] 408 | }, 409 | "metadata": {}, 410 | "output_type": "display_data" 411 | }, 412 | { 413 | "data": { 414 | "application/vnd.jupyter.widget-view+json": { 415 | "model_id": "3a05401222af4d7cbd4c2a98d4c1caf3", 416 | "version_major": 2, 417 | "version_minor": 0 418 | }, 419 | "text/html": [ 420 | "Failed to display Jupyter Widget of type Figure
.
\n", 422 | " If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean\n", 423 | " that the widgets JavaScript is still loading. If this message persists, it\n", 424 | " likely means that the widgets JavaScript library is either not installed or\n", 425 | " not enabled. See the Jupyter\n", 426 | " Widgets Documentation for setup instructions.\n", 427 | "
\n", 428 | "\n", 429 | " If you're reading this message in another frontend (for example, a static\n", 430 | " rendering on GitHub or NBViewer),\n", 431 | " it may mean that your frontend doesn't currently support widgets.\n", 432 | "
\n" 433 | ], 434 | "text/plain": [ 435 | "Figure(camera_center=[0.0, 0.0, 0.0], camera_fov=1.0, height=600, matrix_projection=[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], matrix_world=[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], meshes=[Mesh(color=array([[1., 1., 1.],\n", 436 | " [1., 1., 1.],\n", 437 | " [1., 1., 1.],\n", 438 | " ...,\n", 439 | " [1., 1., 1.],\n", 440 | " [1., 1., 1.],\n", 441 | " [1., 1., 1.]]), texture=None, triangles=array([[ 0, 1, 3],\n", 442 | " [ 4, 3, 1],\n", 443 | " [ 0, 91, 1],\n", 444 | " ...,\n", 445 | " [123307, 123906, 123895],\n", 446 | " [123906, 123907, 123895],\n", 447 | " [123885, 124986, 124987]], dtype=uint32), x=array([18.7413578 , 18.37849426, 19.00789833, ..., 17.78539658,\n", 448 | " 17.8218174 , 17.95105362]), y=array([-127.09669495, -127.08947754, -127.14855194, ..., 96.06409454,\n", 449 | " 96.46263123, 96.3392868 ]), z=array([-48.42454529, -48.42292786, -48.9959259 , ..., 44.24810028,\n", 450 | " 44.08300781, 44.18468475]))], style={'axes': {'color': 'black', 'label': {'color': 'black'}, 'ticklabel': {'color': 'black'}, 'visible': False}, 'background-color': 'white', 'box': {'visible': False}}, tf=None, width=600, xlim=[-100.0, 100.0], ylim=[-127.3917007446289, 127.3917007446289], zlim=[-100.0, 100.0])" 451 | ] 452 | }, 453 | "metadata": {}, 454 | "output_type": "display_data" 455 | } 456 | ], 457 | "source": [ 458 | "from niwidgets import SurfaceWidget\n", 459 | "from niwidgets.exampledata import examplesurface\n", 460 | "from niwidgets.exampledata import exampleoverlays\n", 461 | "\n", 462 | "surface_widget = SurfaceWidget(examplesurface, overlayfiles=exampleoverlays)\n", 463 | "\n", 464 | "surface_widget.surface_plotter()" 465 | ] 466 | }, 467 | { 468 | "cell_type": "markdown", 469 | "metadata": {}, 470 | "source": [ 471 | "## Streamlines\n", 472 | "\n", 473 | "If you have mrtrix or trackvis streamlines, you can display them using the `StreamlineWidget`. Instead of passing a streamlines file, one can also pass a nibabel streamline sequence to the widget." 474 | ] 475 | }, 476 | { 477 | "cell_type": "code", 478 | "execution_count": 9, 479 | "metadata": {}, 480 | "outputs": [ 481 | { 482 | "data": { 483 | "application/vnd.jupyter.widget-view+json": { 484 | "model_id": "de66333d4cce48418133e6ef22f90f5a", 485 | "version_major": 2, 486 | "version_minor": 0 487 | }, 488 | "text/html": [ 489 | "Failed to display Jupyter Widget of type VBox
.
\n", 491 | " If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean\n", 492 | " that the widgets JavaScript is still loading. If this message persists, it\n", 493 | " likely means that the widgets JavaScript library is either not installed or\n", 494 | " not enabled. See the Jupyter\n", 495 | " Widgets Documentation for setup instructions.\n", 496 | "
\n", 497 | "\n", 498 | " If you're reading this message in another frontend (for example, a static\n", 499 | " rendering on GitHub or NBViewer),\n", 500 | " it may mean that your frontend doesn't currently support widgets.\n", 501 | "
\n" 502 | ], 503 | "text/plain": [ 504 | "VBox(children=(Figure(camera_center=[0.0, 0.0, 0.0], camera_fov=1.0, height=500, matrix_projection=[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], matrix_world=[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], meshes=[Mesh(color=array([[ 0.5103893 , 0.7629744 , -0.3967025 ],\n", 505 | " [ 0.5103893 , 0.7629744 , -0.3967025 ],\n", 506 | " [ 0.5103893 , 0.7629744 , -0.3967025 ],\n", 507 | " ...,\n", 508 | " [-0.06500284, -0.4601881 , 0.8854386 ],\n", 509 | " [-0.06500284, -0.4601881 , 0.8854386 ],\n", 510 | " [-0.06500284, -0.4601881 , 0.8854386 ]], dtype=float32), lines=array([ 0, 1, 1, ..., 161141, 161141, 161142], dtype=uint32), texture=None, x=array([76.33768 , 76.1091 , 75.86626 , ..., 49.14276 , 49.224125,\n", 511 | " 49.276688], dtype=float32), y=array([49.301598, 48.87002 , 48.451088, ..., 45.552483, 45.69906 ,\n", 512 | " 45.840733], dtype=float32), z=array([28.900988 , 29.0082 , 29.132801 , ..., 0.87795854,\n", 513 | " 0.40690082, -0.0697186 ], dtype=float32))], style={'axes': {'color': 'red', 'label': {'color': 'white'}, 'ticklabel': {'color': 'white'}, 'visible': False}, 'background-color': 'white', 'box': {'visible': False}}, tf=None, xlim=[-0.497088223695755, 94.8163833618164], ylim=[-0.497088223695755, 94.8163833618164], zlim=[-0.497088223695755, 94.8163833618164]),))" 514 | ] 515 | }, 516 | "metadata": {}, 517 | "output_type": "display_data" 518 | }, 519 | { 520 | "data": { 521 | "application/vnd.jupyter.widget-view+json": { 522 | "model_id": "ccdeeb65175d403491649ee1a498a14e", 523 | "version_major": 2, 524 | "version_minor": 0 525 | }, 526 | "text/html": [ 527 | "Failed to display Jupyter Widget of type interactive
.
\n", 529 | " If you're reading this message in the Jupyter Notebook or JupyterLab Notebook, it may mean\n", 530 | " that the widgets JavaScript is still loading. If this message persists, it\n", 531 | " likely means that the widgets JavaScript library is either not installed or\n", 532 | " not enabled. See the Jupyter\n", 533 | " Widgets Documentation for setup instructions.\n", 534 | "
\n", 535 | "\n", 536 | " If you're reading this message in another frontend (for example, a static\n", 537 | " rendering on GitHub or NBViewer),\n", 538 | " it may mean that your frontend doesn't currently support widgets.\n", 539 | "
\n" 540 | ], 541 | "text/plain": [ 542 | "interactive(children=(FloatSlider(value=43.99999313354492, continuous_update=False, description='threshold', max=97.0, min=13.999998092651367), Output()), _dom_classes=('widget-interact',))" 543 | ] 544 | }, 545 | "metadata": {}, 546 | "output_type": "display_data" 547 | } 548 | ], 549 | "source": [ 550 | "from niwidgets import StreamlineWidget\n", 551 | "from niwidgets.exampledata import streamlines\n", 552 | "\n", 553 | "sw = StreamlineWidget(filename=streamlines)\n", 554 | "style = {'axes': {'color': 'red',\n", 555 | " 'label': {'color': 'white'},\n", 556 | " 'ticklabel': {'color': 'white'},\n", 557 | " 'visible': False},\n", 558 | " 'background-color': 'white',\n", 559 | " 'box': {'visible': False}}\n", 560 | "sw.plot(display_fraction=0.5, width=500, height=500, style=style, percentile=80)" 561 | ] 562 | }, 563 | { 564 | "cell_type": "code", 565 | "execution_count": null, 566 | "metadata": {}, 567 | "outputs": [], 568 | "source": [] 569 | } 570 | ], 571 | "metadata": { 572 | "kernelspec": { 573 | "display_name": "Python [default]", 574 | "language": "python", 575 | "name": "python3" 576 | }, 577 | "language_info": { 578 | "codemirror_mode": { 579 | "name": "ipython", 580 | "version": 3 581 | }, 582 | "file_extension": ".py", 583 | "mimetype": "text/x-python", 584 | "name": "python", 585 | "nbconvert_exporter": "python", 586 | "pygments_lexer": "ipython3", 587 | "version": "3.6.4" 588 | } 589 | }, 590 | "nbformat": 4, 591 | "nbformat_minor": 2 592 | } 593 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.poetry] 2 | name = "niwidgets" 3 | version = "0.2.2" 4 | description = "'Interactive jupyter widgets for neuroimaging.'" 5 | authors = ["Jan Freyberg