- Timestamp:
- 06/11/15 21:53:29 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/DataCheck/DataCheck/plot_ratescan.py
r18202 r18203 14 14 15 15 Usage: 16 plot_ratescan.py [-d DATE] 16 plot_ratescan.py [-d DATE] [--cronjob | --verbose] 17 17 plot_ratescan.py (-h | --help) 18 18 plot_ratescan.py --version 19 plot_ratescan.py all [--verbose] 19 20 20 21 Options: 21 -h --help Show this screen.22 -h --help Show this screen. 22 23 -d --date DATE date in typical fact format: YYYYMMDD 24 --cronjob Suppress most output for humans, only create output in case of real malfunctions. 25 --verbose Create even more output 23 26 """ 24 27 from docopt import docopt … … 27 30 from astropy.io import fits 28 31 import numpy as np 32 import glob 29 33 30 34 # import matplotlib, without a running X server. … … 35 39 outpath = '/loc_data/analysis/ratescan_plots/{y:04d}/{m:02d}/{d:02d}/{y:04d}{m:02d}{d:02d}.png' 36 40 infile_path = '/loc_data/aux/{y:04d}/{m:02d}/{d:02d}/{y:04d}{m:02d}{d:02d}.RATE_SCAN_DATA.fits' 41 pointing_file_path_template = '/loc_data/aux/{y:04d}/{m:02d}/{d:02d}/{y:04d}{m:02d}{d:02d}.DRIVE_CONTROL_POINTING_POSITION.fits' 37 42 38 43 def make_outpath(file_path): … … 41 46 os.makedirs(directory) 42 47 43 def plot_ratescan(datetime_instance ):48 def plot_ratescan(datetime_instance, arguments): 44 49 dt = datetime_instance 45 50 year, month, day = dt.year, dt.month, dt.day 46 51 47 52 file_path = infile_path.format(y=year, m=month, d=day) 48 #print "opening file_path:", file_path 53 pointing_file_path = pointing_file_path_template.format(y=year, m=month, d=day) 54 if arguments['--verbose']: 55 print "opening file_path:", file_path 56 49 57 try: 50 58 f = fits.open(file_path) 51 59 p_file = fits.open(pointing_file_path) 52 60 d = f[1].data 53 61 p_data = p_file[1].data 62 63 ids = d['Id'] 64 threshold = d['Threshold'] 65 trigger_rate = d['TriggerRate'] 66 id_set = sorted(list(set(ids))) 67 54 68 plt.figure(figsize=(8, 6), dpi=80, facecolor='w', edgecolor='k') 55 plt.semilogy( d['Threshold'], d['TriggerRate'], 'o:') 69 for _id in id_set: 70 starttime = _id / (24. * 3600) 71 stoptime = (_id+30) / (24. * 3600) 72 idx = np.where((p_data['Time'] >= starttime) * (p_data['Time'] < stoptime))[0] 73 zd = p_data['Zd'][idx].mean() 74 az = p_data['Az'][idx].mean() 75 # _id is starttime of ratescan in unix timestamp. 76 dt = datetime.datetime.utcfromtimestamp(_id) 77 try: 78 tresh = threshold[ids==_id] 79 rate = trigger_rate[ids==_id] 80 plt.semilogy( 81 tresh[rate > 0.], 82 rate[rate > 0.], 83 'o:', 84 label=dt.strftime("%H:%M:%S")+" Zd:{0:.1f}".format(zd) 85 ) 86 except Exception as e: 87 print e 88 print 'trigger_rate', trigger_rate[ids==_id], (trigger_rate[ids==_id] < 0.).any() 56 89 plt.grid() 90 plt.legend() 57 91 58 92 plt.xlabel('Threshold [DAC]') … … 64 98 make_outpath(file_path) 65 99 plt.savefig(file_path, dpi=80) 66 print file_path, "has been written" 100 if not arguments['--cronjob']: 101 # the cronjob does not like too much output 102 print file_path, "has been written" 67 103 68 104 except IOError as e: 69 print e 105 if not arguments['--cronjob']: 106 # The cronjob might regularly try to open ratescans 107 # which have not yet been taken. So ... well, we don't care. 108 print e 70 109 71 110 if __name__ == '__main__': 72 arguments = docopt(__doc__, version='plot_ratescan 0.9') 73 111 arguments = docopt(__doc__, version='plot_ratescan 0.9.1') 112 if arguments['--verbose']: 113 print arguments 114 115 if arguments['all']: 116 my_list = sorted(glob.glob('/loc_data/aux/*/*/*/*.RATE_SCAN_DATA.fits')) 117 file_names = [] 118 for x in my_list: 119 if 'bad' in x: 120 continue 121 if '_' in x.split('/')[-1].split('.')[0]: 122 continue 123 file_names.append(x) 124 125 ymd = map(int, x.split('/')[3:6]) 126 date = datetime.datetime(*ymd) 127 try: 128 plot_ratescan(date, arguments) 129 except Exception as e: 130 print e 131 74 132 date = arguments['--date'] 75 133 now = datetime.datetime.utcnow() … … 78 136 # need to get y,m,d of yesterday. 79 137 yesterday = now - datetime.timedelta(hours=24) 80 plot_ratescan(yesterday )138 plot_ratescan(yesterday, arguments) 81 139 else: 82 140 # The user supplied a date-string, which we need to parse … … 92 150 print "Please choose a better date" 93 151 94 plot_ratescan(date )152 plot_ratescan(date, arguments) 95 153 except ValueError as e: 96 154 print e
Note:
See TracChangeset
for help on using the changeset viewer.