-
Notifications
You must be signed in to change notification settings - Fork 75
/
user_volumetric_data.py
91 lines (70 loc) · 2.74 KB
/
user_volumetric_data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
"""
This example shows how to render VOLUMETRIC data in brainrender.
It uses data downloaded from: https://fishatlas.neuro.mpg.de/lines/
showing gene expression for this transgenic line (brn3c:GPF): https://zfin.org/ZDB-ALT-050728-2
These data are a 3D image with orientation different from the axes system used by
brainrender, so it has to be loaded and transposed to the correct orientation
This examples shows how to:
- load volumetric data from a TIFF file
- transpose the data with BrainGlobe Space to re-orient it
- extract a mesh from the volumetric data using vedo
- render the data
"""
try:
import imio
except ImportError:
raise ImportError(
'You need imio to run this example: "pip install imio".\nFor more details: https://github.com/brainglobe/imio'
)
from pathlib import Path
import pooch
from bg_space import AnatomicalSpace
from myterial import blue_grey, orange
from rich import print
from vedo import Volume
from brainrender import Scene
print(f"[{orange}]Running example: {Path(__file__).name}")
# specify where the data are saved
retrieved_paths = 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
progressbar=True,
processor=pooch.Unzip(
extract_dir=""
# path to unzipped dir,
# *relative* to the path set in 'path'
),
)
datafile = Path(retrieved_paths[1]) # [0] is zip file
if not datafile.exists():
raise ValueError(
"Before running this example you need to download the data for gene expression of the line brn3c:GFP from https://fishatlas.neuro.mpg.de/lines/"
)
# 1. load the data
print("Loading data")
data = imio.load.load_any(datafile)
# 2. aligned the data to the scene's atlas' axes
print("Transforming data")
scene = Scene(atlas_name="mpin_zfish_1um")
source_space = AnatomicalSpace(
"ira"
) # for more info: https://docs.brainglobe.info/bg-space/usage
target_space = scene.atlas.space
transformed_stack = source_space.map_stack_to(target_space, data)
# 3. create a Volume vedo actor and smooth
print("Creating volume")
vol = Volume(transformed_stack, origin=scene.root.origin()).smooth_median()
# 4. Extract a surface mesh from the volume actor
print("Extracting surface")
mesh = vol.isosurface(value=20).c(blue_grey).decimate().clean()
SHIFT = [-20, 15, 30] # fine tune mesh position
current_position = mesh.pos()
new_position = [SHIFT[i] + current_position[i] for i in range(3)]
mesh.pos(*new_position)
# 5. render
print("Rendering")
scene.add(mesh)
scene.render(zoom=13)