-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.py
More file actions
executable file
·68 lines (60 loc) · 2.08 KB
/
example.py
File metadata and controls
executable file
·68 lines (60 loc) · 2.08 KB
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
from __future__ import print_function
import argparse
import sys
import numpy as np
import neuroglancer
import neuroglancer.cli
from syconn.analysis.backend import SyConnBackend
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.cast[np.uint32](np.floor(np.sqrt((ix - 0.5)**2 + (iy - 0.5)**2 + (iz - 0.5)**2) * 10))
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(sys.argv[1:])
# TODO delete this print
print(args.host)
print(args.port)
neuroglancer.cli.handle_server_arguments(args)
viewer = neuroglancer.Viewer()
with viewer.txn() as s:
a, b = add_example_layers(s)
print(viewer)