comparison output_report.py @ 3:4d7f30a7e2f6 draft

"planemo upload commit d070f1ba04a5141a65487f45b29c22767639e44b"
author gregor.m
date Tue, 24 Nov 2020 13:06:26 +0000
parents 1d62de03829d
children a4c6fcf2c456
comparison
equal deleted inserted replaced
2:c59d1373230e 3:4d7f30a7e2f6
37 37
38 spyplot.input_snapshot(input_movie[frame]) 38 spyplot.input_snapshot(input_movie[frame])
39 fig = ppl.gcf() 39 fig = ppl.gcf()
40 out_path = os.path.join(img_path, f'input_frame{frame}.png') 40 out_path = os.path.join(img_path, f'input_frame{frame}.png')
41 fig.savefig(out_path, dpi=DPI) 41 fig.savefig(out_path, dpi=DPI)
42 ppl.close(fig)
42 43
43 spyplot.phase_snapshot(results['phase'][frame]) 44 spyplot.phase_snapshot(results['phase'][frame])
44 fig = ppl.gcf() 45 fig = ppl.gcf()
45 out_path = os.path.join(img_path, f'phase_frame{frame}.png') 46 out_path = os.path.join(img_path, f'phase_frame{frame}.png')
46 fig.savefig(out_path, dpi=DPI) 47 fig.savefig(out_path, dpi=DPI)
48 ppl.close(fig)
47 49
48 spyplot.period_snapshot(results['period'][frame], 50 spyplot.period_snapshot(results['period'][frame],
49 Wkwargs, 51 Wkwargs,
50 time_unit = 'a.u.') 52 time_unit = 'a.u.')
51 53
52 fig = ppl.gcf() 54 fig = ppl.gcf()
53 out_path = os.path.join(img_path, f'period_frame{frame}.png') 55 out_path = os.path.join(img_path, f'period_frame{frame}.png')
54 fig.savefig(out_path, dpi=DPI) 56 fig.savefig(out_path, dpi=DPI)
57 ppl.close(fig)
55 58
56 spyplot.amplitude_snapshot(results['amplitude'][frame]) 59 spyplot.amplitude_snapshot(results['amplitude'][frame])
57 fig = ppl.gcf() 60 fig = ppl.gcf()
58 out_path = os.path.join(img_path, f'amplitude_frame{frame}.png') 61 out_path = os.path.join(img_path, f'amplitude_frame{frame}.png')
59 fig.savefig(out_path, dpi=DPI) 62 fig.savefig(out_path, dpi=DPI)
63 ppl.close(fig)
60 64
61
62 logger.info(f'Produced 4 snapshots for frame {frame}..') 65 logger.info(f'Produced 4 snapshots for frame {frame}..')
63 66
64 def produce_distr_plots(results, Wkwargs, img_path='.'): 67 def produce_distr_plots(results, Wkwargs, img_path='.'):
65 68
66 ''' 69 '''
85 fig.savefig(out_path, dpi=DPI) 88 fig.savefig(out_path, dpi=DPI)
86 89
87 logger.info(f'Produced 3 distribution plots..') 90 logger.info(f'Produced 3 distribution plots..')
88 91
89 92
90 def create_html(frame_num, html_fname='OutputReport.html'): 93 def create_html(frame_nums, html_fname='OutputReport.html'):
91 94
92 ''' 95 '''
93 The html generated assumes the respective png's (7 in total) 96 The html generated assumes the respective png's
94 have been created with 'produce_snapshots' and 'produce_distr_plots' 97 have been created with 'produce_snapshots' and 'produce_distr_plots'
95 and can be found at the cwd (that's how Galaxy works..) 98 and can be found at the cwd (that's how Galaxy works..)
96 ''' 99 '''
97 100
101 # -- create a gallery for every frame in frame_nums --
102
103 galleries = ''
104 for frame_num in frame_nums:
105 new_gal =f'''
106 <div class="FrameSlides">
107 <h3 style="text-align:center; color=#363333"> Frame Nr. {frame_num} </h3>
108
109 <div class="snapshot_gallery">
110
111 <figure class=”snapshot_gallery__item snapshot_gallery__item--1">
112 <img src="input_frame{frame_num}.png" alt="The Input" class="snapshot_gallery__img">
113 </figure>
114
115 <figure class=”snapshot_gallery__item snapshot_gallery__item--2">
116 <img src="phase_frame{frame_num}.png" alt="Phase" class="snapshot_gallery__img">
117 </figure>
118
119 <figure class=”snapshot_gallery__item snapshot_gallery__item--3">
120 <img src="period_frame{frame_num}.png" alt="Period" class="snapshot_gallery__img">
121 </figure>
122
123 <figure class=”snapshot_gallery__item snapshot_gallery__item--4">
124 <img src="amplitude_frame{frame_num}.png" alt="Amplitude" class="snapshot_gallery__img">
125 </figure>
126 </div>
127 </div>
128 '''
129 galleries += new_gal
130
98 html_string =f''' 131 html_string =f'''
99 <html> 132 <html>
100 <title>SpyBOAT Output Report</title> 133 <title>SpyBOAT Output Report</title>
101 <head> 134 <head>
102 <!-- that doesn't work with galaxy.. --> 135 <!-- that doesn't work with galaxy.. -->
103 <!--link rel="stylesheet" href="styles.css"--> 136 <!--link rel="stylesheet" href="styles.css"-->
104 <style type="text/css"> 137 <style type="text/css">
105 body{{ margin:10 100; background:whitesmoke; }} 138 body{{ margin:10 100; background:whitesmoke; }}
106 /*body{{ margin:10 100; background:darkslategrey; }}*/ 139 /*body{{ margin:10 100; background:darkslategrey; }}*/
107 .center{{ 140 .center{{
141 text-align: center;
108 display: block; 142 display: block;
109 margin-left: auto; 143 margin-left: auto;
110 margin-right: auto; 144 margin-right: auto;
111 width: 40%;}} 145 width: 100%;}}
112 146
113 /* matplotlib output at 1600x1200 */ 147 /* matplotlib output at 1600x1200 */
114 .distr_gallery {{ 148 .distr_gallery {{
115 display: grid; 149 display: grid;
116 margin: 0 auto; 150 margin: 0 auto;
117 text-align: center; 151 text-align: center;
118 /* border: 1px dashed rgba(4, 4, 4, 0.35); */ 152 /* border: 1px dashed rgba(4, 4, 4, 0.35); */
119 grid-template-columns: repeat(3,1fr); 153 grid-template-columns: repeat(3,1fr);
120 grid-template-rows: 25vw; 154 grid-template-rows: 20vw;
121 grid-gap: 0px; 155 grid-gap: 0px;
122 column-gap: 0px 156 column-gap: 0px
123 }} 157 }}
124 .distr_gallery__img {{ 158 .distr_gallery__img {{
125 width: 100%; 159 width: 100%;
141 .snapshot_gallery__img {{ 175 .snapshot_gallery__img {{
142 width: 100%; 176 width: 100%;
143 height: 100%; 177 height: 100%;
144 object-fit: contain; 178 object-fit: contain;
145 }} 179 }}
180 .subheader{{
181 text-align:center;
182 font-size: 160%;
183 color:#363333;}}
146 </style> 184 </style>
147 </head> 185 </head>
148 <body> 186 <body>
149 <h1 style="text-align:center">SpyBOAT Results Report</h1> 187 <h1 style="text-align:center; color:#363333">SpyBOAT Results Report</h1>
150 <hr style="width:50%"> 188 <hr style="width:50%">
189 <h1 class="subheader"> Distribution Dynamics </h1>
151 <div class="distr_gallery"> 190 <div class="distr_gallery">
152 <figure class=”distr_gallery__item distr_gallery__item--1"> 191 <figure class=”distr_gallery__item distr_gallery__item--1">
153 <img src="period_distr.png" alt="Period" class="distr_gallery__img"> 192 <img src="period_distr.png" alt="Period" class="distr_gallery__img">
154 </figure> 193 </figure>
155 194
161 <img src="phase_distr.png" alt="Phase" class="distr_gallery__img"> 200 <img src="phase_distr.png" alt="Phase" class="distr_gallery__img">
162 </figure> 201 </figure>
163 202
164 </div> 203 </div>
165 204
166 <h2 style="text-align:center"> Snapshots - Frame {frame_num}</h2> 205 <h1 class="subheader"> Output Movie Snapshots </h1>
167 <div class="snapshot_gallery"> 206
168 <figure class=”snapshot_gallery__item snapshot_gallery__item--1"> 207 <!-- trigger the javascript at the end--->
169 <img src="input_frame{frame_num}.png" alt="The Input" class="snapshot_gallery__img"> 208 <div class="center">
170 </figure> 209 <button class="w3-button" onclick="plusDivs(-1)">&#10094; Prev</button>
171 210 <button class="w3-button" onclick="plusDivs(1)">Next &#10095;</button>
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> 211 </div>
184 212
185 213 <!-- defines all elements of the "FrameSlides" class --->
186 <!-- *** Section 1 *** ---> 214 {galleries}
215 </div>
216
217 <!-- javascript with escaped '{{'--->
218 <script>
219 var slideIndex = 1;
220 showDivs(slideIndex);
221
222 function plusDivs(n) {{
223 showDivs(slideIndex += n);
224 }}
225
226 function showDivs(n) {{
227 var i;
228 var x = document.getElementsByClassName("FrameSlides");
229 if (n > x.length) {{slideIndex = 1}}
230 if (n < 1) {{slideIndex = x.length}} ;
231 for (i = 0; i < x.length; i++) {{
232 x[i].style.display = "none";
233 }}
234 x[slideIndex-1].style.display = "block";
235 }}
236 </script>
187 </body> 237 </body>
188 </html> 238 </html>
189 ''' 239 '''
190 240
191 with open(html_fname, 'w') as OUT: 241 with open(html_fname, 'w') as OUT:
194 244
195 logger.info(f'Created html report') 245 logger.info(f'Created html report')
196 return html_string 246 return html_string
197 247
198 # for local testing 248 # for local testing
199 # create_html(125) 249 # create_html([0,20,40,60,80])