GithubHelp home page GithubHelp logo

brainglobe / brainglobe-heatmap Goto Github PK

View Code? Open in Web Editor NEW
33.0 4.0 10.0 1.7 MB

Rendering anatomical heatmaps with brainrender and matplotlib

Home Page: https://brainglobe.info

License: MIT License

Python 100.00%
atlas brainglobe neuroanatomy visualization

brainglobe-heatmap's Introduction

BrainGlobe

General information, resources, high-level issues and dicussions for the BrainGlobe project. For more details see brainglobe.info. For developer meeting summaries, see the Discussions tab - developer meetings are open to anyone, join the Zulip chat to participate.

brainglobe-heatmap's People

Contributors

adamltyson avatar alessandrofelder avatar carlocastoldi avatar fedeclaudi avatar igortatarnikov avatar k-meech avatar mathieubo avatar pre-commit-ci[bot] avatar ramroomh avatar robertodf avatar vigji avatar willgraham01 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

brainglobe-heatmap's Issues

Human brain plots won't work

Describe the bug
While creating plots for zebrafish and mice brains works perfectly for me, using bg-heatmaps with the "allen_human_500um" is an actual challenge. I only get a thin bar as results, but no plotted brain slice. Can you provide some info on how to use bg-heatmaps with the human bran atlas? Are there any differences?

To Reproduce



values = dict(  # scalar values for each region
    Mo=1,
    PrCG=0.2,
    OccL=0.4,
    FroL=-3,
    ITG=2.6,
    HiF=-4,
)

f = bgh.heatmap(
    values,
    position=10,
    orientation="horizontal",  # 'frontal' or 'sagittal', or 'horizontal' or a tuple (x,y,z)
    thickness=500,
    atlas_name="allen_human_500um",
    format="2D",
    title="human brain heatmap",
).show(xlabel="AP (μm)", ylabel="DV (μm)")

Screenshots

Bildschirmfoto 2023-05-13 um 15 54 48

Rename package to `brainglobe-heatmap(s)`

Hey, thanks for the software, it's awesome!

I just wanted to let you know that on my side, after pip install bgheatmap and a successful installation, I still could not import the package, getting the error:

ModuleNotFoundError: No module named 'bgheatmap'

looking in the site-packages folder of the conda env that I'm using I noticed that the package there is actually named bgheatmaps with the final s. In fact, import bgheatmaps as bgh works great.

Maybe I'm missing something absolutely trivial, but I found it to be a bit misleading


  • win10
  • clean conda environment with just brainrender and allensdk pip-installed

Coordinates output format

Following up on: brainglobe/brainrender#186

cc: @vigji

We should discuss how we want to format the output of the regions' coordinates in the 2D plane.

Currently it's a dict of N x 2 arrays, but with an added twist: if after slicing a region's mesh is left in 2 distinct components (e.g. left/right hemisphere) the coordinates for each ''piece'' are saved separately.

Overall we should think about what format should these exported (csv?), how we deal with distinct components (merge?) and if we want to allow for basic transforms like rotations mirroring etc.

Slice cell density map

Hi,

I have a naive question.

I wonder if I can generate a cell density map using brainrender's function scene.add(PointsDensity()), and then use slicer() to generate a 2D image containing the cell density map at a specific focal plane?

In the end, I want to generate a video showing how the cell density changes across the AP axis. (I am thinking that showing a bunch of focal planes in sequence would work.)

Thank you in advance and look forward to your reply!

Plane parameters specification

Following on discussion from brainglobe/brainrender#186 (comment)
cc @vigji

Currently, the 'slicing' is done by specifying for one plane:

  • position as offset in XYZ relative to the center of mass of root mesh
  • norm vector (x, y, z)
    A second plane is created offset by a user specified ammount in the direction -norm and with norm as -norm.
    These two planes slice the brain regions twice so that you're left with just what's inbetween the planes as a 'slice'.
    Alternative the plane's orientation can be passed by a string that refers to pre-established orientations frontal, sagittal and horizontal.

Now, I think specifying the position of the plane as relative to the center of mass of the root is not very intuitive, perhaps expressing its coordinates as a point in the atlas' reference space is better. The norm is useful because you don't just need to have a plane at a given angle, you need to have a sense of orientation. E.g., if you are slicing through the midline sagittal plane, do you want to keep what's on the left or on the right of the plane? The norm encodes both angles and orientation in an efficient format.
The downside for the norm is that it's not very intuitive: what's norm=(1, 1, 1) in angles?

I can think of three ways to specify the plane's position:

  • center + norm (current)
  • center + 2 angles
  • 3/4 coordinates

I think we should implement all three and let the user pick the one they prefer, it should be some simple geometry to go from one to the other. We should also have 2 useful features:

  1. a 'design' visualization in which the user can see the position of the planes in the brain, without slicing. This should show plane1 and plane2 clearly labelled and maybe the norm vectors as well.
  2. we should export plane metadata information in some easy to use format for records keeping for the users

Separating slicing from plotting

I'm checking out the API of the package, and I see that at the moment a single class heatmap (I'd suggest renaming to Heatmap) is taking care of both the slicing and the plotting. In this way there's no easy way for the user to just use the package to get a plottable slice, and not use the default matplotlib visualisation.

I would suggest conceptually splitting the slicing from the plotting. Maybe there could be a Slicer class, that performs what now is in self.slice() and can be used to just return the coordinates to be plot, and a Heatmap class with the features of the current one?

[Feature] Refactor to have PEP8 class names.

Is your feature request related to a problem? Please describe.
Having some classes (heatmap, plan) start with a lowercase letter, and others with uppercase (Plane, Slicer), makes the code hard to read. Classes should start with uppercase according to PEP 8.

Describe the solution you'd like
Make class heatmap and class plan(heatmap) uppercase, and refactor examples and other code accordingly.

Describe alternatives you've considered

\

Additional context

\

Testing out the examples

I'm testing out the heat map 2D example and out of the box after installation I get this:
Screenshot 2022-01-21 at 14 19 54

It feels like the sorting fails for a portion of the root mask, is this something that happens for you as well?

Can not install bgheatmaps

Dear @FedeClaudi , I can not install bgheatmaps via pip install bgheatmaps.

ERROR: Could not find a version that satisfies the requirement bgheatmaps (from versions: none)                                                                      
ERROR: No matching distribution found for bgheatmaps   

[Feature] Add some smoke tests

Is your feature request related to a problem? Please describe.
There are currently no tests for brainglobe heatmaps.

Describe the solution you'd like
We should start by writing some smoke tests just to ensure e.g. the examples run without crashing.
We could then think about and open issues for more specific tests.

[Feature] Refactor API for plotting multiple 2D slices from the same dataset at different distances.

Is your feature request related to a problem? Please describe.
The newly added Heatmap.plot_subplot() could have a better public facing API. Right now a separate scene is created for each subplot, this can cause a segmentation fault if the reference to each scene isn't kept between the plot_subplot() call and the call to plt.show().

Describe the solution you'd like
We could allow a scene to be initialised with more than one slicing location. The plot() function would then either provide a single plot if only one slicing location is provided or a plot with multiple subplots if multiple positions were passed during initialisation.

This would generate a single plot at position 8000:

scene = bgh.Heatmap(
    data_dict,
    position=8000,
    orientation="frontal",
    thickness=10,
    format="2D",
    cmap="Reds",
    vmin=0,
    vmax=1,
    label_regions=False,
).plot()

This would generate a plot with 6 subplots:

scene = bgh.Heatmap(
    data_dict,
    position=[7500, 8000, 8500, 9000, 9500, 10000],
    orientation="frontal",
    thickness=10,
    format="2D",
    cmap="Reds",
    vmin=0,
    vmax=1,
    label_regions=False,
).plot()

This is just one idea, the position argument already has a few meaning depending on the dimensionality of the visualisation and the specific type passed (tuple vs ndarray).

See discussion in #44.

Slicer crashes at specific planes

Hi!
I'm creating various 2D planes out of a render by slicing a scene and I noticed a bizarre behavior.
Slicing the scene at very specific planes makes the software stall. It does not raise any error but it never completes running.
After trying in a notebook it makes the kernel die.

after a bit of trial and error, I narrowed it down to an example code that on my machine reproduces this behavior consistently. Specifically, it does not like the plane 11147 but it does like 11155, a few micrometers behind. This is just an example, but it happens randomly with very few planes, but it is still annoying when slicing a set of planes obtained with np.linspace since you never know whether the planes you want to slice will work or not.

I solved it by just changing the plane a bit, but I figured maybe it's worth investigating since it does not even throw an error.

import bgheatmaps as bgh
from bgheatmaps.slicer import Slicer


heatmap = bgh.heatmap(
    {'VISp':10,'fiber tracts':5},      # Dummy data
    position=5000,
    orientation="frontal",
    thickness=100,
    title="bugReport",
    cmap='Blues',
    vmin=0,
    vmax=10,
    format="2D",
)
heatmap.scene.close()


blessedPlane = 11155
cursedPlane = 11147

print(f"Slicing blessed plane...")
s = Slicer(blessedPlane, "frontal", 100, heatmap.scene.root)
projected, _ = s.get_structures_slice_coords(
    heatmap.regions_meshes, heatmap.scene.root
)
print("Done")

print(f"Slicing cursed plane...")
s = Slicer(cursedPlane, "frontal", 100, heatmap.scene.root)
projected, _ = s.get_structures_slice_coords(
    heatmap.regions_meshes, heatmap.scene.root
)
print("Done")

I'm on:

  • Vedo 2021.0.5
  • Brainrender 2.0.5.0
  • bgheatmap 0.0.3

KeyError: 'notebookBackend'

When running the example from heatmap_2D.py:
import bgheatmaps as bgh

"""
This example shows how to use visualize a heatmap in 2D
"""

values = dict( # scalar values for each region
TH=1,
RSP=0.2,
AI=0.4,
SS=-3,
MO=2.6,
PVZ=-4,
LZ=-3,
VIS=2,
AUD=0.3,
RHP=-0.2,
STR=0.5,
CB=0.5,
FRP=-1.7,
HIP=3,
PA=-4,
)

f = bgh.heatmap(
values,
position=5000, # when using a named orientation you can pass a single value!
orientation="frontal", # 'frontal' or 'sagittal', or 'horizontal' or a tuple (x,y,z)
title="horizontal view",
vmin=-5,
vmax=3,
format="2D",
).show()

I get the following Error:

File ~/opt/anaconda3/envs/py3.8/lib/python3.8/site-packages/vedo/utils.py:238, in dotdict.getattr(self, k)
237 def getattr(self, k):
--> 238 return self[k]

KeyError: 'notebookBackend'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.