Skip to main content

yet another brain plot

Project description

yabplot: yet another brain plot

logo

PyPI version Docs Tests DOI

yabplot is a Python library for creating beautiful, publication-quality 3D brain visualizations. it supports plotting cortical regions (+ vertexwise), subcortical structures, and white matter bundles.

the idea is simple. while there are already amazing visualization tools available, they often focus on specific domains—using one tool for white matter tracts and another for cortical surfaces inevitably leads to inconsistent styles. i wanted a unified, simple-to-use tool that enables me (and hopefully others) to perform most brain visualizations in a single place. recognizing that neuroscience evolves daily, i designed yabplot to be modular: it supports standard pre-packaged atlases out of the box, but easily accepts any custom parcellation or tractography dataset you might need.

features

  • pre-existing atlases: access many commonly used atlases (schaefer2018, brainnetome, aparc, aseg, musus100, xtract, etc) on demand.
  • vertexwise plotting: project volume (.nii) to cortical surface and plot.
  • simple to use: plug-n-play functions for cortex, subcortex, and tracts with a unified API.
  • custom atlases: easily use your own parcellations, segmentations (.nii/.gii), or tractograms (.trk).
  • flexible inputs: accepts data as dictionaries (for partial mapping) or arrays (for strict mapping).

installation

uv add yabplot # to install
uv sync --upgrade-package yabplot # to update

or

pip install yabplot # to install
pip install yabplot --upgrade # to update

dependencies: python 3.11 with ipywidgets, nibabel, pandas, pooch, pyvista, scikit-image, trame, trame-vtk, trame-vuetify

(Connectome Workbench (wb_command) is a requirement to create custom cortical atlases unless you plan to only use pre-loaded atlases; see more in docs)

quick start

please refer to the documentation for more comprehensive guides.

import yabplot as yab
import numpy as np

# check that you have the latest version
print(yab.__version__)

# see available atlases and brain meshes
print(yab.get_available_resources())

# see the region names for a specific atlas
print(yab.get_atlas_regions(atlas='aseg', category='subcortical'))

# cortical surface regions
atlas = 'aparc'
dmap1 = {'L_lateraloccipital': 0.265, 'L_postcentral': 0.086, ...}
yab.plot_cortical(data=dmap1, atlas=atlas, vminmax=[-0.1, 0.3], 
                  bmesh='midthickness', views=['left_lateral', 'left_medial'],
                  figsize=(600, 300), cmap='viridis')

# subcortical structures
atlas = 'aseg'
regs = yab.get_atlas_regions(atlas=atlas, category='subcortical')
data = np.arange(1, len(regs)+1)
yab.plot_subcortical(data=data, atlas=atlas, vminmax=[2, 14], 
                     views=['left_lateral', 'superior', 'right_lateral'], 
                     bmesh_alpha=0.1, figsize=(600, 300), cmap='viridis')

# vertex-wise surface
threshold = 4
b_lh_path, b_rh_path = yab.data.get_surface_paths('midthickness', 'bmesh')
lh_data, rh_data = yab.project_vol2surf('path/to/yourdata.nii.gz', bmesh='midthickness')
lh_data = np.where(lh_data > threshold, lh_data, np.nan)
rh_data = np.where(rh_data > threshold, rh_data, np.nan)
lh_mesh, rh_mesh = yab.load_vertexwise_mesh(b_lh_path, b_rh_path, lh_data, rh_data)
yab.plot_vertexwise(lh_mesh, rh_mesh, cmap='viridis', vminmax=[-4, 9], 
                    views=['left_lateral', 'left_medial'], figsize=(600, 300))

# white matter bundles
atlas = 'xtract_tiny'
regs = yab.get_atlas_regions(atlas=atlas, category='tracts')
data = {reg: np.sin(i) for i, reg in enumerate(regs)}
yab.plot_tracts(data=data, atlas=atlas, style='matte',
                views=['left_lateral', 'anterior', 'superior'], bmesh='pial',
                bmesh_alpha=0.1, figsize=(1600, 800), cmap='viridis')

examples

acknowledgements

yabplot relies on the extensive work of the neuroimaging community. if you use these atlases in your work, please cite the original authors. if you use this package for any scientific work, please cite the DOI (see more info on Zenodo).

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

yabplot-0.4.0.tar.gz (34.2 kB view details)

Uploaded Source

Built Distribution

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

yabplot-0.4.0-py3-none-any.whl (34.7 kB view details)

Uploaded Python 3

File details

Details for the file yabplot-0.4.0.tar.gz.

File metadata

  • Download URL: yabplot-0.4.0.tar.gz
  • Upload date:
  • Size: 34.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for yabplot-0.4.0.tar.gz
Algorithm Hash digest
SHA256 c58dd8ee62c61befa9f4e853df147ed0b41f29946cdd827d0de418f1e795eb6c
MD5 8b117b301526e0105d6d7899201a3f52
BLAKE2b-256 c9aa88d1f7dbfd889ed9db5742a0175656933f06ac02d790eb44d7844987d759

See more details on using hashes here.

Provenance

The following attestation bundles were made for yabplot-0.4.0.tar.gz:

Publisher: publish.yml on teanijarv/yabplot

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file yabplot-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: yabplot-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 34.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for yabplot-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3842ebe0493031baba23fa7bba181ed53193d758e095d81d76301a8935dc134c
MD5 8555752770f9aac634fe6cd37f18bba0
BLAKE2b-256 430a146a08a6b527644c6a5c30a21fdabd547b0abb402abcc5696f605e41d666

See more details on using hashes here.

Provenance

The following attestation bundles were made for yabplot-0.4.0-py3-none-any.whl:

Publisher: publish.yml on teanijarv/yabplot

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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