Skip to main content

Brain regions heatmaps in brainrender

Project description

BG Heatmaps

Rendering heatmaps with brainrender.

DOI

bgheatmap makes it easier to create beautiful heatmaps from anatomical data mapping a scalar values for each brain region (e.g., number of labelled cells in each region) to color and creating beautiful visualizations in 3D and 2D.

installation

pip install bgheatmap

User guide

The starting point for a heatmap visualization is a dict assigning scalar values to a set of brain regions (identified by their acronym). For example:

    regions = dict(  # scalar values for each region
        TH=1,
        RSP=0.2,
        AI=0.4,
        SS=-3,
        MO=2.6,
        ...
    )

bgheatmap creates a brainrender 3D Scene with the given regions colored according the values in the dictionary. Next, to create visualizations like the ones shown above, the three dimensional sceen needs to be sliced to expose the relevant parts. This is done by specifying the position and orientation of a Plane which cuts through the scene.

The orientation is set by the direction of a normal vector specified by the user.

Everything that is on the side opposite where the normal vector will be cut and discarded. To keep a section of the 3D brain, two planes with normal vectors facing in opposite directions are used:

and everything in-between the two planes is kept as a slice.

Slicing plane position

Finding the right position and orientation to the plane can take some tweaking. bgheatmap provides a planner class that makes the process easier by showing the position of the planes and how they intersect with the user provided regions (see image above). In examples/plan.py there's an example showing how to use the planner:

import bgheatmap as bgh


planner = bgh.plan(
    regions,
    position=(
        8000,
        5000,
        5000,
    ),  
    orientation="frontal",  # orientation, or 'sagittal', or 'horizontal' or a tuple (x,y,z)
    thickness=2000,  # thickness of the slices used for rendering (in microns)
)

The position of the center of the plane is given by a set of (x, y, z) coordinates. The orientation can be specified by a string (frontal, sagittal, horizontal) which will result in a standard orthogonal slice, or by a vector (x, y, z) with the orientation along the 3 axes.

Whe using one of the named orientation, you don't need to pass a whole set of (x, y, z) coordinates for the plane center. A single value is sufficient as the other two won't affect the plane position:

f = bgh.heatmap(
    values,
    position=1000,
    orientation="sagittal",  # 'frontal' or 'sagittal', or 'horizontal' or a tuple (x,y,z)
    thickness=1000,
    atlas_name="allen_cord_20um",
    format='2D',
).show()

Also, you can create a slice with a plane centered in the brain by passing position=None:

f = bgh.heatmap(
    values,
    position=None,
    orientation="sagittal",  # 'frontal' or 'sagittal', or 'horizontal' or a tuple (x,y,z)
    thickness=1000,
    atlas_name="mpin_zfish_1um",
    format='2D',
    title='zebra fish heatmap'
).show(xlabel='AP (μm)', ylabel='DV (μm)')

Visualization

Once happy with the position of the slicing planes, creating a visualization is as simple as:

bgh.heatmap(
    values,
    position=(
        8000,
        5000,
        5000,
    ),  
    orientation="horizontal",  # 'frontal' or 'sagittal', or 'horizontal' or a tuple (x,y,z)
    title="horizontal view",
    vmin=-5,
    vmax=3,
    cmap='Red',
    format="2D",
).show()

Here, format spcifies if a 2D plot should be made (using matplotlib) or a 3D rendering instead (using brainrender). The cmap parameter specifies the colormap used and vmin, vmax the color range.

Regions coordinates

You can use bgheatmap to get the coordinates of the 2D 'slices' (in the 2D plane's coordinates system):

regions = ['TH', 'RSP', 'AI', 'SS', 'MO', 'PVZ', 'LZ', 'VIS', 'AUD', 'RHP', 'STR', 'CB', 'FRP', 'HIP', 'PA']


coordinates = bgh.get_plane_coordinates(
    regions,
    position=(
        8000,
        5000,
        5000,
    ),  
    orientation="frontal",  # 'frontal' or 'sagittal', or 'horizontal' or a tuple (x,y,z)
)

Using bgheatmap with other atlases.

bgheatmap uses brainrender which, in turn, uses brainglobe's Atlas API under the hood. That means that all of bgheatmap's functionality is compatible with any of the atlases supported by the atlas API. bgh.heatmap, bgh.planner and bgh.get_plane_coordinates all accept a atlas_name argument, pass the name of the atlas name you'd like to use! For more information see the API's https://docs.brainglobe.info/bg-atlasapi/introduction.

Citing bgheatmap

If you use bgheatmap in your work, please cite it as:

Federico Claudi, & Luigi Petrucco. (2022). brainglobe/bg-heatmaps: (V0.2). Zenodo. https://doi.org/10.5281/zenodo.5891814

Bgheatmap was developed by Federico Claudi and Luigi Petrucco, with the help of Marco Musy (the developer of vedo)

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

bgheatmap-0.0.3.tar.gz (1.4 MB view details)

Uploaded Source

Built Distribution

bgheatmap-0.0.3-py3-none-any.whl (1.4 MB view details)

Uploaded Python 3

File details

Details for the file bgheatmap-0.0.3.tar.gz.

File metadata

  • Download URL: bgheatmap-0.0.3.tar.gz
  • Upload date:
  • Size: 1.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.0

File hashes

Hashes for bgheatmap-0.0.3.tar.gz
Algorithm Hash digest
SHA256 4efcf692a4a269c28269ec12aca76553cbd3e2a30c4ca834c8837ebaa643ec1e
MD5 b3140cb282d9de11cf7e15c7ab3d5e31
BLAKE2b-256 24215cd658a5c68c84e95086ec89f9837a42168515ba1f505de37f13e7156b84

See more details on using hashes here.

Provenance

File details

Details for the file bgheatmap-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: bgheatmap-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.0

File hashes

Hashes for bgheatmap-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 8820230f63149c1b54f01110391bbe047f6cef8fecdf88935244606a6f8b0dbc
MD5 ff21e40df14394cded342e1183c823b9
BLAKE2b-256 eb0e2fe2350d6823ac8155f2dcb29dc145c77e617c080864f5eda695712bd76d

See more details on using hashes here.

Provenance

Supported by

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