Skip to main content

A package to visualize subcortical brain data in two dimensions.

Project description

Subcortical data visualization in 2D

🙋‍♀️ 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 provided as part of the ENIGMA toolbox; more information on this powerful resource can be found in Larivière, S., et al. Nat Methods (2021).

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 generated by Ye Tian ('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. There is currently no other software available to visualize the Melbourne Subcortex Atlas segmentation in 2D with real data, hence development here (currently detail levels S1 and S2 are available in this package, as described below).

🖥️ Installation

The package can be installed from GitHub in two ways. First, you can install directly with pip:

pip install git+https://github.com/anniegbryant/subcortex_visualization.git#egg=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)

🧠 Usage with different levels of granularity in the Melbourne Subcortex Atlas

We currently offer two levels of detail from the Melbourne Subcortex Atlas: S1 (total of 16 regions) and S2 (total of 32 regions). Here's a schematic overview of the conversion from 3D to 2D for these two segmentations:

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

This package provides three popular subcortical atlases as a starting point: the aseg segmentation into seven regions per hemisphere from the FreeSurfer recon-all pipeline, and two segmentation levels (S1 and S2) from Ye Tian's segmentations as part of the Melbourne Subcortical Atlas. 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 nii2mesh software 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 Ye Tian, Chris Rorden, 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.

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.11.tar.gz (309.3 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.11-py3-none-any.whl (314.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: subcortex_visualization-0.1.11.tar.gz
  • Upload date:
  • Size: 309.3 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.11.tar.gz
Algorithm Hash digest
SHA256 87c99652b313aecf657a0166d5babe4317b50633372c313c18ec8f37bc771567
MD5 e5f443b551b0e3af991ec093fee8a40d
BLAKE2b-256 c3ffccd757b4ffbebad19c1ee920a3c3c429bc2f4489da95d5fba9f83cd47257

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for subcortex_visualization-0.1.11-py3-none-any.whl
Algorithm Hash digest
SHA256 cd32fc628d9582e2749441503353a22182d4cec1faa4a4b005bd7eff92514fd0
MD5 2d6454947fa9fc68d4ff051eac003fb8
BLAKE2b-256 b60688d2a7924c1858536a13c58c6e14bf58729947966866f97219468ef91aad

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