generated from neuroinformatics-unit/HowTo
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adapt
brainrender-napari
tutorial (#225)
* minimal docs update for splitting atlas vis and version management * minimal improvements to brainrender-napari docs * quick and dirty script to autogenerate br-napari tutorial screenshots but good to get into version control as a start * improve download tutorial icon * Apply suggestions from code review Co-authored-by: Adam Tyson <[email protected]> * move download tutorial to end --------- Co-authored-by: Adam Tyson <[email protected]>
- Loading branch information
1 parent
2bca572
commit b0be0a7
Showing
13 changed files
with
157 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+53.6 KB
(140%)
docs/source/tutorials/images/brainrender-napari/add-region-brainrender-napari.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-6.17 KB
(94%)
docs/source/tutorials/images/brainrender-napari/added-brainrender-napari.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+173 KB
(170%)
...tutorials/images/brainrender-napari/additional-reference-brainrender-napari.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+21.8 KB
...rce/tutorials/images/brainrender-napari/atlas-download-progress-in-terminal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+89.5 KB
docs/source/tutorials/images/brainrender-napari/open-manager-widget.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+8.74 KB
(110%)
docs/source/tutorials/images/brainrender-napari/plugin-menu-brainrender-napari.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
+5.98 KB
(100%)
...urce/tutorials/images/brainrender-napari/toggle-ndisplay-brainrender-napari.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Download an atlas through napari | ||
|
||
In this tutorial, you will use `brainrender-napari`'s Atlas Manager widget to download a BrainGlobe atlas through a series of simple clicks. The [`mpin_zfish_1um` zebrafish brain atlas](https://doi.org/10.1016/j.neuron.2019.04.034) will serve as an example. | ||
|
||
:::{note} | ||
You will need `napari` installed on your computer - please follow [`napari`'s installation instructions to do so](https://napari.org/stable/tutorials/fundamentals/installation.html). | ||
::: | ||
|
||
1. Open `napari`. | ||
2. Install `brainrender-napari` by selecting `Plugins > Install/Uninstall plugins` and searching for `brainrender-napari` in the searchbox. Then click on the `Install` button. | ||
3. Open the Atlas Manager widget by selecting `Plugins > Brainrender > Manage atlas versions` in the napari menu bar near the top left of the window. | ||
![brainrender widget](./images/brainrender-napari/open-manager-widget.png) | ||
|
||
**The Atlas Manager widget appears on the right hand side of the window.** | ||
|
||
1. In the widget's `Atlas Manager` section, double-click the row which contains the `mpin_zfish_1um` atlas (you may have to scroll down slightly). The plugin will prompt you to download it (click yes). It may take a long time | ||
(depending on your internet speed) so please be patient. | ||
|
||
:::{note} | ||
We are working on providing a progress indicator in `napari` - in the meantime, you can see download progress in the terminal from which you launched napari. | ||
::: | ||
|
||
![atlas manager dialog](./images/brainrender-napari/atlas-download-progress-in-terminal.png) | ||
|
||
**You have downloaded the zebrafish atlas - you can visualise it in napari by following our [atlas visualisation tutorial](./visualise-atlas-napari).** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import napari | ||
from skimage.io import imsave | ||
from skimage.draw import disk | ||
import pytest | ||
import numpy as np | ||
import shutil | ||
from pathlib import Path | ||
|
||
VIEWPORT_WIDTH = 1400 | ||
VIEWPORT_HEIGHT = 700 | ||
|
||
COMPARE_OR_REGENERATE = "REGENERATE" | ||
RELATIVE_PATH_FOR_SCREENSHOTS = Path("./docs/source/tutorials/images/brainrender-napari/") | ||
|
||
@pytest.fixture | ||
def standard_size_viewer(qtbot): | ||
viewer = napari.Viewer() | ||
viewer.window.resize(VIEWPORT_WIDTH, VIEWPORT_HEIGHT) | ||
yield viewer | ||
viewer.close() | ||
|
||
@pytest.fixture | ||
def take_viewer_screenshot(qtbot): | ||
def _take_viewer_screenshot(viewer, path): | ||
qtbot.wait(2000) # figure out how replace with qtbot.wait_exposed instead | ||
screenshot = viewer.window.screenshot() | ||
# hackily stick in a green point (or later, a cursor) at (x,y) with: | ||
# screenshot[y, x] = [0, 255, 0, 255] | ||
imsave(path, screenshot) | ||
return _take_viewer_screenshot | ||
|
||
@pytest.fixture | ||
def clean_atlas_manager_widget(tmp_path, standard_size_viewer, take_viewer_screenshot): | ||
"""Returns an inner function that | ||
- opens the brainglobe-segmentation widget | ||
- configures the widget so an example project is loaded in atlas space | ||
- saves a screenshot after each of the above steps | ||
- returns the viewer and the widget | ||
""" | ||
def _clean_atlas_manager_widget(): | ||
viewer = standard_size_viewer | ||
_, atlas_manager_widget = viewer.window.add_plugin_dock_widget( | ||
plugin_name="brainrender-napari", | ||
widget_name="Manage atlas versions" | ||
) | ||
atlas_manager_widget.viewer = viewer | ||
viewer.show() | ||
|
||
screenshot_file = RELATIVE_PATH_FOR_SCREENSHOTS / "open-manager-widget.png" | ||
take_viewer_screenshot(viewer, screenshot_file) | ||
return viewer, atlas_manager_widget | ||
|
||
return _clean_atlas_manager_widget | ||
|
||
@pytest.fixture | ||
def clean_brainrender_widget(tmp_path, standard_size_viewer, take_viewer_screenshot): | ||
"""Returns an inner function that | ||
- opens the brainglobe-segmentation widget | ||
- configures the widget so an example project is loaded in atlas space | ||
- saves a screenshot after each of the above steps | ||
- returns the viewer and the widget | ||
""" | ||
def _clean_brainrender_widget(): | ||
viewer = standard_size_viewer | ||
_, brainrender_widget = viewer.window.add_plugin_dock_widget( | ||
plugin_name="brainrender-napari", | ||
widget_name="Brainrender" | ||
) | ||
brainrender_widget.viewer = viewer | ||
viewer.show() | ||
|
||
screenshot_file = RELATIVE_PATH_FOR_SCREENSHOTS / "plugin-menu-brainrender-napari.png" | ||
take_viewer_screenshot(viewer, screenshot_file) | ||
return viewer, brainrender_widget | ||
|
||
return _clean_brainrender_widget | ||
|
||
def test_manager_widget(tmp_path, take_viewer_screenshot, clean_atlas_manager_widget): | ||
viewer, atlas_manager_widget = clean_atlas_manager_widget() | ||
|
||
def test_brainrender_widget(qtbot, tmp_path, take_viewer_screenshot, clean_brainrender_widget): | ||
viewer, brainrender_widget = clean_brainrender_widget() # has already taken basic screenshot | ||
fish_index = brainrender_widget.atlas_viewer_view.model().index(5,0) # fish is 5th row (some rows are hidden but still count!) | ||
brainrender_widget.atlas_viewer_view.setCurrentIndex(fish_index) | ||
brainrender_widget.atlas_viewer_view.doubleClicked.emit(fish_index) | ||
screenshot_file = RELATIVE_PATH_FOR_SCREENSHOTS / "added-brainrender-napari.png" | ||
take_viewer_screenshot(viewer, screenshot_file) | ||
|
||
viewer.dims.ndisplay = 3 | ||
screenshot_file = RELATIVE_PATH_FOR_SCREENSHOTS / "toggle-ndisplay-brainrender-napari.png" | ||
take_viewer_screenshot(viewer, screenshot_file) | ||
|
||
root_index = brainrender_widget.structure_view.model().index(0,0) | ||
forebrain_index = brainrender_widget.structure_view.model().index(0,0, root_index) | ||
telencephalon_index = brainrender_widget.structure_view.model().index(1,0, forebrain_index) | ||
brainrender_widget.structure_view.setCurrentIndex(telencephalon_index) | ||
brainrender_widget.structure_view.doubleClicked.emit(telencephalon_index) | ||
screenshot_file = RELATIVE_PATH_FOR_SCREENSHOTS / "add-region-brainrender-napari.png" | ||
take_viewer_screenshot(viewer, screenshot_file) | ||
|
||
brainrender_widget.atlas_viewer_view.additional_reference_requested.emit("GAD1b") | ||
screenshot_file = RELATIVE_PATH_FOR_SCREENSHOTS / "additional-reference-brainrender-napari.png" | ||
take_viewer_screenshot(viewer, screenshot_file) | ||
|
||
|