Skip to content

Commit

Permalink
Improve "Quickstart" section
Browse files Browse the repository at this point in the history
Co-authored-by: Adam Tyson <[email protected]>
  • Loading branch information
paulbrodersen and adamltyson authored Apr 19, 2024
1 parent fc32195 commit 72723ee
Showing 1 changed file with 34 additions and 14 deletions.
48 changes: 34 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,28 +37,48 @@ If you encounter any issues, please consult our troubleshooting guide [here](htt
## Quickstart

``` python
import random

import numpy as np

from brainrender import Scene
from brainrender.actors import Neuron
from brainrender.actors import Points

def get_n_random_points_in_region(region, N):
"""
Gets N random points inside (or on the surface) of a mesh
"""

region_bounds = region.mesh.bounds()
X = np.random.randint(region_bounds[0], region_bounds[1], size=10000)
Y = np.random.randint(region_bounds[2], region_bounds[3], size=10000)
Z = np.random.randint(region_bounds[4], region_bounds[5], size=10000)
pts = [[x, y, z] for x, y, z in zip(X, Y, Z)]

ipts = region.mesh.inside_points(pts).coordinates
return np.vstack(random.choices(ipts, k=N))


# Display the Allen Brain mouse atlas.
scene = Scene(atlas_name="allen_mouse_25um")
scene = Scene(atlas_name="allen_mouse_25um", title="Cells in primary visual cortex")

# Highlight the cerebral cortex.
scene.add_brain_region("CTX", alpha=0.2, color="green")
# Display a brain region
primary_visual = scene.add_brain_region("VISp", alpha=0.2)

# Add a neuron morphological reconstruction,
# with coordinates pre-registered to the Allen Brain Atlas.
neuron = Neuron("/path/to/neuron/morphology.swc")
scene.add(neuron)
# Get a numpy array with (fake) coordinates of some labelled cells
coordinates = get_n_random_points_in_region(primary_visual, 2000)

# Display the figure.
scene.render()
# Create a Points actor
cells = Points(coordinates)

# Add to scene
scene.add(cells)

# Export to PNG.
scene.screenshot("figure.png")
# Add label to the brain region
scene.add_label(primary_visual, "Primary visual cortex")

# Export to HTML.
scene.screenshot("figure.html")
# Display the figure.
scene.render()

```

Expand Down

0 comments on commit 72723ee

Please sign in to comment.