Mercurial > repos > gregor.m > spyboat
comparison output_report.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 |
comparison
equal
deleted
inserted
replaced
| 4:a4c6fcf2c456 | 5:d5a4180410c4 |
|---|---|
| 1 ''' Produces plots and a summary html 'headless' ''' | 1 """ Produces plots and a summary html 'headless' """ |
| 2 | 2 import logging |
| 3 import os | 3 import os |
| 4 | |
| 4 import matplotlib | 5 import matplotlib |
| 5 # headless plotting and disable latex | |
| 6 matplotlib.use('Agg') | |
| 7 matplotlib.rcParams['text.usetex'] = False | |
| 8 import matplotlib.pyplot as ppl | 6 import matplotlib.pyplot as ppl |
| 9 | |
| 10 import logging | |
| 11 | |
| 12 import spyboat.plotting as spyplot | 7 import spyboat.plotting as spyplot |
| 13 | 8 |
| 9 ppl.switch_backend('Agg') | |
| 10 matplotlib.rcParams["text.usetex"] = False | |
| 14 logger = logging.getLogger(__name__) | 11 logger = logging.getLogger(__name__) |
| 15 | 12 |
| 16 # figure resolution | 13 # figure resolution |
| 17 DPI=250 | 14 DPI = 250 |
| 18 | 15 |
| 19 def produce_snapshots(input_movie, results, frame, Wkwargs, | 16 |
| 20 img_path='.'): | 17 def produce_snapshots(input_movie, results, frame, Wkwargs, img_path="."): |
| 21 | 18 """ |
| 22 ''' | 19 Takes the *input_movie* and the *results* dictionary |
| 23 Takes the *input_movie* and the | 20 from spyboat.processing.run_parallel and produces phase, |
| 24 *results* dictionary from spyboat.processing.run_parallel | 21 period and amplitude snapshot png's. |
| 25 and produces phase, period and amplitude snapshot png's. | |
| 26 | 22 |
| 27 For the period snapshot also the period range is needed, | 23 For the period snapshot also the period range is needed, |
| 28 hence the analysis dictionary 'Wkwargs' also gets passed. | 24 hence the analysis dictionary 'Wkwargs' also gets passed. |
| 29 | 25 |
| 30 The output files name pattern is: | 26 The output files name pattern is: |
| 31 [input, phase, period, amplitude]_frame{frame}.png | 27 [input, phase, period, amplitude]_frame{frame}.png |
| 32 and the storage location in *img_path*. | 28 and the storage location in *img_path*. |
| 33 | 29 |
| 34 These get picked up by 'create_html' | 30 These get picked up by 'create_html' |
| 35 ''' | 31 """ |
| 36 | |
| 37 | 32 |
| 38 spyplot.input_snapshot(input_movie[frame]) | 33 spyplot.input_snapshot(input_movie[frame]) |
| 39 fig = ppl.gcf() | 34 fig = ppl.gcf() |
| 40 out_path = os.path.join(img_path, f'input_frame{frame}.png') | 35 out_path = os.path.join(img_path, f"input_frame{frame}.png") |
| 41 fig.savefig(out_path, dpi=DPI) | 36 fig.savefig(out_path, dpi=DPI) |
| 42 ppl.close(fig) | 37 ppl.close(fig) |
| 43 | 38 |
| 44 spyplot.phase_snapshot(results['phase'][frame]) | 39 spyplot.phase_snapshot(results["phase"][frame]) |
| 45 fig = ppl.gcf() | 40 fig = ppl.gcf() |
| 46 out_path = os.path.join(img_path, f'phase_frame{frame}.png') | 41 out_path = os.path.join(img_path, f"phase_frame{frame}.png") |
| 47 fig.savefig(out_path, dpi=DPI) | 42 fig.savefig(out_path, dpi=DPI) |
| 48 ppl.close(fig) | 43 ppl.close(fig) |
| 49 | 44 |
| 50 spyplot.period_snapshot(results['period'][frame], | 45 spyplot.period_snapshot( |
| 51 Wkwargs['Tmin'],Wkwargs['Tmax'], | 46 results["period"][frame], Wkwargs["Tmin"], |
| 52 time_unit = 'a.u.') | 47 Wkwargs["Tmax"], time_unit="a.u." |
| 53 | 48 ) |
| 54 fig = ppl.gcf() | 49 |
| 55 out_path = os.path.join(img_path, f'period_frame{frame}.png') | 50 fig = ppl.gcf() |
| 56 fig.savefig(out_path, dpi=DPI) | 51 out_path = os.path.join(img_path, f"period_frame{frame}.png") |
| 57 ppl.close(fig) | 52 fig.savefig(out_path, dpi=DPI) |
| 58 | 53 ppl.close(fig) |
| 59 spyplot.amplitude_snapshot(results['amplitude'][frame]) | 54 |
| 60 fig = ppl.gcf() | 55 spyplot.amplitude_snapshot(results["amplitude"][frame]) |
| 61 out_path = os.path.join(img_path, f'amplitude_frame{frame}.png') | 56 fig = ppl.gcf() |
| 62 fig.savefig(out_path, dpi=DPI) | 57 out_path = os.path.join(img_path, f"amplitude_frame{frame}.png") |
| 63 ppl.close(fig) | 58 fig.savefig(out_path, dpi=DPI) |
| 64 | 59 ppl.close(fig) |
| 65 logger.info(f'Produced 4 snapshots for frame {frame}..') | 60 |
| 66 | 61 logger.info(f"Produced 4 snapshots for frame {frame}..") |
| 67 def produce_distr_plots(results, Wkwargs, img_path='.'): | 62 |
| 68 | 63 |
| 69 ''' | 64 def produce_distr_plots(results, Wkwargs, img_path="."): |
| 65 """ | |
| 70 Output file names are: | 66 Output file names are: |
| 71 | 67 |
| 72 period_distr.png, power_distr.png and phase_distr.png | 68 period_distr.png, power_distr.png and phase_distr.png |
| 73 ''' | 69 """ |
| 74 | 70 |
| 75 spyplot.period_distr_dynamics(results['period'], Wkwargs) | 71 spyplot.period_distr_dynamics(results["period"], Wkwargs) |
| 76 fig = ppl.gcf() | 72 fig = ppl.gcf() |
| 77 out_path = os.path.join(img_path, f'period_distr.png') | 73 out_path = os.path.join(img_path, "period_distr.png") |
| 78 fig.savefig(out_path, dpi=DPI) | 74 fig.savefig(out_path, dpi=DPI) |
| 79 | 75 |
| 80 spyplot.power_distr_dynamics(results['power'], Wkwargs) | 76 spyplot.power_distr_dynamics(results["power"], Wkwargs) |
| 81 fig = ppl.gcf() | 77 fig = ppl.gcf() |
| 82 out_path = os.path.join(img_path, f'power_distr.png') | 78 out_path = os.path.join(img_path, "power_distr.png") |
| 83 fig.savefig(out_path, dpi=DPI) | 79 fig.savefig(out_path, dpi=DPI) |
| 84 | 80 |
| 85 spyplot.phase_coherence_dynamics(results['phase'], Wkwargs) | 81 spyplot.phase_coherence_dynamics(results["phase"], Wkwargs) |
| 86 fig = ppl.gcf() | 82 fig = ppl.gcf() |
| 87 out_path = os.path.join(img_path, f'phase_distr.png') | 83 out_path = os.path.join(img_path, "phase_distr.png") |
| 88 fig.savefig(out_path, dpi=DPI) | 84 fig.savefig(out_path, dpi=DPI) |
| 89 | 85 |
| 90 logger.info(f'Produced 3 distribution plots..') | 86 logger.info("Produced 3 distribution plots..") |
| 91 | 87 |
| 92 | 88 |
| 93 def create_html(frame_nums, html_fname='OutputReport.html'): | 89 def create_html(frame_nums, html_fname="OutputReport.html"): |
| 94 | 90 """ |
| 95 ''' | 91 The html generated assumes the respective png's |
| 96 The html generated assumes the respective png's | |
| 97 have been created with 'produce_snapshots' and 'produce_distr_plots' | 92 have been created with 'produce_snapshots' and 'produce_distr_plots' |
| 98 and can be found at the cwd (that's how Galaxy works..) | 93 and can be found at the cwd (that's how Galaxy works..) |
| 99 ''' | 94 """ |
| 100 | 95 |
| 101 # -- create a gallery for every frame in frame_nums -- | 96 # -- create a gallery for every frame in frame_nums -- |
| 102 | 97 |
| 103 galleries = '' | 98 galleries = "" |
| 104 for frame_num in frame_nums: | 99 for frame_num in frame_nums: |
| 105 new_gal =f''' | 100 new_gal = f""" |
| 106 <div class="FrameSlides"> | 101 <div class="FrameSlides"> |
| 107 <h3 style="text-align:center; color=#363333"> Frame Nr. {frame_num} </h3> | 102 <h3 style="text-align:center; color=#363333"> |
| 103 Frame Nr. {frame_num} </h3> | |
| 108 | 104 |
| 109 <div class="snapshot_gallery"> | 105 <div class="snapshot_gallery"> |
| 110 | 106 |
| 111 <figure class=”snapshot_gallery__item snapshot_gallery__item--1"> | 107 <figure class=”snapshot_gallery__item |
| 112 <img src="input_frame{frame_num}.png" alt="The Input" class="snapshot_gallery__img"> | 108 snapshot_gallery__item--1"> |
| 113 </figure> | 109 <img src="input_frame{frame_num}.png" alt="The Input" |
| 114 | 110 class="snapshot_gallery__img"> |
| 115 <figure class=”snapshot_gallery__item snapshot_gallery__item--2"> | 111 </figure> |
| 116 <img src="phase_frame{frame_num}.png" alt="Phase" class="snapshot_gallery__img"> | 112 |
| 117 </figure> | 113 <figure class=”snapshot_gallery__item |
| 118 | 114 snapshot_gallery__item--2"> |
| 119 <figure class=”snapshot_gallery__item snapshot_gallery__item--3"> | 115 <img src="phase_frame{frame_num}.png" alt="Phase" |
| 120 <img src="period_frame{frame_num}.png" alt="Period" class="snapshot_gallery__img"> | 116 class="snapshot_gallery__img"> |
| 121 </figure> | 117 </figure> |
| 122 | 118 |
| 123 <figure class=”snapshot_gallery__item snapshot_gallery__item--4"> | 119 <figure class=”snapshot_gallery__item |
| 124 <img src="amplitude_frame{frame_num}.png" alt="Amplitude" class="snapshot_gallery__img"> | 120 snapshot_gallery__item--3"> |
| 121 <img src="period_frame{frame_num}.png" | |
| 122 alt="Period" class="snapshot_gallery__img"> | |
| 123 </figure> | |
| 124 | |
| 125 <figure class=”snapshot_gallery__item | |
| 126 snapshot_gallery__item--4"> | |
| 127 <img src="amplitude_frame{frame_num}.png" | |
| 128 alt="Amplitude" class="snapshot_gallery__img"> | |
| 125 </figure> | 129 </figure> |
| 126 </div> | 130 </div> |
| 127 </div> | 131 </div> |
| 128 ''' | 132 """ |
| 129 galleries += new_gal | 133 galleries += new_gal |
| 130 | 134 |
| 131 html_string =f''' | 135 html_string = f""" |
| 132 <html> | 136 <html> |
| 133 <!-- this file got automatically created by 'output_report.py' --> | 137 <!-- this file got automatically created by 'output_report.py' --> |
| 134 <title>SpyBOAT Output Report</title> | 138 <title>SpyBOAT Output Report</title> |
| 135 <head> | 139 <head> |
| 136 <!-- that doesn't work with galaxy.. --> | 140 <!-- that doesn't work with galaxy.. --> |
| 150 display: grid; | 154 display: grid; |
| 151 margin: 0 auto; | 155 margin: 0 auto; |
| 152 text-align: center; | 156 text-align: center; |
| 153 /* border: 1px dashed rgba(4, 4, 4, 0.35); */ | 157 /* border: 1px dashed rgba(4, 4, 4, 0.35); */ |
| 154 grid-template-columns: repeat(3,1fr); | 158 grid-template-columns: repeat(3,1fr); |
| 155 grid-template-rows: 20vw; | 159 grid-template-rows: 20vw; |
| 156 grid-gap: 0px; | 160 grid-gap: 0px; |
| 157 column-gap: 0px | 161 column-gap: 0px |
| 158 }} | 162 }} |
| 159 .distr_gallery__img {{ | 163 .distr_gallery__img {{ |
| 160 width: 100%; | 164 width: 100%; |
| 184 color:#363333;}} | 188 color:#363333;}} |
| 185 </style> | 189 </style> |
| 186 </head> | 190 </head> |
| 187 <body> | 191 <body> |
| 188 <h1 style="text-align:center; color:#363333">SpyBOAT Results Report</h1> | 192 <h1 style="text-align:center; color:#363333">SpyBOAT Results Report</h1> |
| 189 <hr style="width:50%"> | 193 <hr style="width:50%"> |
| 190 <h1 class="subheader"> Distribution Dynamics </h1> | 194 <h1 class="subheader"> Distribution Dynamics </h1> |
| 191 <div class="distr_gallery"> | 195 <div class="distr_gallery"> |
| 192 <figure class=”distr_gallery__item distr_gallery__item--1"> | 196 <figure class=”distr_gallery__item distr_gallery__item--1"> |
| 193 <img src="period_distr.png" alt="Period" class="distr_gallery__img"> | 197 <img src="period_distr.png" alt="Period" class="distr_gallery__img"> |
| 194 </figure> | 198 </figure> |
| 235 x[slideIndex-1].style.display = "block"; | 239 x[slideIndex-1].style.display = "block"; |
| 236 }} | 240 }} |
| 237 </script> | 241 </script> |
| 238 </body> | 242 </body> |
| 239 </html> | 243 </html> |
| 240 ''' | 244 """ |
| 241 | 245 |
| 242 with open(html_fname, 'w') as OUT: | 246 with open(html_fname, "w") as OUT: |
| 243 | |
| 244 OUT.write(html_string) | 247 OUT.write(html_string) |
| 245 | 248 |
| 246 logger.info(f'Created html report') | 249 logger.info("Created html report") |
| 247 return html_string | 250 return html_string |
| 248 | 251 |
| 249 # for local testing | 252 # for local testing |
| 250 # create_html([0,20,40,60,80]) | 253 # create_html([0,20,40,60,80]) |
