Skip to content

Commit

Permalink
Merge pull request #345 from brainglobe/resources
Browse files Browse the repository at this point in the history
Move resources to top level
  • Loading branch information
alessandrofelder committed May 16, 2024
2 parents 04d579a + b8176de commit 004e84d
Show file tree
Hide file tree
Showing 21 changed files with 43 additions and 35 deletions.
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
4 changes: 2 additions & 2 deletions brainrender/_colors.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import random

import matplotlib.cm as cm_mpl
import matplotlib as mpl
import numpy as np
from vedo.colors import colors as vcolors
from vedo.colors import get_color as getColor
Expand All @@ -20,7 +20,7 @@ def map_color(value, name="jet", vmin=None, vmax=None):
if vmax < vmin:
raise ValueError("vmax should be larger than vmin")

mp = cm_mpl.get_cmap(name=name)
mp = mpl.colormaps.get_cmap(name)

value -= vmin
value /= vmax - vmin
Expand Down
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()
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
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.
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
9 changes: 5 additions & 4 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 @@ -368,7 +369,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
14 changes: 7 additions & 7 deletions tests/test_neuron.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from importlib.resources import files
from pathlib import Path

import pytest
from vedo import Sphere
Expand All @@ -7,12 +7,12 @@
from brainrender.actor import Actor
from brainrender.actors import Neuron, make_neurons

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


def test_neuron():
s = Scene(title="BR")
neuron = s.add(
Neuron(files("brainrender").joinpath("resources/neuron1.swc"))
)
neuron = s.add(Neuron(resources_dir / "neuron1.swc"))
s.add(Neuron(Actor(neuron.mesh)))
s.add(Neuron(neuron.mesh))
Neuron(Sphere())
Expand All @@ -21,13 +21,13 @@ def test_neuron():
Neuron(1)

with pytest.raises(FileExistsError):
Neuron(files("brainrender").joinpath("resources/neuronsfsfs.swc"))
Neuron(resources_dir / "neuronsfsfs.swc")
with pytest.raises(NotImplementedError):
Neuron(files("brainrender").joinpath("resources/random_cells.h5"))
Neuron(resources_dir / "random_cells.h5")

del s


def test_make_neurons():
data_path = files("brainrender").joinpath("resources/neuron1.swc")
data_path = resources_dir / "neuron1.swc"
make_neurons(data_path, data_path)
10 changes: 6 additions & 4 deletions tests/test_points.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import random
from importlib.resources import files
from pathlib import Path

import numpy as np
import pytest
Expand All @@ -8,6 +8,8 @@
from brainrender.actor import Actor
from brainrender.actors import Point, Points, PointsDensity

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


def get_n_random_points_in_region(region, N):
"""
Expand All @@ -26,7 +28,7 @@ def get_n_random_points_in_region(region, N):

def test_points_working():
s = Scene(title="BR")
data_path = files("brainrender").joinpath("resources/random_cells.npy")
data_path = resources_dir / "random_cells.npy"
act = Points(np.load(data_path))
act2 = Points(data_path, colors="k")
act3 = Points(data_path, name="test")
Expand Down Expand Up @@ -59,11 +61,11 @@ def test_points_density():
def test_points_error():
with pytest.raises(FileExistsError):
Points(
files("brainrender").joinpath("resources/testsfsdfs.npy"),
resources_dir / "testsfsdfs.npy",
colors="k",
)
with pytest.raises(NotImplementedError):
Points(
files("brainrender").joinpath("resources/random_cells.h5"),
resources_dir / "random_cells.h5",
colors="k",
)
6 changes: 4 additions & 2 deletions tests/test_volume.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
from importlib.resources import files
from pathlib import Path

import numpy as np

from brainrender import Scene
from brainrender.actors import Volume

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


def test_volume():
s = Scene(inset=False, root=True)

data = np.load(files("brainrender").joinpath("resources/volume.npy"))
data = np.load(resources_dir / "volume.npy")
s.add(Volume(data, voxel_size=200, as_surface=False, c="Reds"))
s.add(Volume(data, voxel_size=200, as_surface=True, c="Reds"))
del s

0 comments on commit 004e84d

Please sign in to comment.