Skip to main content

A package to visualize subcortical and cerebellar brain data in two dimensions.

Project description

Subcortical data visualization in 2D

DOI

This package (implemented in Python and R) currently includes the following nine subcortical and cerebellar atlases for data visualization in two-dimensional vector graphics:

More information about these atlases, including the process of rendering the surfaces and tracing the outlines for each, can be found in the atlas_info/ directory and at the project website.

🙋‍♀️ Motivation

This visualization package was created to generate two-dimensional subcortex images in the style of the popular ggseg package in R. We based our vector graphic outlines on the three-dimensional subcortical meshes either (1) provided as part of the ENIGMA toolbox for the aseg atlas or (2) meshes generated in-house using rendering software from Chris Rorden's lab (Surf Ice; check out custom_segmentation_pipeline/ for more information).

The below graphic summarizes the transformation from 3D volumetric meshes to 2D surfaces, starting from the Melbourne Subcortex Atlas as published in Tian et al. (2020) at the 'S1' resolution.

While ggseg offers subcortical plotting with the aseg atlas, it is not currently possible to show data from all seven subcortical regions (accumbens, amygdala, caudate, hippocampus, pallidum, putamen, thalamus) in the same figure. Moreover, there is currently no other software available to visualize any of the other above subcortical, thalamic, or cerebellar atlases in two dimensions with real data, motivating the development of this package.

🖥️ Installation

Python

The Python version of this package can be installed in two ways. First, you can install directly with pip from the PyPI repository:

pip install subcortex-visualization

If you would like to make your own modifications before installing, you can also clone this repository first and then install from your local version:

git clone https://github.com/anniegbryant/subcortex_visualization.git
cd subcortex_visualization
pip install .

This will install the subcortex_visualization package so you have access to the plot_subcortical_data function and associated data.

R

The R version of this package can be installed from GitHub within R using the remotes package as follows:

# if not already installed
install.packages("remotes")

# then install subcortexVisualizationR
remotes::install_github("anniegbryant/subcortex_visualization", subdir = "subcortexVisualizationR"

👨‍💻 Usage

❗️ Quick start

Running the code below (in either python or R) will produce an image of the left subcortex in the aseg atlas (the default), each region colored by its index, with the plasma color scheme:

plot_subcortical_data(hemisphere='L', cmap='plasma', 
                      fill_title = "Subcortical region index")

📚 Tutorial

For a guide that goes through all the functionality and atlases available in this package, we compiled a simple walkthrough tutorial in tutorial.ipynb. To plot real data in the subcortex, your subcortex_data should be a Python pandas.DataFrame or an R data.frame structured as follows (here we've just assigned an integer index to each region):

region value Hemisphere
accumbens 0 L
amygdala 1 L
caudate 2 L
hippocampus 3 L
pallidum 4 L
putamen 5 L
thalamus 6 L

Briefly, all functionality is contained within the plot_subcortical_data function, which takes in the following arguments:

  • subcortex_data: The three-column dataframe in a format as shown above; this is optional, if left out the plot will just color each region by its index
  • atlas: The name of the subcortical, thalamic, or cerebellar segmentation atlas (default is 'aseg', all options listed below)
  • value_column: The name of the column in your subcortex_data to plot, defaults to 'value'
  • line_thickness: How thick the lines around each subcortical region should be drawn
  • line_color: What color the lines around each subcortical region should be (default is 'black')
  • hemisphere: Which hemisphere ('L' or 'R') the subcortex_data is from; can also be 'both' (default is 'L')
  • fill_title: Name to add to legend (default is 'values')
  • cmap: name of colormap (e.g., 'plasma' or 'viridis') or a matplotlib.colors.Colormap (default is 'viridis'); for R, this could be a vector of discrete colors or a color palette generating function
  • vmin: Min fill value; this is optional, and you would only want to use this to manually constrain the fill range to match another figure
  • vmax: Max fill value; this is optional, and you would only want to use this to manually constrain the fill range to match another figure
  • midpoint: Midpoint value to enforce for fill range; this is optional

Here's an example in Python for plotting both hemispheres, with data randomly sampled from a normal distribution, setting a color range from blue (low) to red (high) with white at the center (midpoint=0):

import matplotlib.colors as mcolors
import numpy as np

np.random.seed(127)

example_continuous_data_L = pd.DataFrame({"region": ["accumbens", "amygdala", "caudate", "hippocampus", "pallidum", "putamen", "thalamus"],
                                          "value": np.random.normal(0, 1, 7)}).assign(Hemisphere = "L")
example_continuous_data_R = pd.DataFrame({"region": ["accumbens", "amygdala", "caudate", "hippocampus", "pallidum", "putamen", "thalamus"],
                                            "value": np.random.normal(0, 1, 7)}).assign(Hemisphere = "R")
example_continuous_data = pd.concat([example_continuous_data_L, example_continuous_data_R], axis=0)

white_blue_red_cmap = mcolors.LinearSegmentedColormap.from_list("BlueWhiteRed", ["blue", "white", "red"])

plot_subcortical_data(subcortex_data=example_continuous_data, atlas='aseg',
                      hemisphere='both', fill_title = "Normal distribution sample",
                      cmap=white_blue_red_cmap, midpoint=0)

Available atlases

The following nine subcortical atlases are currently supported with more information at the project website:

💡 Want to generate your own mesh and/or parcellation?

This package provides nine subcortical, thalamic, and cerebellar atlases as a starting point. The workflow can readily be extended to your favorite segmentation atlas, though! We have a dedicated folder for a custom segmentation pipeline that will walk you through the two key steps:

  1. Rendering a series of triangulated surface meshes from your parcellation atlas (starting from a .nii.gz volume), using the surfice_atlas software, both developed by Chris Rorden's lab; and
  2. Tracing the outline of each region in the rendered mesh in vector graphic editing software (we use Inkscape in the tutorial as a powerful and free option), to yield a two-dimensional image of your atlas in scalable vector graphic (.svg) format.

Check out the walkthrough in the custom_segmentation_pipeline/ folder for more information on how to render your own volumetric segmentation with an interactive mesh and convert to a two-dimensional vector graphic that can be integrated with this package.

🙏 Acknowledgments

Thank you very much to Chris Rorden, Ye Tian, and Sid Chopra for their suggestions and continued development of open tools for neuroimaging visualization that enabled the development of this project!

We're also very grateful for ongoing contributions from members of the GitHub community:

Contributors

🔗 Citing this package

If you use this package in a scientific publication, blog post, etc., please cite the corresponding Zenodo release as follows:

Annie G. Bryant. (2025). anniegbryant/subcortex_visualization: Initial Zenodo release (initial_release). Zenodo. https://doi.org/10.5281/zenodo.15385316

❓📧 Questions, comments, or suggestions always welcome!

Please feel free to ask questions, report bugs, or share suggestions by creating an issue or by emailing me (Annie) at (anniegbryant@gmail.com) 😊

As an open-source tool, pull requests are always welcome from the community, too. If you create your own custom vector graphic for your segmentation atlas of choice, feel free to create a pull request to incorporate and be acknowledged.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

subcortex_visualization-1.2.0.tar.gz (1.2 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

subcortex_visualization-1.2.0-py3-none-any.whl (1.3 MB view details)

Uploaded Python 3

File details

Details for the file subcortex_visualization-1.2.0.tar.gz.

File metadata

  • Download URL: subcortex_visualization-1.2.0.tar.gz
  • Upload date:
  • Size: 1.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.21

File hashes

Hashes for subcortex_visualization-1.2.0.tar.gz
Algorithm Hash digest
SHA256 06e14b51652a4ec2fb666eb7f546f452d4c65ec31843ff366dfe6691c20f0c3b
MD5 27bd063a3389ee3fae95d96b3474d0a1
BLAKE2b-256 bc9fb03f5c23b6f0944c7a1460625b86fe89ddaa0414734d0ec96bd2e66f317d

See more details on using hashes here.

File details

Details for the file subcortex_visualization-1.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for subcortex_visualization-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e49ff801900320a6f704cbe65e7cf22fd1a7b96544167d86da8e7c15b9ba9f4c
MD5 ca20e3160fb45725e6463d1736257cf7
BLAKE2b-256 bf40dc5521e2139b460a4b02b0718c99b573a365b90fd9d37d93580b927438a9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page