Skip to main content

A package to visualize subcortical brain data in two dimensions.

Project description

Subcortical data visualization in 2D

This python package currently includes the following six subcortical 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.

🙋‍♀️ Motivation

This Python 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 (either nii2mesh or 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 ENIGMA toolbox ('aseg' atlas, left) or a custom-rendered mesh from the Melbourne Subcortex Atlas as published in Tian et al. (2020)https://www.nature.com/articles/s41593-020-00711-6 -- ('S1' granularity level, right).

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 atlases in 2D with real data, hence development here.

🖥️ Installation

The package can be installed from GitHub 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.

👨‍💻 Usage

❗️ Quick start

Running the below code 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 pandas.DataFrame 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 segmentation atlas (default is 'aseg', which is currently the only supported atlas)
  • 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, in mm (default is 1.5)
  • 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')
  • 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 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)

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

This package provides six subcortical 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 either the nii2mesh or surfice_atlas software, both developed by Chris Rorden; 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 development of this project!

❓📧 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-0.1.2.tar.gz (736.4 kB view details)

Uploaded Source

Built Distribution

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

subcortex_visualization-0.1.2-py3-none-any.whl (748.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: subcortex_visualization-0.1.2.tar.gz
  • Upload date:
  • Size: 736.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for subcortex_visualization-0.1.2.tar.gz
Algorithm Hash digest
SHA256 d709601bff635b149aff029bd55834bfca0bab4b6aa5a42694f028478e029a8b
MD5 25564a42118b163c0ca1365ad389a1bf
BLAKE2b-256 a1ec8fcb07d5b5fb3bebf1a5bf506bd2a13bc0a81d94115db2d608221bd8d397

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for subcortex_visualization-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ab9bfb6524deb00ebd8d97fd49aa7c1f4f7667d6c684222d1d89face971fc369
MD5 1592626dc2025095298d582a5ee401a3
BLAKE2b-256 1824db9985e329a4b97f08f6cb3d4de33194901822399eae983fa7ea6e47eeb0

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