annotate spyboat_cli.py @ 5:d5a4180410c4 draft default tip

"planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
author gregor.m
date Sat, 28 Nov 2020 18:50:09 +0000
parents a4c6fcf2c456
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
1 #!/usr/bin/env python
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
2
5
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
3 # Gets interfaced by Galaxy or can be used for bash scripting
3
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
4 import argparse
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
5 import logging
5
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
6 import os
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
7 import sys
3
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
8
5
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
9 import output_report
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
10 import spyboat
3
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
11 from numpy import float32
5
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
12 from skimage import io
3
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
13
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
14 logging.basicConfig(level=logging.INFO, stream=sys.stdout, force=True)
4
a4c6fcf2c456 "planemo upload commit 0584e8878deaf91614c6bb3c0122975300132c25"
gregor.m
parents: 3
diff changeset
15 logger = logging.getLogger('spyboat-cli')
3
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
16
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
17 # ----------command line parameters ---------------
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
18
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
19 parser = argparse.ArgumentParser(description='Process some arguments.')
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
20
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
21 # I/O
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
22 parser.add_argument('--input_path', help="Input movie location", required=True)
5
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
23 parser.add_argument('--phase_out', help='Phase output file name', required=False)
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
24 parser.add_argument('--period_out', help='Period output file name', required=False)
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
25 parser.add_argument('--power_out', help='Power output file name', required=False)
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
26 parser.add_argument('--amplitude_out', help='Amplitude output file name', required=False)
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
27 parser.add_argument('--preprocessed_out', help="Preprocessed-input output file name", required=False)
3
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
28
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
29 # (Optional) Multiprocessing
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
30
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
31 parser.add_argument('--ncpu', help='Number of processors to use',
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
32 required=False, type=int, default=1)
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
33
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
34 # Optional spatial downsampling
5
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
35 parser.add_argument('--rescale_factor', help='Rescale the image by a factor given in %%, None means no rescaling',
3
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
36 required=False, type=int)
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
37 # Optional Gaussian smoothing
5
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
38 parser.add_argument('--gauss_sigma', help='Gaussian smoothing parameter, None means no smoothing', required=False,
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
39 type=float)
3
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
40
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
41 # Wavelet Analysis Parameters
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
42 parser.add_argument('--dt', help='Sampling interval', required=True, type=float)
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
43 parser.add_argument('--Tmin', help='Smallest period', required=True, type=float)
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
44 parser.add_argument('--Tmax', help='Biggest period', required=True, type=float)
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
45 parser.add_argument('--nT', help='Number of periods to scan for', required=True, type=int)
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
46
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
47 parser.add_argument('--Tcutoff', help='Sinc cut-off period, disables detrending if not set', required=False, type=float)
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
48 parser.add_argument('--win_size', help='Sliding window size for amplitude normalization, None means no normalization',
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
49 required=False, type=float)
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
50
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
51 # Optional masking
5
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
52 parser.add_argument('--masking', help="Set to either 'dynamic', 'static' or 'None' which is the default",
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
53 default='None', required=False, type=str)
3
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
54
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
55 parser.add_argument('--mask_frame',
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
56 help="The frame of the input movie to create a static mask from, needs masking set to 'static'",
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
57 required=False, type=int)
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
58
5
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
59 parser.add_argument('--mask_thresh',
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
60 help='The threshold of the mask, all pixels with less than this value get masked (if masking enabled).',
3
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
61 required=False, type=float,
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
62 default=0)
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
63
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
64 # output html report/snapshots
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
65 parser.add_argument('--html_fname', help="Name of the html report.",
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
66 default='OutputReport.html', required=False, type=str)
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
67
5
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
68 parser.add_argument('--report_img_path', help="For the html report, to be set in Galaxy. Without galaxy leave at cwd!",
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
69 default='.', required=False, type=str)
3
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
70
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
71 parser.add_argument('--version', action='version', version='0.1.0')
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
72
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
73 arguments = parser.parse_args()
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
74
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
75 logger.info("Received following arguments:")
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
76 for arg in vars(arguments):
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
77 logger.info(f'{arg} -> {getattr(arguments, arg)}')
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
78
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
79 # ------------Read the input----------------------------------------
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
80 try:
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
81 movie = spyboat.open_tif(arguments.input_path)
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
82 except FileNotFoundError:
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
83 logger.critical(f"Couldn't open {arguments.input_path}, check movie storage directory!")
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
84 sys.exit(1)
4
a4c6fcf2c456 "planemo upload commit 0584e8878deaf91614c6bb3c0122975300132c25"
gregor.m
parents: 3
diff changeset
85 # problems get logged in 'open_tif'
a4c6fcf2c456 "planemo upload commit 0584e8878deaf91614c6bb3c0122975300132c25"
gregor.m
parents: 3
diff changeset
86 if movie is None:
a4c6fcf2c456 "planemo upload commit 0584e8878deaf91614c6bb3c0122975300132c25"
gregor.m
parents: 3
diff changeset
87 sys.exit(1)
3
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
88 # -------- Do (optional) spatial downsampling ---------------------------
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
89
5
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
90 scale_factor = arguments.rescale_factor
3
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
91
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
92 # defaults to None
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
93 if not scale_factor:
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
94 logger.info('No downsampling requested..')
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
95
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
96 elif 0 < scale_factor < 100:
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
97 logger.info(f'Downsampling the movie to {scale_factor:d}% of its original size..')
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
98 movie = spyboat.down_sample(movie, scale_factor / 100)
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
99 else:
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
100 raise ValueError('Scale factor must be between 0 and 100!')
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
101
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
102 # -------- Do (optional) pre-smoothing -------------------------
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
103 # note that downsampling already is a smoothing operation..
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
104
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
105 # check if pre-smoothing requested
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
106 if not arguments.gauss_sigma:
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
107 logger.info('No pre-smoothing requested..')
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
108 else:
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
109 logger.info(f'Pre-smoothing the movie with Gaussians, sigma = {arguments.gauss_sigma:.2f}..')
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
110
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
111 movie = spyboat.gaussian_blur(movie, arguments.gauss_sigma)
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
112
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
113 # ----- Set up Masking before processing ----
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
114
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
115 mask = None
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
116 if arguments.masking == 'static':
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
117 if not arguments.mask_frame:
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
118 logger.critical("Frame number for static masking is missing!")
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
119 sys.exit(1)
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
120
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
121 if (arguments.mask_frame > movie.shape[0]) or (arguments.mask_frame < 0):
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
122 logger.critical(f'Requested frame does not exist, input only has {movie.shape[0]} frames.. exiting')
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
123 sys.exit(1)
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
124
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
125 else:
5
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
126 logger.info(f'Creating static mask from frame {arguments.mask_frame} with threshold {arguments.mask_thresh}')
3
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
127 mask = spyboat.create_static_mask(movie, arguments.mask_frame,
5
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
128 arguments.mask_thresh)
3
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
129 elif arguments.masking == 'dynamic':
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
130 logger.info(f'Creating dynamic mask with threshold {arguments.mask_thresh}')
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
131 mask = spyboat.create_dynamic_mask(movie, arguments.mask_thresh)
5
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
132
3
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
133 else:
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
134 logger.info('No masking requested..')
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
135
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
136 # ------ Retrieve wavelet parameters ---------------------------
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
137
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
138 Wkwargs = {'dt': arguments.dt,
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
139 'Tmin': arguments.Tmin,
5
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
140 'Tmax': arguments.Tmax,
3
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
141 'nT': arguments.nT,
5
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
142 'T_c': arguments.Tcutoff, # defaults to None
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
143 'win_size': arguments.win_size # defaults to None
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
144 }
3
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
145
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
146 # --- start parallel processing ---
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
147
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
148 results = spyboat.run_parallel(movie, arguments.ncpu, **Wkwargs)
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
149
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
150 # --- masking? ---
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
151
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
152 if mask is not None:
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
153 # mask all output movies (in place!)
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
154 for key in results:
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
155 logger.info(f'Masking {key}')
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
156 spyboat.apply_mask(results[key], mask, fill_value=-1)
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
157
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
158 # --- Produce Output HTML Report Figures/png's ---
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
159
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
160 # create the directory, yes we have to do that ourselves :)
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
161 # galaxy then magically renders the html from that directory
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
162 try:
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
163
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
164 if arguments.report_img_path != '.':
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
165 logger.info(f'Creating report directory {arguments.report_img_path}')
5
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
166 os.mkdir(arguments.report_img_path)
3
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
167
5
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
168 # 4 snapshots each
4
a4c6fcf2c456 "planemo upload commit 0584e8878deaf91614c6bb3c0122975300132c25"
gregor.m
parents: 3
diff changeset
169 Nsnap = 7
3
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
170 NFrames = movie.shape[0]
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
171 # show only frames at least one Tmin
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
172 # away from the edge (-effects)
5
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
173 start_frame = int(Wkwargs['Tmin'] / Wkwargs['dt'])
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
174
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
175 if (start_frame > NFrames // 2):
3
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
176 logger.warning("Smallest period already is larger than half the observation time!")
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
177 # set to 0 in this case
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
178 start_frame = 0
5
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
179
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
180 frame_increment = int((NFrames - 2 * start_frame) / Nsnap)
3
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
181 snapshot_frames = range(start_frame, NFrames - start_frame, frame_increment)
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
182
5
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
183 for snapshot_frame in snapshot_frames:
3
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
184 output_report.produce_snapshots(movie, results, snapshot_frame, Wkwargs, img_path=arguments.report_img_path)
5
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
185
3
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
186 output_report.produce_distr_plots(results, Wkwargs, img_path=arguments.report_img_path)
5
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
187
3
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
188 output_report.create_html(snapshot_frames, arguments.html_fname)
5
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
189
3
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
190 except FileExistsError as e:
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
191 logger.critical(f"Could not create html report directory: {repr(e)}")
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
192
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
193 # --- save out result movies ---
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
194
5
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
195 # None means output is filtered from galaxy settings
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
196 if arguments.phase_out is not None:
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
197 # save phase movie
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
198 io.imsave(arguments.phase_out, results['phase'], plugin="tifffile")
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
199 logger.info(f'Written phase to {arguments.phase_out}')
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
200 if arguments.period_out is not None:
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
201 # save period movie
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
202 io.imsave(arguments.period_out, results['period'], plugin="tifffile")
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
203 logger.info(f'Written period to {arguments.period_out}')
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
204 if arguments.power_out is not None:
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
205 # save power movie
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
206 io.imsave(arguments.power_out, results['power'], plugin="tifffile")
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
207 logger.info(f'Written power to {arguments.power_out}')
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
208 if arguments.amplitude_out is not None:
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
209 # save amplitude movie
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
210 io.imsave(arguments.amplitude_out, results['amplitude'], plugin="tifffile")
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
211 logger.info(f'Written amplitude to {arguments.amplitude_out}')
3
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
212
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
213 # save out the probably pre-processed (scaled and blurred) input movie for
4d7f30a7e2f6 "planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
gregor.m
parents:
diff changeset
214 # direct comparison to results and coordinate mapping etc.
5
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
215 if arguments.preprocessed_out is not None:
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
216 io.imsave(arguments.preprocessed_out, movie.astype(float32), plugin='tifffile')
d5a4180410c4 "planemo upload commit 7bc843096b70fe1c8fc149e69d8f87fceac4eb3b"
gregor.m
parents: 4
diff changeset
217 logger.info(f'Written preprocessed to {arguments.preprocessed_out}')