Skip to content

Commit 7be5d95

Browse files
authored
Merge pull request #98 from liuzhenqi77/surf-plot
[DOC] Added example for plotting on fsaverage surface
2 parents 79936ea + be78189 commit 7be5d95

File tree

2 files changed

+113
-0
lines changed

2 files changed

+113
-0
lines changed

docs/installation.rst

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,88 @@ Alternatively, you can install ``netneurotools`` directly from PyPi with:
2323
.. code-block:: bash
2424
2525
pip install netneurotools
26+
27+
Optional installation for surface plotting
28+
------------------------------------------
29+
30+
In order to use surface plotting functionality like
31+
:py:func:`netneurotools.plotting.plot_fsaverage`, you will need a working
32+
``vtk``/``mayavi``/``pysurfer`` installation. These can generally be installed
33+
with the following command:
34+
35+
.. code-block: bash
36+
37+
pip install vtk mayavi pysurfer
38+
39+
However, we include instructions below for installing the bleeding-edge version
40+
of the dependencies. Note: if you already have a working ``mayavi``/``pysurfer``
41+
installation, there is generally no need to follow these instructions!
42+
43+
- Install Qt
44+
45+
- Installing Jupyterlab using conda (``conda install jupyterlab``)
46+
should automatically install the required qt/pyqt packages.
47+
- If otherwise, using ``pip install PyQt5`` should also work as
48+
suggested by
49+
`here <http://docs.enthought.com/mayavi/mayavi/installation.html#latest-stable-release>`__
50+
and `here <https://github.com/enthought/mayavi#installation>`__
51+
- If not working, search for the error prompts like
52+
`this <https://askubuntu.com/questions/308128/failed-to-load-platform-plugin-xcb-while-launching-qt5-app-on-linux-without>`__.
53+
54+
- Install VTK
55+
56+
- Official wheels for the latest VTK9 are available for download
57+
`here <https://vtk.org/download/>`__.
58+
- For Python>=3.9, official wheel is `not available at the
59+
moment <https://discourse.vtk.org/t/python-3-9/4369/3>`__.
60+
Following
61+
`here <https://docs.pyvista.org/extras/building_vtk.html>`__ and
62+
`here <https://gitlab.kitware.com/vtk/vtk/-/blob/master/Documentation/dev/build.md#python-wheels>`__,
63+
it’s possible to build the wheel. See the example code below.
64+
65+
.. code:: bash
66+
67+
git clone https://github.com/Kitware/VTK
68+
cd VTK
69+
70+
mkdir build
71+
cd build
72+
PYBIN=<PATH TO YOUR PYTHON EXECUTABLE>
73+
cmake -GNinja -DVTK_BUILD_TESTING=OFF -DVTK_WHEEL_BUILD=ON -DVTK_PYTHON_VERSION=3 -DVTK_WRAP_PYTHON=ON -DPython3_EXECUTABLE=$PYBIN ../
74+
75+
# optionally, apt install ninja
76+
ninja
77+
$PYBIN setup.py bdist_wheel
78+
79+
# to install
80+
pip install dist/vtk-*.whl
81+
82+
- Install mayavi
83+
84+
- Install from source
85+
``pip install git+https://github.com/enthought/mayavi.git``
86+
87+
- Install pysurfer
88+
89+
- Install from source
90+
``pip install git+https://github.com/nipy/PySurfer.git``
91+
92+
- Install netneurotools
93+
94+
- Install from source
95+
``pip install git+https://github.com/netneurolab/netneurotools.git``
96+
97+
Troubleshooting
98+
~~~~~~~~~~~~~~~
99+
100+
- Error related to ``from tvtk.vtk_module import VTK_MAJOR_VERSION``
101+
102+
- `Currently not
103+
fixed <https://github.com/enthought/mayavi/issues/939#issuecomment-747266625>`__
104+
- Temporary workaround: adding ``VTK_MAJOR_VERSION = 9`` to
105+
``mayavi/tvtk/vtk_module.py``
106+
107+
- Error related to GLX
108+
109+
- Try ``glxgears`` or ``glxinfo``
110+
- Check display driver compatibility

netneurotools/plotting.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,34 @@ def plot_fsaverage(data, *, lhannot, rhannot, order='lr', mask=None,
416416
-------
417417
brain : surfer.Brain
418418
Plotted PySurfer brain
419+
420+
Examples
421+
--------
422+
>>> import numpy as np
423+
>>> from netneurotools.datasets import fetch_cammoun2012, \
424+
fetch_schaefer2018
425+
>>> from netneurotools.plotting import plot_fsaverage
426+
427+
Plotting with the Cammoun 2012 parcellation we specify `order='RL'` because
428+
many of the Lausanne connectomes have data for the right hemisphere before
429+
the left hemisphere.
430+
431+
>>> values = np.random.rand(219)
432+
>>> scale = 'scale125'
433+
>>> cammoun = fetch_cammoun2012('fsaverage', verbose=False)[scale]
434+
>>> plot_fsaverage(values, order='RL',
435+
... lhannot=cammoun.lh, rhannot=cammoun.rh) # doctest: +SKIP
436+
437+
Plotting with the Schaefer 2018 parcellation we can use the default
438+
parameter for `order`:
439+
440+
>>> values = np.random.rand(400)
441+
>>> scale = '400Parcels7Networks'
442+
>>> schaefer = fetch_schaefer2018('fsaverage', verbose=False)[scale]
443+
>>> plot_fsaverage(values,
444+
... lhannot=schaefer.lh,
445+
... rhannot=schaefer.rh) # doctest: +SKIP
446+
419447
"""
420448

421449
subject_id, subjects_dir = _get_fs_subjid(subject_id, subjects_dir)

0 commit comments

Comments
 (0)