From 32164d0056173d5c28daeb50e07fa0bf85343ab8 Mon Sep 17 00:00:00 2001
From: Mikhail Karnevskiy <karnem@max-exfl001.desy.de>
Date: Tue, 7 Aug 2018 10:04:07 +0200
Subject: [PATCH] include more statisticcs information

---
 notebooks/LPD/PlotFromCalDB.py | 81 +++++++++++++++++++++-------------
 1 file changed, 51 insertions(+), 30 deletions(-)

diff --git a/notebooks/LPD/PlotFromCalDB.py b/notebooks/LPD/PlotFromCalDB.py
index 9845a140a..136b1334b 100644
--- a/notebooks/LPD/PlotFromCalDB.py
+++ b/notebooks/LPD/PlotFromCalDB.py
@@ -20,7 +20,7 @@ warnings.filterwarnings('ignore')
 matplotlib.use("agg")
 
 
-start_date = "2018-07-25" # date to start investigation interval from
+start_date = "2018-06-25" # date to start investigation interval from
 end_date = "now" # date to end investigation interval at, can be "now"
 interval = 3 # interval for evaluation in days
 detector = "LPD1M1" # detector to investigate
@@ -105,7 +105,7 @@ while dt < end:
             if cdata is not None:
                 carr = np.zeros((5, max_cells, 3))
                 carr_glob = np.zeros((5, 3))
-                carr_rad = np.zeros((cdata.shape[0], max_cells, 3))
+                carr_px = np.zeros((cdata.shape[0], max_cells, 3, 2))
                 for g in range(3):
                     td = np.nanmean(cdata[...,g], axis=(0,1))
                     print (td.shape)
@@ -138,9 +138,11 @@ while dt < end:
                     td = np.nanstd(cdata[...,g])
                     carr_glob[3, g] = td
                     
-                    carr_rad[...,g] = np.nanmedian(cdata[...,g], axis=0)
+                    carr_px[...,g, 0] = np.nanmedian(cdata[...,g], axis=0)
+                    carr_px[...,g, 1] = np.nanmedian(cdata[...,g], axis=1)
 
-                ret_constants[const][qm].append((creation_time,(carr, carr_glob, carr_rad)))
+                ret_constants[const][qm].append((creation_time,
+                                        (carr, carr_glob, carr_px)))
                 
     dt += step
 
@@ -167,41 +169,24 @@ for const, modules in ret_constants.items():
             pmm, glob, _ = list(zip(*cd))
             pma = np.array(pmm)
             ga = np.array(glob)
-            
             d = pma[:,typ,:,:]
-            print (pma.shape, ga.shape, d.shape)
 
             if np.allclose(d, 0):
                 continue
-            x = []
-            y = []
-            hue = []
-
-            # loop over gain
-            for g in range(3):
-                dd = (pma[:,typ,:,g]-pma[0,typ,:,g])/pma[0,typ,:,g]
-                print (pma[0,typ,:,g])
-                dd[~np.isfinite(dd)] = 0
-                x.append(np.repeat(np.array(ctimes)[:,None], dd.shape[1], axis=1).flatten())
-                print (x)
-                y.append(dd.flatten())
-                hue.append(np.ones(dd.shape).flatten()*g)
-            x = np.concatenate(x)
-            y = np.concatenate(y)
-            hue = np.concatenate(hue)
-            print (x.shape)
+            dd = pma[:,typ,:,:]#-pma[0,typ,:,:])/pma[0,typ,:,:]
+            y = dd.flatten()
+            x = np.repeat(np.array(ctimes)[:,None],
+                 dd[0,:,:].size, axis=1).flatten()
+            hue = np.repeat(np.array(['gain 0', 'gain 1', 'gain 2'])[:,None],
+                   dd[:,:,0].size, axis=1).swapaxes(0,1).flatten()
             seaborn.violinplot(x, y, hue, scale="width", dodge=False, saturation=0.7)
-            #for i in range(max_cells):
-                #ax.scatter(ctimes, (pma[:,typ,i,g]-pma[0,typ,i,g])/pma[0,typ,i,g], marker='.', color=colors[g], alpha=0.5)
-                #ax.plot(ctimes, (ga[:,typ,g]-ga[0,typ,g])/ga[0,typ,g], color=colors[g], alpha=0.5)
-                                   
-            ax.set_ylim(-0.25, .25)
+
+            #ax.set_ylim(-0.25, .25)
             
         if typ != len(types)-1:
             ax.axes.get_xaxis().set_visible(False)
         else:
             def format_date(x, pos=None):
-    
                 return ctimes[x].strftime('%d-%m')
             ax.xaxis.set_major_formatter(ticker.FuncFormatter(format_date))
             ax.set_xlabel("Date")
@@ -211,5 +196,41 @@ for const, modules in ret_constants.items():
     plt.subplots_adjust(wspace=0.2, hspace=0.2)
     
     if out_folder != "":
-        fig.savefig("{}/{}_time_development.pdf".format(out_folder, const), bbox_inches='tight')
+        fig.savefig("{}/{}_time_development.pdf".format(out_folder, const), 
+             bbox_inches='tight')
+    plt.show()
+
+
+    
+
+    fig = plt.figure(figsize=(15,7))
+    ax = plt.subplot2grid((1, 1), (0, 0))
+        
+    # loop over modules
+    for mod, data in modules.items():
+        ctimes, cd = list(zip(*data))
+        _, _, px = list(zip(*cd))
+        px = np.array(px)
+        print (px.shape)
+        y = px[:,:,5,0,:].flatten()
+        x = np.repeat(np.array(ctimes)[:,None],
+                px[0,:,5,0,:].size, axis=1).flatten()
+        hue = np.repeat(np.array(['px','py'])[:,None], px[:,:,5,0,0].size, 
+                axis=1).swapaxes(0,1).flatten()
+
+        seaborn.violinplot(x, y, hue, palette="muted", split=True)
+
+        def format_date(x, pos=None):
+            return ctimes[x].strftime('%d-%m')
+        ax.xaxis.set_major_formatter(ticker.FuncFormatter(format_date))
+        ax.set_xlabel("Date")
+        ax.set_ylabel("Median over pixels")
+        
+    plt.subplots_adjust(wspace=0.2, hspace=0.2)
+    
+    if out_folder != "":
+        fig.savefig("{}/{}_pxtime_development.pdf".format(out_folder, const),
+             bbox_inches='tight')
+    plt.show()
+
 
-- 
GitLab