PlotDataQA.py
Go to the documentation of this file.
1 import os
2 import sys
3 import subprocess
4 import datetime
5 import time
6 #sys.path.append('/Users/athula/Desktop/MuonMonitor/ACNETdata/PhysicsStudies/Utility/')
7 import PlotUtilityNew as pu
8 import matplotlib.pyplot as plt
9 import pandas as pd
10 import numpy as np
11 #import seaborn as sns
12 import matplotlib.dates as mdates
13 import matplotlib
14 from datetime import datetime
15 
16 #matplotlib.use('GTK')
17 #matplotlib.use('Agg')
18 plt.switch_backend('agg')
19 #----------------------------
20 level0_list = ['MM1XAV','MM2XAV','MM3XAV','MM1YAV','MM2YAV','MM3YAV',
21  'TORTGT','TRTGTD']
22 level1_list = ['MM1COR_CAL','MM2COR_CAL','MM3COR_CAL']
23 
24 plt.rcParams["font.weight"] = "bold"
25 plt.rcParams["axes.labelweight"] = "bold"
26 plt.rcParams['figure.figsize'] = 12, 8
27 plt.rcParams.update({'font.size': 12})
28 plt.rcParams["lines.linewidth"] = 2
29 my_markersize = 1.0
30 #----------------------------
31 def MakePlots(unixtime,pldir):
32  timein = datetime.fromtimestamp(unixtime)
33  timein = timein.replace(minute=0,second=0)
34 
35  timepast = datetime.fromtimestamp(int(unixtime) - 60*60*24)
36  timepast = timepast.replace(minute=0,second=0)
37 
38  myFmt = mdates.DateFormatter('%Y-%m-%d %H:%M')
39 
40  d2 = str(timein.year)+'-'+str(timein.month)+'-'+str(timein.day)
41  d1 = str(timepast.year)+'-'+str(timepast.month)+'-'+str(timepast.day)
42  t2 = str(timein.time())
43  t1 = str(timepast.time())
44  #print(timein.replace(minute=0,second=0))
45  print(d1,t1,d2,t2)
46 #-------------------MMAVE Plots:
47 
48  #==== Setting limits: ========
49  mm1xavMin = 1.7
50  mm1xavMax = 2.0
51  mm2xavMin = 5.6
52  mm2vavMax = 6.1
53 
54  mm1yavMin = -1.5
55  mm1yavMax = -1.0
56  mm2yavMin = 0.0
57  mm2yavMax = 0.3
58 
59  mm1corMin = 1.7
60  mm1corMax = 2.0
61  mm2corMin = 5.6
62  mm2corMax = 6.1
63 
64  hornIMin = -200.
65  hornIMax = -198.
66  #=============================
67 #-------------------MMAVE Plots:
68  var_array = ['MM1XAV', 'MM1YAV','MM2XAV','MM2YAV']
69 
70  df_result =pu.pull_MultiData(d1,t1,d2,t2,var_array)
71  df_result['time_new'] = pd.to_datetime(df_result['date'] +' '+df_result['time'])
72 
73  df_result['mm1ymin'] = mm1yavMin
74  df_result['mm1ymax'] = mm1yavMax
75  df_result['mm2ymin'] = mm2yavMin
76  df_result['mm2ymax'] = mm2yavMax
77  var_array = ['MM1XAV', 'MM1YAV','MM2XAV','MM2YAV','mm1ymin','mm1ymax','mm2ymin','mm2ymax']
78 
79  #-- Setting up status:
80  std_mm1y = df_result['MM1YAV'].std()
81  std_mm2y = df_result['MM2YAV'].std()
82  std_mm1x = df_result['MM1XAV'].std()
83  std_mm2x = df_result['MM2XAV'].std()
84 
85  ave90_mm2y = df_result['MM2YAV'].quantile(0.95)
86  ave90_mm1y = df_result['MM1YAV'].quantile(0.95)
87 
88  ave10_mm2y = df_result['MM2YAV'].quantile(0.1)
89  ave10_mm1y = df_result['MM1YAV'].quantile(0.1)
90 
91  print(df_result.describe(percentiles=[.9]))
92 
93  stat_mm1y = 'Good'
94  face_colr = 'g'
95  if (ave10_mm1y < mm1yavMin or ave90_mm1y > mm1yavMax) or (ave10_mm2y < mm2yavMin or ave90_mm2y > mm2yavMax) or std_mm1x > 10.0 or std_mm2x > 10:
96  stat_mm1y = 'Not Good'
97  face_colr = 'r'
98  #-----------------------
99  props = dict(boxstyle='round', facecolor=face_colr, alpha=0.7)
100 
101  fig, ax = plt.subplots()
102 
103  df_result.plot(x='time_new',y = var_array,ax=ax, markersize = my_markersize,label=[r'MM1 $X_{ave}$',r'MM1 $Y_{ave}$',r'MM2 $X_{ave}$',r'MM2 $Y_{ave}$','','','',''], marker='o', linestyle=' ',color = ['b','r','g','orange','magenta','magenta','coral','coral'])
104  plt.ylim((-2., 1.5))
105  ax.text(0.05, 0.95, 'Status: '+str(stat_mm1y), transform=ax.transAxes, fontsize=14,verticalalignment='top', bbox=props)
106 
107  plt.ylabel('Muon Monitor Centroid Position [in]')
108  plt.xlabel('Time')
109  plt.grid(True)
110  plt.title(r'Muon Monitor 1 & 2 $X_{ave}$ and $Y_{ave}$ Data Last refreshed:'+str(d2)+"-"+str(t2), fontsize=14)
111  plt.legend(loc='upper right', numpoints=5, fontsize=15)
112  plt.gcf().autofmt_xdate()
113  plt.gca().xaxis.set_major_formatter(myFmt)
114  plt.savefig(str(pldir)+'MMAVE.png')
115 
116  #======================== MMCOR : ===================================
117 
118  fig, ax1 = plt.subplots()
119  ax2 = ax1.twinx()
120  ax2.tick_params(axis='y', labelcolor='green')
121  var_array = ['MM1COR_CAL', 'MM2COR_CAL','TRTGTD']
122 
123  df_result =pu.pull_MultiData(d1,t1,d2,t2,var_array)
124  df_result['time_new'] = pd.to_datetime(df_result['date'] +' '+df_result['time'])
125 
126  df_result['MM1COR_norm'] = df_result['MM1COR_CAL']/df_result['TRTGTD']
127  df_result['MM2COR_norm'] = df_result['MM2COR_CAL']/df_result['TRTGTD']
128 
129  df_result['mm1cormin'] = mm1corMin
130  df_result['mm1cormax'] = mm1corMax
131  df_result['mm2cormin'] = mm2corMin
132  df_result['mm2cormax'] = mm2corMax
133  #-- Setting up status:
134 
135  ave90_mm1cor = df_result['MM1COR_norm'].quantile(0.98)
136  ave90_mm2cor = df_result['MM2COR_norm'].quantile(0.98)
137  ave10_mm1cor = df_result['MM1COR_norm'].quantile(0.1)
138  ave10_mm2cor = df_result['MM2COR_norm'].quantile(0.1)
139 
140  print(df_result.describe(percentiles=[.9]))
141  print(ave90_mm1cor,ave90_mm2cor)
142 
143  stat_cor = 'Good'
144  face_colr = 'g'
145  if (ave10_mm1cor < mm1corMin or ave90_mm1cor > mm1corMax) or (ave10_mm2cor < mm2corMin or ave90_mm2cor > mm2corMax):
146  stat_cor = 'Not Good'
147  face_colr = 'r'
148  #-----------------------
149  props = dict(boxstyle='round', facecolor=face_colr, alpha=0.7)
150 
151  df_result.plot(x='time_new',y = ['MM1COR_norm','MM2COR_norm','mm1cormin','mm1cormax','mm2cormin','mm2cormax'],ax = ax1,color = ['b','r','cyan','cyan','magenta','magenta'], label=['Muon Monitor 1','Muon Monitor 2','','','',''],markersize = my_markersize, marker='o', linestyle=' ')
152  ax1.text(0.4, 0.95, 'Gain Status: '+str(stat_cor), transform=ax.transAxes, fontsize=14,verticalalignment='top', bbox=props)
153 
154  ax1.set_ylim(1,8)
155  ax2.set_ylim(-205,-190)
156  ax1.tick_params(axis='y', labelcolor='b')
157  ax1.set_ylabel('Calibrated Signal Gain/POT[E12]')
158  ax1.set_xlabel('Time')
159  ax1.grid(True)
160  plt.gcf().autofmt_xdate()
161  plt.gca().xaxis.set_major_formatter(myFmt)
162  ax1.legend(loc='upper left', numpoints=5, fontsize=15)
163 
164 #---------- horn current plots:
165 
166  var_array = ['NSLINA','NSLINB','NSLINC','NSLIND']
167  df_cur =pu.pull_MultiData(d1,t1,d2,t2,var_array)
168  df_cur['HornI'] = df_cur.iloc[:,2:6].sum(axis = 1)
169 
170  df_cur['hornImin'] = hornIMin
171  df_cur['hornImax'] = hornIMax
172  #-- Setting up status:
173 
174  cuartile10_hornI = df_cur['HornI'].quantile(0.05)
175  cuartile90_hornI = df_cur['HornI'].quantile(0.98)
176 
177  print(df_cur.describe(percentiles=[.9]))
178 
179  stat_I = 'Good'
180  face_I = 'g'
181  if (cuartile10_hornI < hornIMin or cuartile90_hornI > hornIMax):
182  stat_I = 'Not Good'
183  face_I = 'r'
184 #-----------------------
185  props = dict(boxstyle='round', facecolor=face_I, alpha=0.7)
186  print(df_cur)
187  df_cur['time_new'] = pd.to_datetime(df_cur['date'] +' '+df_cur['time'])
188  df_cur.plot(x='time_new',y = ['HornI','hornImin','hornImax'], ax = ax2,color=['green','lime','lime'],label=['Horn Current','',''],markersize = my_markersize, marker='o', linestyle=' ')
189  ax2.text(0.4, 0.88, 'Horn I Status: '+str(stat_I), transform=ax.transAxes, fontsize=14,verticalalignment='top', bbox=props)
190 
191  ax2.set_ylabel('Horn Current [kA]')
192  ax2.set_xlabel('Time')
193  plt.grid(True)
194  plt.gcf().autofmt_xdate()
195  plt.gca().xaxis.set_major_formatter(myFmt)
196  plt.title(r'Muon Monitor 1 & 2 signal gain and Horn Current data Last refreshed:'+str(d2)+"-"+str(t2), fontsize=14)
197  ax2.legend(loc=0, numpoints=5, fontsize=15)
198  plt.savefig(str(pldir)+'MMCOR.png')
199 
200 
bool print
unsigned int quantile(std::vector< std::vector< double >> v, float E, float hadEfrac)
Definition: Toy_analyses.C:480
def MakePlots(unixtime, pldir)
Definition: PlotDataQA.py:31
Double_t sum
Definition: plot.C:31