#!/usr/bin/python -tt ############################################## # based on plot_trigger_rate.py by QW and TPK ############################################## from array import array import os import re import sys import numpy as np import time from pyfact import SlowData #from ROOT import TCanvas, TGraph, TGraphErrors, TH2F #from ROOT import gStyle import matplotlib.pyplot as plt import matplotlib.dates filelist = [] if len(sys.argv) > 1: base_path = sys.argv[1] else: print 'Usage:', sys.argv[0], '/your/search/path' for base,subdirs,files in os.walk(base_path): for filename in files: #include only run files regex = re.search(r'\d\d\d\d\d\d\d\d\.FSC_CONTROL_TEMPERATURE.fits',filename) #include run files and also the nightly file #regex = re.search(r'FTM_CONTROL_TRIGGER_RATES',filename) if regex: filelist.append(os.path.join(base,filename)) plotlist = ['T_aux', 'T_back', 'T_crate', 'T_eth', 'T_ps', 'T_sens'] plotfmts = ['.:g', '.:k', '.:r', '.:y', '.:b', '.:m'] per_name = [] for filename in filelist: print filename f = SlowData(filename) # 'columns': {'QoS': (1L, 4L, 'J', ''), # 'T_aux': (4L, 4L, 'E', 'deg'), # 'T_back': (4L, 4L, 'E', 'deg'), # 'T_crate': (8L, 4L, 'E', 'deg'), # 'T_eth': (4L, 4L, 'E', 'deg'), # 'T_ps': (8L, 4L, 'E', 'deg'), # 'T_sens': (31L, 4L, 'E', 'deg'), # 'Time': (1L, 8L, 'D', 'MJD'), # 't': (1L, 4L, 'E', 's')}, f.register("all") f.stack() for row in f: pass for name in plotlist: per_name.append(f.columns[name][0]) fig = plt.figure() ax = fig.add_subplot(111) plt.hold(True) for i,name in enumerate(plotlist): for number in range(per_name[i]): print name, number Time = f.stacked_cols['Time'] data = f.stacked_cols[name][:,number] med = np.median(Time) # get rid of Times of the previous day. Time_today = Time[np.where( Time>med-0.25 )[0]] data_today = data[np.where( Time>med-0.25)[0]] ax.plot_date( Time_today, data_today, fmt=plotfmts[i]) today_str = time.strftime('%d.%m.' ,time.gmtime(Time_today[0]*24*3600)) print today_str plt.title('T_ps:blue T_eth:yellow T_aux:green T_crate:red T_back:black T_sens:magenta \n'+today_str) ax.xaxis.set_major_locator( matplotlib.dates.HourLocator(byhour=range(24), interval=1) ) ax.xaxis.set_major_formatter( matplotlib.dates.DateFormatter('%Hh') ) plt.ylim(12,41) if len(sys.argv) > 2: plt.savefig(sys.argv[2]) print 'plot saved to', sys.argv[2] else: print "WARNING:" print "plot was not saved..." print "please type: plt.savefig('') or so ... to save it"