Skip to content

Commit

Permalink
Update brainrender notebook docs (#131)
Browse files Browse the repository at this point in the history
* Update instructions for using brainrender with notebooks

* Add sphinx-copybutton
  • Loading branch information
adamltyson authored Jan 3, 2024
1 parent b95451f commit bf91fd6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 26 deletions.
1 change: 1 addition & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ sphinx-design
sphinx-togglebutton
sphinx-notfound-page
sphinx-sitemap
sphinx-copybutton
ablog>=0.11.0rc2
1 change: 1 addition & 0 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"numpydoc",
"nbsphinx",
"notfound.extension",
"sphinx_copybutton"
]

# Configure the myst parser to enable cool markdown features
Expand Down
63 changes: 37 additions & 26 deletions docs/source/documentation/brainrender/usage/using-notebooks.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,31 @@
1. you can **embed** a window with your rendered scene
2. you can have your scene be rendered in a **pop-up** window.

For an example of how to use `brainrender` with `jupyter` have a look
[here](https://github.com/brainglobe/brainrender/blob/master/examples/notebook_workflow.ipynb).

## Rendering your scene in a separate window

If you want to have your scene be rendered in a new window, then you just need to set this option before your create your `scene`.
If you want your scene to be rendered in a new window, then set this option before you create
your `Scene`.

```python
from vedo import embedWindow
embedWindow(None)
import vedo
vedo.settings.default_backend= 'vtk'
```

After this everything will work exactly the same as usual, and you will have access to all of `brainrender`'s features!
After this everything will work exactly the same as usual, and you will have access to all of `brainrender`'s features.
E.g. to visualise primary visual cortex in the Allen Adult Mouse Brain Atlas:

```python
import vedo
vedo.settings.default_backend= 'vtk'

from brainrender import Scene
popup_scene = Scene(atlas_name='allen_mouse_50um', title='popup')

popup_scene.add_brain_region('VISp')

popup_scene.render() # press 'Esc' to close
```
## Embedding renderings in Jupyter notebooks

:::{hint}
Expand All @@ -28,32 +39,32 @@ If you want to support all of `brainrender`'s features you should **not embed**
Note that this is due to the backend \(`k3d`\) used to embed the renderings not because of `brainrender`.
:::

If you want to embed your scene anyway, you can do that as either a `k3d` panel or a with `itkwidgets` by setting:
If you still need to embed your `Scene` then `brainrender` works slightly differently. E.g. to visualise the
tectum in the larval zebrafish atlas:

```python
embedWindow('k3d') # or 'itkwidgets'
```
# Set the backend
import vedo
vedo.settings.default_backend= 'k3d'

If you chose `k3d` then to rendered your scene:
# Create a brainrender scene
from brainrender import Scene
scene = Scene(atlas_name='mpin_zfish_1um', title='Embedded') # note the title will not actually display
scene.add_brain_region('tectum')

```python
from vedo import show
# Make sure it gets embedded in the window
scene.jupyter = True

# scene.render now will prepare the scene for rendering,
# but it won't render anything yet
# scene.render now will prepare the scene for rendering, but it won't render anything yet
scene.render()

# to actually display the scene we use `vedo`'s `show`
# method to show the scene's actors
show(scene.actors)
# To display the scene we use `vedo`'s `show` method to show the scene's actors
from vedo import Plotter # <- this will be used to render an embedded scene
plt = Plotter()
plt.show(*scene.renderables) # same as vedo.show(*scene.renderables)
```

and with `itkwidgets`:

```python
from ipywidgets import VBox, Button
VBox([show(scene.actors)])
```



:::{hint}
As with all BrainGlobe tools, if you do not have these atlases locally, the first time you run the commands
it may be slow as the data is downloaded.
:::

0 comments on commit bf91fd6

Please sign in to comment.