Changeset 18293 for branches/trigger_burst_research
- Timestamp:
- 08/25/15 12:56:28 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/trigger_burst_research/sketch.py
r18291 r18293 1 1 # coding: utf-8 2 import progressbar 2 3 import calendar 3 4 import numpy as np … … 32 33 33 34 34 def get_ data_runs_from_run_db(night_int,factdb):35 def get_all_data_runs_from_run_db(factdb): 35 36 keys = [ 36 37 'fRunID', … … 41 42 42 43 sql_query = """SELECT {comma_sep_keys} 43 FROM RunInfo WHERE fRunTypeKey=1 AND fNight={night:d};44 FROM RunInfo WHERE fRunTypeKey=1 ORDER BY fNight; 44 45 """ 45 46 sql_query = sql_query.format( 46 47 comma_sep_keys=', '.join(keys), 47 night=night_int,48 48 ) 49 49 … … 57 57 58 58 59 59 60 def get_trigger_rates(night_int, base_path='/fact/aux/'): 60 61 night_string = str(night_int) 61 62 fits_file = fits.open( 62 63 base_path+'{y}/{m}/{d}/{n}.FTM_CONTROL_TRIGGER_RATES.fits'.format( 63 n i=night_string,64 n=night_string, 64 65 y=night_string[0:4], 65 66 m=night_string[4:6], … … 71 72 72 73 73 def add_ratio_and_more_to_dataframe(data_runs , trigger_rates):74 def add_ratio_and_more_to_dataframe(data_runs): 74 75 75 76 # create new columns and pre-assign some hopefully good NULL-like-values … … 79 80 data_runs['fBoardTriggerRateRatioAboveThreshold'] = np.nan 80 81 81 for dataframe_index in data_runs.index: 82 trigger_rates = None 83 last_night = None 84 85 progress = progressbar.ProgressBar(widgets=[progressbar.Bar('=', '[', ']'), ' ', 86 progressbar.Percentage(), ' ', 87 progressbar.ETA()]) 88 89 for dataframe_index in progress(data_runs.index): 82 90 this_run = data_runs.ix[dataframe_index] 91 if last_night != this_run['fNight']: 92 try: 93 trigger_rates = get_trigger_rates(this_run['fNight']) 94 except (IOError, ValueError): 95 continue 96 last_night = this_run['fNight'] 97 83 98 mask = ( 84 99 (trigger_rates['Time'] > fjd(this_run['fRunStart'])) * 85 100 (trigger_rates['Time'] < fjd(this_run['fRunStop'])) 86 101 ) 87 this_board_rates = trigger_rates['BoardRate'][mask] 102 103 if mask.sum() == 0: 104 continue 105 try: 106 this_board_rates = trigger_rates['BoardRate'][mask] 107 except KeyError: 108 continue 88 109 89 110 N = this_board_rates.shape[0] … … 109 130 def main(night_int): 110 131 factdb = create_DB_connection() 111 data_runs = get_data_runs_from_run_db(night_int, factdb) 112 trigger_rates = get_trigger_rates(night_int) 113 add_ratio_and_more_to_dataframe(data_runs, trigger_rates) 132 data_runs = get_all_data_runs_from_run_db(factdb) 133 add_ratio_and_more_to_dataframe(data_runs) 114 134 return data_runs 115 135
Note:
See TracChangeset
for help on using the changeset viewer.