A set of pictures generated in Paraview and the brain-connectivity plugin is collected here. Feel free to send additional pictures to the authors/maintainers of the plugin.
The image is shown as a 3D volume, a specific cluster is highlighted from a cluster file computed offline.
The installation is done in 2 steps:
Things to consider:
The installation procedure for the package and the plugin depend on the version of Paraview in use.
In case you want to use the visualization plugin and the package functions inside Paraview, you will need to identify the version of Paraview you are using. The most important aspect is to
In case the installation of Paraview is standalone, Paraview may use its own Python interpreter (through
pvpython
or pvbatch
), while your package may be using another Python interpreter that is eg.
the one that defaults on your operating system.
Should this be the case, the interpreters in use in the plugin and the package would be different. This is usually not an issue, as the package code (as of May 2018) is pure Python and does not bring any compiled python extension. However, in case you start developing additional extensions and those contain python extensions, an ABI problem may occur and will potentially lead to a crash during the execution of the plugin.
To be safe, it is recommended to install a version of Paraview that uses the OS Python interpreter, and to use the same interpreter for installing our package.
See the Platform specific details for more information.
The package preferably installs in a virtual environment. Also since Paraview is using Python2, we suggest
sticking to Python2. For installing the package, you need at least virtualenv
and pip
. Once there,
let’s first create a virtual environment like this (in a terminal):
mkdir ~/.venvs
virtualenv --system-site-packages ~/.venvs/venv_paraview_brain
. ~/.venvs/venv_paraview_brain/bin/activate
and then navigate to the path where you cloned the package, and type
cd <brain-connectivity-visualization-path>
pip install -r requirements.txt
pip install .
After the installation, you should see the package with pip list
:
pip list
Package Version
-------------------------------- ---------
[...]
brain-connectivity-visualization 1.0
For installing the plugin, we first generate a binding between Paraview and the package in the form
of an .xml
file, and we then install/register this file in Paraview as a plugin.
This .xml
will act as a binding between the relevant functions in our package and Paraview.
There is no streamlined procedure for installing a python plugin into Paraview, and/or to use an external python library. Paraview has different installation flavour that differ according to the platform or the way you installed the tool. We tried to make the procedure as easy as possible.
Installing the package will bring you a script generate_brain_connectivity_plugin
that will
be used for generating a plugin file in the .xml
format. This little tool converts the
entry point of the plugin into an XML file that can be installed/registered into Paraview.
To call the tool, run the following from the command line terminal:
generate_brain_connectivity_plugin mpi_brain_plugin.xml
This plugin should then be imported into Paraview
Open the menu from Tools > Manage Plugins
:
On the custom filter window, click on Load New:
Select the .xml
file that you generated earlier, make sure that the file filter of the selection
dialog shows .xml
:
You should then see the plugin on the list of plugins, make sure the plugin is loaded. You may check
the autoload
option for loading the plugin the next time you start Paraview.
Warning
Paraview will need the .xml
file you generated every time it needs to run your plugin. In case you
move this file to some other physical location on disk, you will be needing to redo the installation steps
above after having uninstalled the plugin.
Also the plugin will be using the location of the python virtual environment where the package is installed. This will let you update the package (and the plugin functionalities) without registering the plugin again, but will prevent you from removing the virtual environment.
Note
In case you save your session in Paraview for later reuse/load, the plugin needs to be loaded prior to
loading the session. This is why the autoload
option is convenient.
Tip
You may have noticed the message
Local plugins are automatically searched for in <some-path>
at the top of the plugin list dialog box.
If you have a standalone installation of Paraview, you may generate the .xml
file directly there and
then skip the registration and loading of the plugin.
Paraview on OSX relies on the OSX system Python (2.7.X at the current day). This means that it is possible to install the package and the plugins from a unique location using a python virtual environment, and this will be the preferred method on this platform.
Warning
If another version of Python is in use from the command line, eg. after an installation with Homebrew (either Python2 or Python3), it would mean that you may fall in the case mentioned earlier, and it would be safer to make the OSX system Python the default in that case.
The installation of Paraview is often located in /Application
folder, and it is not
possible to write into the Paraview application folder. Therefor the installation
on OSX requires a virtual environment or a global installation.
Paraview comes with its own version of Numpy, that might not be ABI compatible with newer versions of the library. Numpy is extensively used in the visualization plugin, which indirectly means that the API being used in the plugin should be compatible with the version of Numpy installed along Paraview.
Some parts of the visualization plugin require VTK. It is unfortunately quite difficult to use VTK installation provided by Paraview. In particular it is not straightforward to use the libraries provided by Paraview with your own Python setup. One possibility would be
For compiling VTK:
cd <vtk-source-folder>
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=~/usr/local -DVTK_WRAP_PYTHON=ON ..
make -j 4
make install
For using VTK if it is not installed in a system folder (recommanded), if for instance VTK is installed in ~/usr/local
virtualenv venv_paraview
. venv_paraview/bin/activate
pip install -r requirements.txt
pip install .
pip install ipython
# adding VTK to the list of paths of the virtualenv
USER_SITE=$(python -c "import os; print os.environ['VIRTUAL_ENV']")
echo "/Users/<myself>/usr/local/lib/python2.7/site-packages/" >> $USER_SITE/lib/python2.7/site-packages/vtk.pth
export DYLD_LIBRARY_PATH=/Users/<myself>/usr/local/lib/:$DYLD_LIBRARY_PATH
python -c "import vtk; print 'success!'"
ipython
> import vtk
For being able to run the scripts that require VTK, after installation do:
export DYLD_LIBRARY_PATH=/Users/<myself>/usr/local/lib/:$DYLD_LIBRARY_PATH
export PYTHONPATH=/Users/<myself>/usr/local/lib/python2.7/site-packages/:$PYTHONPATH
generate_brain_connectivity_volume_file id1090_timestep.nii nii-volume-2
The Linux installation is either:
In first case, the procedure with virtual environments can be safely followed. In the second case, and if the version of Python is different than the one of the operating system, an additional step outside of the virtual environment should be taken:
Suppose the standalone version of Paraview is located $PARAVIEW_PATH
, and the visualization package
has been cloned to <brain-connectivity-visualization-path>
Then install the package within the Paraview Python environment by typing the following in a terminal
cd <brain-connectivity-visualization-path>
$PARAVIEW_PATH/bin/pvpython setup.py install
The previous commands will install the package inside the Python installation shipped with Paraview. In this case the virtual environment installation is not necessary, as Paraview will be using only the package installed in its own environment. In all cases, the registration of the plugin remains the same.
you may need the virtual environment installation described above only if you need to perform some processing using the utility functions from a regular command line. The package will then have two installation location: the Paraview Python environement and your virtual environment.
This page describes how to use the brain visualization filter inside Paraview:
For the plugin to compute the visualization, the following elements are required:
numpy
file that is generated with a command line tool form
the brain connectivity package, and that is described in the section Connectivity file from Nifti.The parameters exposed to the user by the plugin are shown in the picture below:
The meaning of the parameters are:
resolution
: indicates the edges resolution, ie. the number of intermediate steps a path
connecting two sites is divided into. The higher this number, the smoother the trajectory but also the
heavier the on-screen drawing,edge selection
: a range of edge indices on which the processing will be performed. Any edge falling
outside of this range is ignored in the visualization and the computation. This entry is ignored when
a cluster file is provided.edge file
: the absolute path of the file containing the definition of the topology,show edges
: if checked, the edges will be shownclusters file
: the absolute path to the file containing the results of the clustering.
This file contains a preprocessed version
of the clustering. If not present, a clustering of the selected edges will be computed during the visualization,
which may take some time. For offline computation of the clustering, see the corresponding section.nb_clusters
: indicates the number of desired clusters. This applies on the range of edges that has
been selected or the full range if no selection has been made, and is ignored if the clustering file
is
given.cluster index
: if given, a specific cluster to show on screen. All other clusters are discarded. The
edges that are in the specified cluster are also shown.hierarchy index
: the level of the hierarchy to which the cluster index applies.Note
The hierarchical part is not functional.
Along the Paraview plugin, several functions have been developed. Those utilities have different purposes:
The visualization requires a little preparation step that aims at creating necessary or optional files. Those files are either required for the visualization, or assist the visualization with additional elements.
The only necessary file is the edge file that indicates the plugin the end-points of the different connectivity edges in the 3d volume.
Additionally, it is possible to create:
The clustering of edges is performed with the kmeans algorithm.
The version of this algorithm currently being in use within the plugin is implemented in a naive way in Python, using a distance function that is specific to the needs of the visualization. Accelerated algorithms exist such as the [Elkan] and that involves a lower number of computations and distance evaluations.
The hierarchical version of the kMeans runs the kMeans at each level of the hierarchy, and has also a complexity similar to the kMeans multiplied by the number of hierarchy levels.
Since the clustering may take some time to converge, a script accessible after the installation of the package in a virtual environment is provided.
[Elkan] | Elkan: Using the triangle inequality to accelerate k-means, ICML‘03 |
This module defines the k-means clustering used for creating clusters of edges and summarized information for the set of edges. The implementation is pure python and is slow, hence the name naive.
convergent
(old_means, new_means)¶Returns True
if the two sets of edges are close enough.
This would indicate that the convergence of the k-means clustering has been reached.
create_flip_map
(distances)¶Compares two arrays column-wise and returns an array of integer indices denoting whether the first or second array contains the smaller value.
Parameters: | distances – a matrix of shape (2, k, n) where k is the number of means and n is the number of edges each mean is compared to |
---|---|
Returns: | an array of integer values of 0, 1 |
distances
(edges, means)¶Computes the distance between two set of edges.
The distance is summing the distance between the end points of two edges, irrespective of the orientation of those edges.
The fixed set is called means
. For each edge returns the index of
the closest mean edge, as well as a boolean value marking whether or not
edge_i has been closer to the flipped or original version of the mean in
question.
fetch_edges
(mean_index, edges, means)¶Returns a matrix containing all edges assigned to a mean_index.
init_centroids
(k, edges)¶Returns k centroids by randomly sampling data points out of a given set of edges, as a matrix of shape (k, n).
Parameters: |
|
---|---|
Returns: | a matrix of k data points from the original edges matrix |
Raises: |
|
kmeans
(k, edges, max_iterations=100, verbose=False, callback=None)¶Returns k-means clustering of a set of edges.
This algorithm clusters the set of edges
in k
clusters, using the metric
given by the distance()
function.
Parameters: |
|
---|---|
Returns: | a 2-uples where the first element is a matrix of shape |
label_elements
(distances)¶reorder_edges
(edges, flip_map)¶Combines an array edges
of datapoints and its flipped copy into a
single array with length equal to the length of the original edges
.
Datapoints are chosen based on a boolean array flip_map
.
Parameters: |
|
---|---|
Returns: | a matrix of shape (n, 6) |
update_centroids
(edges, labels, means, flip_map)¶Returns an updated matrix of means. For each mean, sets it to the mean of all points assigned to it.
Parameters: |
|
---|---|
Returns: | a matrix of shape (k, 1, n), containing the updated means |
The set of connection between two different sites of the brain is contained in a edge file file, that makes it convenient to read in the visualization filter in Paraview.
Generating the edge file is done through the command generate_brain_connectivity_edge_file
and requires:
nifti
file that can be read with nibabel
,csv
file encoding the connections between sites in the brain,Warning
This functionality requires the installation of the nibabel
python package. Please make sure you followed
the Installation procedures.
The 3D volume containing all the end-points of the connexels can be generated from the command line in the same manner as for the connectivity file. The generated file is in the VTK format.
Warning
Requires nibabel
(see above) and VTK
(see installation instructions).
The 3D volumetric image may be generated from the command line with the command generate_brain_connectivity_volume_file
.
This call is a wrapper
around the function generate_volume_file()
.
A script for performing the clustering of all the edges is provided. This scripts generates a file that can be given to the visualization filter, which makes the exploration of the different edge clusters much faster.
The command to generate the cluster file is generate_brain_connectivity_cluster_file
. The command
requires:
The output file can be given to the visualization filter in Paraview to avoid expensive computations during the visualization.
Warning
Requires nibabel
(see above) and VTK
(see installation instructions).
Tip
scipy
may be used to speed-up the computation of the k-means if installed.
Provides tools for constructing intermediate files needed for the visualization.
Note
This file is meant to be installed during the installation of the package as a callable script with several commands.
The functions provided here are:
The edge file requires:
generate_cluster_file
(mesh_file, edge_file, number_of_clusters, output_file, max_iterations=100)¶Convenience function for running the clustering on a set of edges
Parameters: |
|
---|
Note
The plugin will not know if the files and parameters are consistent. If you provide a file name that contains the computation of the centroids for a specific edge file, and the edge file is incorrectly given to the plugin, the plugin will be unable to check.
generate_edge_file
(csv_file_path, nifti_edge_file_path, output_file)¶Convenience script for creating an edge file
Parameters: |
|
---|
See also
file_ops.assemble_edges()
generate_edge_volume_file
(nifti_edge_file_path, output_file)¶Convenience script for creating a volume locating all edges end-points
Parameters: |
|
---|
See also
file_ops.assemble_edges()
See also
file_ops.save_points_to_vtk_array()
generate_volume_file
(nifti_volumetric_file_path, output_file)¶Convenience script for creating a VTK compatible volume image file.
Provides tools for generating the XML Paraview plugins.
generatePythonFilterFromFiles
(script_file, output_file, function_name=None)¶Generates an XML plugin file for Paraview from Python source file
Parameters: | function_name – the name of the function containing the plugin entry point. Defaults to RequestData |
---|
generate_plugin_after_install
(output_file)¶Utility for generating the plugin XML file after the package has been successfully installed
This utility uses the plugin.py file as an entry point. This is suitable for running in Paraview in an environment that is not a virtual environment. It requires a Paraview installation of the plugin using pvpython. See the documentation for more details.
generate_plugin_in_virtualenv_after_install
(output_file)¶Utility for generating the plugin XML file after the package has been successfully installed
This utility uses the plugin.py file as an entry point. This is suitable for running in Paraview in an environment that is not a virtual environment. It requires a Paraview installation of the plugin using pvpython. See the documentation for more details.
This package contains a set of python tools for assisting in the visualization of brain connectivity information. The package contains:
This package was developed by Lennart Bramlage and Raffi Enficiaud at the Software Workshop Central Scientific Facility of the Max Planck Institute for Intelligent Systems, in Tübingen, Germany. The details of the computations are given in the following report:
The installation procedures are described on the page Installation.
The usage of the plugin is detailed in the page Paraview visualization filter.
The additional tools are described in the pages Computation utilities and File conversion utilities.
The code contained in this repository is released under the MIT license and copyright is owned by
See the LICENSE.txt file at the root folder of the repository for more information.