Skip to content

Commit

Permalink
Add a new example visualising brainmapper cells in specific brain reg…
Browse files Browse the repository at this point in the history
…ions. (#382)

* update description to reflect new brainmapper widget

* Add new example plotting cells from brainmapper only in specific regions

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update examples/brainmapper.py

Co-authored-by: Igor Tatarnikov <[email protected]>

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Igor Tatarnikov <[email protected]>
  • Loading branch information
3 people authored Sep 12, 2024
1 parent 2723b6d commit 7952179
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 3 deletions.
9 changes: 6 additions & 3 deletions examples/brainmapper.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
"""
Visualise the output from brainmapper. Cells transformed to atlas space can
be found at brainmapper_output/points/points.npy.
Visualise the output from brainmapper.
Cells transformed to atlas space can be found at
brainmapper_output/points/points.npy or exported by the brainmapper
napari widget
For more details on brainmapper, please see:
https://brainglobe.info/documentation/brainglobe-workflows/brainmapper/index.html
- https://brainglobe.info/documentation/brainglobe-workflows/brainmapper/index.html
- https://brainglobe.info/documentation/brainglobe-utils/transform-widget.html
"""

from pathlib import Path
Expand Down
69 changes: 69 additions & 0 deletions examples/brainmapper_regions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
"""
Visualise the output from brainmapper in some specific brain regions.
Cells transformed to atlas space can be found at
brainmapper_output/points/points.npy or exported by the brainmapper napari
widget
For more details on brainmapper, please see:
- https://brainglobe.info/documentation/brainglobe-workflows/brainmapper/index.html
- https://brainglobe.info/documentation/brainglobe-utils/transform-widget.html
"""

from pathlib import Path

from myterial import orange
from rich import print

from brainrender.scene import Scene
from brainrender.actors import Points
from brainrender import settings

import numpy as np

settings.SHADER_STYLE = "plastic"
settings.SHOW_AXES = False

cells_path = Path(__file__).parent.parent / "resources" / "points.npy"

# Define regions of interest (easier to define all at the
# terminal/finest level of the hierarchy)
regions = ["VISp1", "VISp4", "VISp5"]

print(f"[{orange}]Running example: {Path(__file__).name}")


def get_cells_in_regions(scene, cells_path, regions):
cells = np.load(cells_path)
new_cells = []

for cell in cells:
if (
scene.atlas.structure_from_coords(
cell, as_acronym=True, microns=True
)
in regions
):
if cell[0] > 0:
new_cells.append(cell)

new_cells = np.asarray(new_cells)

return new_cells


# Create a brainrender scene
scene = Scene(title=f"brainmapper cells in {regions}", inset=False)

cells_points = get_cells_in_regions(scene, cells_path, regions)

# Create points actor
cells = Points(cells_points, radius=45, colors="palegoldenrod", alpha=0.8)

# Add specific regions
for region in regions:
scene.add_brain_region(region, color="mediumseagreen", alpha=0.2)

# Add cells
scene.add(cells)

scene.render()

0 comments on commit 7952179

Please sign in to comment.