forked from napari/napari
-
Notifications
You must be signed in to change notification settings - Fork 0
/
live_tiffs_generator_.py
57 lines (47 loc) · 1.48 KB
/
live_tiffs_generator_.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
"""
Live tiffs generator
====================
Simulation of microscope acquisition. This code generates time series tiffs in
an output directory (must be supplied by the user).
.. tags:: experimental
"""
import argparse
import os
import sys
import time
import numpy as np
import tifffile
from skimage import data
parser = argparse.ArgumentParser()
parser.add_argument('outdir', help='output directory for tiffs')
parser.add_argument(
'--sleep-time',
help='how long to sleep between volumes, in seconds',
type=float,
default=1.0,
)
parser.add_argument(
'-n', help='total number of volumes', type=int, default=100
)
def main(argv=sys.argv[1:]):
args = parser.parse_args(argv)
outdir = args.outdir
sleep_time = args.sleep_time
n = args.n
fractions = np.linspace(0.05, 0.5, n)
os.makedirs(outdir, exist_ok=True)
for i, f in enumerate(fractions):
# We are using skimage binary_blobs which generate's synthetic binary
# image with several rounded blob-like objects and write them into files.
curr_vol = 255 * data.binary_blobs(
length=128, blob_size_fraction=0.05, n_dim=3, volume_fraction=f
).astype(np.uint8)
tifffile.imwrite(
os.path.join(outdir, f'{i}.tiff'), curr_vol, compress=6
)
time.sleep(sleep_time)
# create a final.log file as an indicator for end of acquisition
with open(os.path.join(outdir, 'final.log'), 'w'):
pass
if __name__ == '__main__':
main()