comparison output_report.py @ 0:1d62de03829d draft

"planemo upload commit c6cd06d44dce1eef9136017289d362f144687dc1"
author gregor.m
date Mon, 23 Nov 2020 13:31:47 +0000
parents
children 4d7f30a7e2f6
comparison
equal deleted inserted replaced
-1:000000000000 0:1d62de03829d
1 ''' Produces plots and a summary html 'headless' '''
2
3 import os
4 import matplotlib
5 # headless plotting and disable latex
6 matplotlib.use('Agg')
7 matplotlib.rcParams['text.usetex'] = False
8 import matplotlib.pyplot as ppl
9
10 import logging
11
12 import spyboat.plotting as spyplot
13
14 logger = logging.getLogger(__name__)
15
16 # figure resolution
17 DPI=250
18
19 def produce_snapshots(input_movie, results, frame, Wkwargs,
20 img_path='.'):
21
22 '''
23 Takes the *input_movie* and the
24 *results* dictionary from spyboat.processing.run_parallel
25 and produces phase, period and amplitude snapshot png's.
26
27 For the period snapshot also the period range is needed,
28 hence the analysis dictionary 'Wkwargs' also gets passed.
29
30 The output files name pattern is:
31 [input, phase, period, amplitude]_frame{frame}.png
32 and the storage location in *img_path*.
33
34 These get picked up by 'create_html'
35 '''
36
37
38 spyplot.input_snapshot(input_movie[frame])
39 fig = ppl.gcf()
40 out_path = os.path.join(img_path, f'input_frame{frame}.png')
41 fig.savefig(out_path, dpi=DPI)
42
43 spyplot.phase_snapshot(results['phase'][frame])
44 fig = ppl.gcf()
45 out_path = os.path.join(img_path, f'phase_frame{frame}.png')
46 fig.savefig(out_path, dpi=DPI)
47
48 spyplot.period_snapshot(results['period'][frame],
49 Wkwargs,
50 time_unit = 'a.u.')
51
52 fig = ppl.gcf()
53 out_path = os.path.join(img_path, f'period_frame{frame}.png')
54 fig.savefig(out_path, dpi=DPI)
55
56 spyplot.amplitude_snapshot(results['amplitude'][frame])
57 fig = ppl.gcf()
58 out_path = os.path.join(img_path, f'amplitude_frame{frame}.png')
59 fig.savefig(out_path, dpi=DPI)
60
61
62 logger.info(f'Produced 4 snapshots for frame {frame}..')
63
64 def produce_distr_plots(results, Wkwargs, img_path='.'):
65
66 '''
67 Output file names are:
68
69 period_distr.png, power_distr.png and phase_distr.png
70 '''
71
72 spyplot.period_distr_dynamics(results['period'], Wkwargs)
73 fig = ppl.gcf()
74 out_path = os.path.join(img_path, f'period_distr.png')
75 fig.savefig(out_path, dpi=DPI)
76
77 spyplot.power_distr_dynamics(results['power'], Wkwargs)
78 fig = ppl.gcf()
79 out_path = os.path.join(img_path, f'power_distr.png')
80 fig.savefig(out_path, dpi=DPI)
81
82 spyplot.phase_coherence_dynamics(results['phase'], Wkwargs)
83 fig = ppl.gcf()
84 out_path = os.path.join(img_path, f'phase_distr.png')
85 fig.savefig(out_path, dpi=DPI)
86
87 logger.info(f'Produced 3 distribution plots..')
88
89
90 def create_html(frame_num, html_fname='OutputReport.html'):
91
92 '''
93 The html generated assumes the respective png's (7 in total)
94 have been created with 'produce_snapshots' and 'produce_distr_plots'
95 and can be found at the cwd (that's how Galaxy works..)
96 '''
97
98 html_string =f'''
99 <html>
100 <title>SpyBOAT Output Report</title>
101 <head>
102 <!-- that doesn't work with galaxy.. -->
103 <!--link rel="stylesheet" href="styles.css"-->
104 <style type="text/css">
105 body{{ margin:10 100; background:whitesmoke; }}
106 /*body{{ margin:10 100; background:darkslategrey; }}*/
107 .center{{
108 display: block;
109 margin-left: auto;
110 margin-right: auto;
111 width: 40%;}}
112
113 /* matplotlib output at 1600x1200 */
114 .distr_gallery {{
115 display: grid;
116 margin: 0 auto;
117 text-align: center;
118 /* border: 1px dashed rgba(4, 4, 4, 0.35); */
119 grid-template-columns: repeat(3,1fr);
120 grid-template-rows: 25vw;
121 grid-gap: 0px;
122 column-gap: 0px
123 }}
124 .distr_gallery__img {{
125 width: 100%;
126 height: 100%;
127 object-fit: contain;
128 }}
129
130
131 /* matplotlib output at 1600x1200 */
132 .snapshot_gallery {{
133 display: grid;
134 margin: 0 auto;
135 border: 1px dashed rgba(4, 4, 4, 0.35);
136 text-align: center;
137 grid-template-columns: repeat(2,1fr);
138 grid-template-rows: repeat(2,20vw);
139 grid-gap: 5px;
140 }}
141 .snapshot_gallery__img {{
142 width: 100%;
143 height: 100%;
144 object-fit: contain;
145 }}
146 </style>
147 </head>
148 <body>
149 <h1 style="text-align:center">SpyBOAT Results Report</h1>
150 <hr style="width:50%">
151 <div class="distr_gallery">
152 <figure class=”distr_gallery__item distr_gallery__item--1">
153 <img src="period_distr.png" alt="Period" class="distr_gallery__img">
154 </figure>
155
156 <figure class=”distr_gallery__item distr_gallery__item--2">
157 <img src="power_distr.png" alt="Power" class="distr_gallery__img">
158 </figure>
159
160 <figure class=”distr_gallery__item distr_gallery__item--3">
161 <img src="phase_distr.png" alt="Phase" class="distr_gallery__img">
162 </figure>
163
164 </div>
165
166 <h2 style="text-align:center"> Snapshots - Frame {frame_num}</h2>
167 <div class="snapshot_gallery">
168 <figure class=”snapshot_gallery__item snapshot_gallery__item--1">
169 <img src="input_frame{frame_num}.png" alt="The Input" class="snapshot_gallery__img">
170 </figure>
171
172 <figure class=”snapshot_gallery__item snapshot_gallery__item--2">
173 <img src="phase_frame{frame_num}.png" alt="Phase" class="snapshot_gallery__img">
174 </figure>
175
176 <figure class=”snapshot_gallery__item snapshot_gallery__item--3">
177 <img src="period_frame{frame_num}.png" alt="Period" class="snapshot_gallery__img">
178 </figure>
179
180 <figure class=”snapshot_gallery__item snapshot_gallery__item--4">
181 <img src="amplitude_frame{frame_num}.png" alt="Amplitude" class="snapshot_gallery__img">
182 </figure>
183 </div>
184
185
186 <!-- *** Section 1 *** --->
187 </body>
188 </html>
189 '''
190
191 with open(html_fname, 'w') as OUT:
192
193 OUT.write(html_string)
194
195 logger.info(f'Created html report')
196 return html_string
197
198 # for local testing
199 # create_html(125)