-
Notifications
You must be signed in to change notification settings - Fork 312
/
Copy pathexample.py
executable file
·70 lines (63 loc) · 1.95 KB
/
example.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
import argparse
import neuroglancer
import neuroglancer.cli
import numpy as np
def add_example_layers(state):
a = np.zeros((3, 100, 100, 100), dtype=np.uint8)
ix, iy, iz = np.meshgrid(
*[np.linspace(0, 1, n) for n in a.shape[1:]], indexing="ij"
)
a[0, :, :, :] = np.abs(np.sin(4 * (ix + iy))) * 255
a[1, :, :, :] = np.abs(np.sin(4 * (iy + iz))) * 255
a[2, :, :, :] = np.abs(np.sin(4 * (ix + iz))) * 255
b = np.asarray(
np.floor(np.sqrt((ix - 0.5) ** 2 + (iy - 0.5) ** 2 + (iz - 0.5) ** 2) * 10),
dtype=np.uint32,
)
b = np.pad(b, 1, "constant")
dimensions = neuroglancer.CoordinateSpace(
names=["x", "y", "z"], units="nm", scales=[10, 10, 10]
)
state.dimensions = dimensions
state.layers.append(
name="a",
layer=neuroglancer.LocalVolume(
data=a,
dimensions=neuroglancer.CoordinateSpace(
names=["c^", "x", "y", "z"],
units=["", "nm", "nm", "nm"],
scales=[1, 10, 10, 10],
coordinate_arrays=[
neuroglancer.CoordinateArray(labels=["red", "green", "blue"]),
None,
None,
None,
],
),
voxel_offset=(0, 20, 30, 15),
),
shader="""
void main() {
emitRGB(vec3(toNormalized(getDataValue(0)),
toNormalized(getDataValue(1)),
toNormalized(getDataValue(2))));
}
""",
)
state.layers.append(
name="b",
layer=neuroglancer.LocalVolume(
data=b,
dimensions=dimensions,
),
)
return a, b
if __name__ == "__main__":
ap = argparse.ArgumentParser()
neuroglancer.cli.add_server_arguments(ap)
args = ap.parse_args()
neuroglancer.cli.handle_server_arguments(args)
viewer = neuroglancer.Viewer()
with viewer.txn() as s:
a, b = add_example_layers(s)
print(viewer)