Skip to content

Commit

Permalink
Merge branch 'screenshot' of https://github.com/brainglobe/brainrender
Browse files Browse the repository at this point in the history
…into screenshot
  • Loading branch information
adamltyson committed May 20, 2024
2 parents 8201c27 + c351f8a commit 40b5421
Show file tree
Hide file tree
Showing 28 changed files with 111 additions and 139 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/test_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ jobs:
python-version: "3.11"

steps:
- name: Cache atlases
uses: actions/cache@v3
with:
path: ~/.brainglobe
key: brainglobe

- name: Install hdf5 libs for Mac
if: runner.os == 'macOS'
run: brew install hdf5
Expand All @@ -69,6 +75,7 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
secret-codecov-token: ${{ secrets.CODECOV_TOKEN }}
use-xvfb: true

build_sdist_wheels:
name: Build source distribution
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ brainrender/atlas_specific/gene_expression/__pycache__
brainrender/atlas_specific/gene_expression/__pycache__/*
brainrender/atlas_specific/__pycache__

example_brainrender_shot*

workspace.py
workspace.ipynb
brexport.html
Expand Down
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ prune tests
prune examples
prune imgs
prune videos
prune resources

graft brainrender

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,4 @@ year = {2021}

## Contributing

Contributions to brainrender are more than welcome. Please see the [developers guide](https://brainglobe.info/community/developers/index.html). Note that some tests are only run locally, by specifying `--runslow --runlocal` in `pytest`.
Contributions to brainrender are more than welcome. Please see the [developers guide](https://brainglobe.info/community/developers/index.html).
6 changes: 5 additions & 1 deletion examples/__init__.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
from examples import (
add_cells,
add_cylinder,
add_labels,
add_mesh_from_file,
add_cylinder,
animation,
brain_regions,
brainglobe_atlases,
cell_density,
custom_camera,
gene_expression,
line,
neurons,
probe_tracks,
ruler,
screenshot,
settings,
slice,
# streamlines,
user_volumetric_data,
video,
volumetric_data,
web_export,
)
8 changes: 3 additions & 5 deletions examples/add_mesh_from_file.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from pathlib import Path
from importlib.resources import files

from myterial import orange
from rich import print

from brainrender import Scene

obj_file = Path(__file__).parent.parent / "resources" / "CC_134_1_ch1inj.obj"

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

# Create a brainrender scene
Expand All @@ -15,10 +16,7 @@
scene.add_brain_region("SCm", alpha=0.2)

# Add from file
scene.add(
files("brainrender").joinpath("resources/CC_134_1_ch1inj.obj"),
color="tomato",
)
scene.add(obj_file, color="tomato")

# Render!
scene.render()
1 change: 0 additions & 1 deletion examples/brainglobe_atlases.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@

# Create a brainrender scene using the zebrafish atlas
scene = Scene(atlas_name="mpin_zfish_1um", title="zebrafish")

# Render!
scene.render()
4 changes: 3 additions & 1 deletion examples/neurons.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
from brainrender import Scene
from brainrender.actors import Neuron, make_neurons

neuron_file = Path(__file__).parent.parent / "resources" / "neuron1.swc"

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

# Create a brainrender scene
scene = Scene(title="neurons")

# Add a neuron from file
scene.add(Neuron(files("brainrender").joinpath("resources/neuron1.swc")))
scene.add(Neuron(neuron_file))

# Download neurons data with morphapi
mlapi = MouseLightAPI()
Expand Down
8 changes: 4 additions & 4 deletions examples/notebook_workflow.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import vedo\n",
"vedo.settings.default_backend= 'vtk'\n",
Expand All @@ -46,7 +45,8 @@
"popup_scene.add_brain_region('VISp')\n",
"\n",
"popup_scene.render() # press 'Esc' to close"
]
],
"outputs": []
},
{
"cell_type": "markdown",
Expand All @@ -73,7 +73,6 @@
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Set the backend\n",
"import vedo\n",
Expand All @@ -94,7 +93,8 @@
"from vedo import Plotter # <- this will be used to render an embedded scene \n",
"plt = Plotter()\n",
"plt.show(*scene.renderables) # same as vedo.show(*scene.renderables)"
]
],
"outputs": []
}
],
"metadata": {
Expand Down
6 changes: 3 additions & 3 deletions examples/probe_tracks.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from brainrender import Scene
from brainrender.actors import Points

data_path = Path(__file__).parent.parent / "brainrender" / "resources"
resource_path = Path(__file__).parent.parent / "resources"

scene = Scene(title="Silicon Probe Visualization")

Expand All @@ -21,15 +21,15 @@
# part of the probe.
scene.add(
Points(
np.load(data_path / "probe_1_striatum.npy"),
np.load(resource_path / "probe_1_striatum.npy"),
name="probe_1",
colors="darkred",
radius=50,
)
)
scene.add(
Points(
np.load(data_path / "probe_2_RSP.npy"),
np.load(resource_path / "probe_2_RSP.npy"),
name="probe_2",
colors="darkred",
radius=50,
Expand Down
20 changes: 9 additions & 11 deletions examples/user_volumetric_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,21 @@

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

download_path = Path.home() / ".brainglobe" / "brainrender" / "example-data"
filename = "T_AVG_s356tTg.tif"
scene = Scene(atlas_name="mpin_zfish_1um")

retrieved_paths = pooch.retrieve(
# for some reason the list of returned by pooch does not seem to be
# in the same order every time
_ = pooch.retrieve(
url="https://api.mapzebrain.org/media/Lines/brn3cGFP/average_data/T_AVG_s356tTg.zip",
known_hash="54b59146ba08b4d7eea64456bcd67741db4b5395235290044545263f61453a61",
path=Path.home()
/ ".brainglobe"
/ "brainrender"
/ "example-data", # zip will be downloaded here
path=download_path,
progressbar=True,
processor=pooch.Unzip(
extract_dir=""
# path to unzipped dir,
# *relative* to the path set in 'path'
),
processor=pooch.Unzip(extract_dir="."),
)

datafile = Path(retrieved_paths[0]) # [0] is zip file
datafile = download_path / filename


# 1. load the data
Expand Down
5 changes: 3 additions & 2 deletions examples/volumetric_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@
from brainrender.actors import Volume

from pathlib import Path
from importlib.resources import files

from myterial import orange
from rich import print

settings.SHOW_AXES = False
volume_file = Path(__file__).parent.parent / "resources" / "volume.npy"


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

scene = Scene(inset=False)

data = np.load(files("brainrender").joinpath("resources/volume.npy"))
data = np.load(volume_file)
print(data.shape)

# make a volume actor and add
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 0 additions & 14 deletions tests/conftest.py

This file was deleted.

1 change: 0 additions & 1 deletion tests/test_aba_gene.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

# return geapi


# @pytest.mark.xfail
# def test_gene_expression_api(geapi):

Expand Down
31 changes: 4 additions & 27 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,5 @@
import pytest

from brainrender import settings

settings.INTERACTIVE = False


@pytest.mark.slow
@pytest.mark.local
def test_examples():
import examples

examples.add_cells
examples.add_mesh_from_file
examples.animation
examples.brain_regions
examples.brainglobe_atlases
examples.cell_density
examples.custom_camera
examples.gene_expression
examples.neurons
examples.ruler
examples.settings
examples.slice
# examples.streamlines
examples.user_volumetric_data
examples.video
examples.volumetric_data
"""
Run every script in the examples directory
"""
import examples # noqa
33 changes: 16 additions & 17 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from importlib.resources import files
from pathlib import Path

import numpy as np
Expand All @@ -19,6 +18,8 @@
)
from brainrender.atlas_specific import GeneExpressionAPI

resources_dir = Path(__file__).parent.parent / "resources"


def get_n_points_in_region(region, N):
"""
Expand Down Expand Up @@ -109,7 +110,7 @@ def test_add_labels(scene):


def test_add_mesh_from_file(scene):
data_path = files("brainrender").joinpath("resources/CC_134_1_ch1inj.obj")
data_path = resources_dir / "CC_134_1_ch1inj.obj"
scene.add_brain_region("SCm", alpha=0.2)
file_mesh = scene.add(data_path, color="tomato")

Expand Down Expand Up @@ -236,7 +237,7 @@ def test_gene_expression(scene):


def test_neurons(scene, pytestconfig):
data_path = files("brainrender").joinpath("resources/neuron1.swc")
data_path = resources_dir / "neuron1.swc"

neuron = Neuron(data_path)
scene.add(neuron)
Expand Down Expand Up @@ -300,26 +301,24 @@ def test_slice(scene):
assert np.all(ca1_clone.bounds() != ca1.bounds())


@pytest.mark.slow
@pytest.mark.local
def test_user_volumetric_data():
download_path = (
Path.home() / ".brainglobe" / "brainrender" / "example-data"
)
filename = "T_AVG_s356tTg.tif"
scene = Scene(atlas_name="mpin_zfish_1um")
retrieved_paths = pooch.retrieve(

# for some reason the list of returned by pooch does not seem to be
# in the same order every time
_ = pooch.retrieve(
url="https://api.mapzebrain.org/media/Lines/brn3cGFP/average_data/T_AVG_s356tTg.zip",
known_hash="54b59146ba08b4d7eea64456bcd67741db4b5395235290044545263f61453a61",
path=Path.home()
/ ".brainglobe"
/ "brainrender"
/ "example-data", # zip will be downloaded here
path=download_path,
progressbar=True,
processor=pooch.Unzip(
extract_dir=""
# path to unzipped dir,
# *relative* to the path set in 'path'
),
processor=pooch.Unzip(extract_dir="."),
)

datafile = Path(retrieved_paths[0])
datafile = download_path / filename
data = load_any(datafile)
source_space = AnatomicalSpace("ira")
target_space = scene.atlas.space
Expand Down Expand Up @@ -368,7 +367,7 @@ def test_video(scene, pytestconfig):


def test_volumetric_data(scene):
data_path = files("brainrender").joinpath("resources/volume.npy")
data_path = resources_dir / "volume.npy"
data = np.load(data_path)
actor = Volume(
data,
Expand Down
Loading

0 comments on commit 40b5421

Please sign in to comment.