forked from nanshe-org/nanshe_workflow
-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup_tests.py
executable file
·81 lines (62 loc) · 2.12 KB
/
setup_tests.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
#!/usr/bin/env python
import operator
import os
import sys
import numpy
import tifffile
from builtins import range as irange
import xnumpy
import xnumpy.core
import nanshe
if not os.environ.get("TEST_NOTEBOOKS"):
sys.exit(0)
space = numpy.array([110, 120])
radii = numpy.array([6, 6, 6, 6, 7, 6])
magnitudes = numpy.array([15, 16, 15, 17, 16, 16])
points = numpy.array([[30, 24],
[59, 65],
[21, 65],
[80, 78],
[72, 16],
[45, 32]])
bases_indices = [[1, 3, 4], [0, 2], [5]]
linspace_length = 25
masks = nanshe.syn.data.generate_hypersphere_masks(space, points, radii)
images = nanshe.syn.data.generate_gaussian_images(space,
points,
radii/3.0,
magnitudes) * masks
bases_masks = numpy.zeros(
(len(bases_indices),) + masks.shape[1:], dtype=masks.dtype
)
bases_images = numpy.zeros(
(len(bases_indices),) + images.shape[1:], dtype=images.dtype
)
for i, each_basis_indices in enumerate(bases_indices):
bases_masks[i] = masks[list(each_basis_indices)].max(axis=0)
bases_images[i] = images[list(each_basis_indices)].max(axis=0)
image_stack = None
ramp = numpy.concatenate([
numpy.linspace(0, 1, linspace_length),
numpy.linspace(1, 0, linspace_length)
])
image_stack = numpy.zeros(
(bases_images.shape[0] * len(ramp),) + bases_images.shape[1:],
dtype=bases_images.dtype
)
for i in irange(len(bases_images)):
image_stack_slice = slice(i * len(ramp), (i+1) * len(ramp), 1)
image_stack[image_stack_slice] = xnumpy.core.permute_op(
operator.mul,
ramp,
bases_images[i]
)
image_stack *= numpy.iinfo(numpy.uint16).max / image_stack.max()
image_stack = image_stack.astype(numpy.uint16)
image_stack[:, :5, :] = 50000
image_stack[:, -5:, :] = 50000
image_stack[:, :, :5] = 50000
image_stack[:, :, -5:] = 50000
with tifffile.TiffWriter("data.tif", bigtiff=True) as f:
for i in irange(len(image_stack)):
f.save(image_stack[i])