7 import PlotUtilityNew
as pu
8 import matplotlib.pyplot
as plt
12 import matplotlib.dates
as mdates
14 from datetime
import datetime
18 plt.switch_backend(
'agg')
20 level0_list = [
'MM1XAV',
'MM2XAV',
'MM3XAV',
'MM1YAV',
'MM2YAV',
'MM3YAV',
22 level1_list = [
'MM1COR_CAL',
'MM2COR_CAL',
'MM3COR_CAL']
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
32 timein = datetime.fromtimestamp(unixtime)
33 timein = timein.replace(minute=0,second=0)
35 timepast = datetime.fromtimestamp(
int(unixtime) - 60*60*24)
36 timepast = timepast.replace(minute=0,second=0)
38 myFmt = mdates.DateFormatter(
'%Y-%m-%d %H:%M')
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())
68 var_array = [
'MM1XAV',
'MM1YAV',
'MM2XAV',
'MM2YAV']
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'])
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']
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()
85 ave90_mm2y = df_result[
'MM2YAV'].
quantile(0.95)
86 ave90_mm1y = df_result[
'MM1YAV'].
quantile(0.95)
88 ave10_mm2y = df_result[
'MM2YAV'].
quantile(0.1)
89 ave10_mm1y = df_result[
'MM1YAV'].
quantile(0.1)
91 print(df_result.describe(percentiles=[.9]))
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' 99 props = dict(boxstyle=
'round', facecolor=face_colr, alpha=0.7)
101 fig, ax = plt.subplots()
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'])
105 ax.text(0.05, 0.95,
'Status: '+
str(stat_mm1y), transform=ax.transAxes, fontsize=14,verticalalignment=
'top', bbox=props)
107 plt.ylabel(
'Muon Monitor Centroid Position [in]')
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')
118 fig, ax1 = plt.subplots()
120 ax2.tick_params(axis=
'y', labelcolor=
'green')
121 var_array = [
'MM1COR_CAL',
'MM2COR_CAL',
'TRTGTD']
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'])
126 df_result[
'MM1COR_norm'] = df_result[
'MM1COR_CAL']/df_result[
'TRTGTD']
127 df_result[
'MM2COR_norm'] = df_result[
'MM2COR_CAL']/df_result[
'TRTGTD']
129 df_result[
'mm1cormin'] = mm1corMin
130 df_result[
'mm1cormax'] = mm1corMax
131 df_result[
'mm2cormin'] = mm2corMin
132 df_result[
'mm2cormax'] = mm2corMax
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)
140 print(df_result.describe(percentiles=[.9]))
141 print(ave90_mm1cor,ave90_mm2cor)
145 if (ave10_mm1cor < mm1corMin
or ave90_mm1cor > mm1corMax)
or (ave10_mm2cor < mm2corMin
or ave90_mm2cor > mm2corMax):
146 stat_cor =
'Not Good' 149 props = dict(boxstyle=
'round', facecolor=face_colr, alpha=0.7)
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)
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')
160 plt.gcf().autofmt_xdate()
161 plt.gca().xaxis.set_major_formatter(myFmt)
162 ax1.legend(loc=
'upper left', numpoints=5, fontsize=15)
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)
170 df_cur[
'hornImin'] = hornIMin
171 df_cur[
'hornImax'] = hornIMax
174 cuartile10_hornI = df_cur[
'HornI'].
quantile(0.05)
175 cuartile90_hornI = df_cur[
'HornI'].
quantile(0.98)
177 print(df_cur.describe(percentiles=[.9]))
181 if (cuartile10_hornI < hornIMin
or cuartile90_hornI > hornIMax):
185 props = dict(boxstyle=
'round', facecolor=face_I, alpha=0.7)
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)
191 ax2.set_ylabel(
'Horn Current [kA]')
192 ax2.set_xlabel(
'Time')
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')
unsigned int quantile(std::vector< std::vector< double >> v, float E, float hadEfrac)
def MakePlots(unixtime, pldir)