diff 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
line wrap: on
line diff
--- a/output_report.py	Mon Nov 23 14:38:37 2020 +0000
+++ b/output_report.py	Tue Nov 24 13:06:26 2020 +0000
@@ -39,11 +39,13 @@
     fig = ppl.gcf()
     out_path = os.path.join(img_path, f'input_frame{frame}.png')
     fig.savefig(out_path, dpi=DPI)
+    ppl.close(fig)
     
     spyplot.phase_snapshot(results['phase'][frame])
     fig = ppl.gcf()
     out_path = os.path.join(img_path, f'phase_frame{frame}.png')    
     fig.savefig(out_path, dpi=DPI)
+    ppl.close(fig)
 
     spyplot.period_snapshot(results['period'][frame],
                             Wkwargs,
@@ -52,13 +54,14 @@
     fig = ppl.gcf()
     out_path = os.path.join(img_path, f'period_frame{frame}.png')    
     fig.savefig(out_path, dpi=DPI)
+    ppl.close(fig)
     
     spyplot.amplitude_snapshot(results['amplitude'][frame])
     fig = ppl.gcf()
     out_path = os.path.join(img_path, f'amplitude_frame{frame}.png')    
     fig.savefig(out_path, dpi=DPI)
+    ppl.close(fig)
         
-
     logger.info(f'Produced 4 snapshots for frame {frame}..')
 
 def produce_distr_plots(results, Wkwargs, img_path='.'):
@@ -87,14 +90,44 @@
     logger.info(f'Produced 3 distribution plots..')
 
     
-def create_html(frame_num, html_fname='OutputReport.html'):
+def create_html(frame_nums, html_fname='OutputReport.html'):
 
     '''
-    The html generated assumes the respective png's (7 in total)
+    The html generated assumes the respective png's 
     have been created with 'produce_snapshots' and 'produce_distr_plots'
     and can be found at the cwd (that's how Galaxy works..)
     '''
 
+    # -- create a gallery for every frame in frame_nums --
+    
+    galleries = ''
+    for frame_num in frame_nums:
+        new_gal =f'''
+        <div class="FrameSlides"> 
+        <h3 style="text-align:center; color=#363333"> Frame Nr. {frame_num} </h3>
+
+            <div class="snapshot_gallery">
+
+               <figure class=”snapshot_gallery__item snapshot_gallery__item--1">
+                 <img src="input_frame{frame_num}.png" alt="The Input" class="snapshot_gallery__img">
+               </figure>
+
+               <figure class=”snapshot_gallery__item snapshot_gallery__item--2">
+                 <img src="phase_frame{frame_num}.png" alt="Phase" class="snapshot_gallery__img">
+               </figure>
+
+               <figure class=”snapshot_gallery__item snapshot_gallery__item--3">
+                 <img src="period_frame{frame_num}.png" alt="Period" class="snapshot_gallery__img">
+               </figure>
+
+               <figure class=”snapshot_gallery__item snapshot_gallery__item--4">
+                 <img src="amplitude_frame{frame_num}.png" alt="Amplitude" class="snapshot_gallery__img">
+               </figure>
+            </div>
+        </div>
+        '''
+        galleries += new_gal
+    
     html_string =f'''
     <html>
     <title>SpyBOAT Output Report</title>
@@ -105,10 +138,11 @@
         body{{ margin:10 100; background:whitesmoke; }}
         /*body{{ margin:10 100; background:darkslategrey; }}*/
         .center{{
+            text-align: center;
             display: block;
             margin-left: auto;
             margin-right: auto;
-            width: 40%;}}
+            width: 100%;}}
 
         /* matplotlib output at 1600x1200  */
         .distr_gallery {{
@@ -117,7 +151,7 @@
             text-align: center;
             /* border: 1px dashed rgba(4, 4, 4, 0.35);     */
             grid-template-columns: repeat(3,1fr);
-            grid-template-rows: 25vw;    
+            grid-template-rows: 20vw;    
             grid-gap: 0px;
             column-gap: 0px
         }}
@@ -143,11 +177,16 @@
             height: 100%;
             object-fit: contain;
         }}
+        .subheader{{
+             text-align:center;
+             font-size: 160%;
+             color:#363333;}}
      </style>
     </head>
     <body>
-    <h1 style="text-align:center">SpyBOAT Results Report</h1>
+    <h1 style="text-align:center; color:#363333">SpyBOAT Results Report</h1>
     <hr style="width:50%"> 
+    <h1 class="subheader"> Distribution Dynamics </h1>
     <div class="distr_gallery">
        <figure class=”distr_gallery__item distr_gallery__item--1">
          <img src="period_distr.png" alt="Period" class="distr_gallery__img">
@@ -163,27 +202,38 @@
 
     </div>
 
-    <h2 style="text-align:center"> Snapshots - Frame {frame_num}</h2>
-    <div class="snapshot_gallery">
-       <figure class=”snapshot_gallery__item snapshot_gallery__item--1">
-         <img src="input_frame{frame_num}.png" alt="The Input" class="snapshot_gallery__img">
-       </figure>
+    <h1 class="subheader"> Output Movie Snapshots </h1>
 
-       <figure class=”snapshot_gallery__item snapshot_gallery__item--2">
-         <img src="phase_frame{frame_num}.png" alt="Phase" class="snapshot_gallery__img">
-       </figure>
+    <!-- trigger the javascript at the end--->
+    <div class="center">
+        <button class="w3-button" onclick="plusDivs(-1)">&#10094; Prev</button>
+        <button class="w3-button" onclick="plusDivs(1)">Next &#10095;</button>
+    </div>
+
+    <!-- defines all elements of the "FrameSlides" class --->
+    {galleries}
+    </div>
 
-       <figure class=”snapshot_gallery__item snapshot_gallery__item--3">
-         <img src="period_frame{frame_num}.png" alt="Period" class="snapshot_gallery__img">
-       </figure>
+    <!-- javascript with escaped '{{'--->
+    <script>
+        var slideIndex = 1;
+        showDivs(slideIndex);
+
+        function plusDivs(n) {{
+          showDivs(slideIndex += n);
+        }}
 
-       <figure class=”snapshot_gallery__item snapshot_gallery__item--4">
-         <img src="amplitude_frame{frame_num}.png" alt="Amplitude" class="snapshot_gallery__img">
-       </figure>
-    </div>
-    
-
-        <!-- *** Section 1 *** --->
+        function showDivs(n) {{
+          var i;
+          var x = document.getElementsByClassName("FrameSlides");
+          if (n > x.length) {{slideIndex = 1}}
+          if (n < 1) {{slideIndex = x.length}} ;
+          for (i = 0; i < x.length; i++) {{
+            x[i].style.display = "none";
+          }}
+          x[slideIndex-1].style.display = "block";
+        }}
+    </script>
     </body>
     </html>
     '''
@@ -196,4 +246,4 @@
     return html_string
 
 # for local testing
-# create_html(125)
+# create_html([0,20,40,60,80])