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