Ignore:
Timestamp:
08/25/15 12:56:28 (9 years ago)
Author:
dneise
Message:
debugging, special treatment of old aux-files (continue), and progressbar
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/trigger_burst_research/sketch.py

    r18291 r18293  
    11# coding: utf-8
     2import progressbar
    23import calendar
    34import numpy as np
     
    3233
    3334
    34 def get_data_runs_from_run_db(night_int, factdb):
     35def get_all_data_runs_from_run_db(factdb):
    3536    keys = [
    3637        'fRunID',
     
    4142
    4243    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;
    4445        """
    4546    sql_query = sql_query.format(
    4647        comma_sep_keys=', '.join(keys),
    47         night=night_int,
    4848        )
    4949   
     
    5757
    5858
     59
    5960def get_trigger_rates(night_int, base_path='/fact/aux/'):
    6061    night_string = str(night_int)
    6162    fits_file = fits.open(
    6263        base_path+'{y}/{m}/{d}/{n}.FTM_CONTROL_TRIGGER_RATES.fits'.format(
    63             ni=night_string,
     64            n=night_string,
    6465            y=night_string[0:4],
    6566            m=night_string[4:6],
     
    7172
    7273
    73 def add_ratio_and_more_to_dataframe(data_runs, trigger_rates):
     74def add_ratio_and_more_to_dataframe(data_runs):
    7475
    7576    # create new columns and pre-assign some hopefully good NULL-like-values
     
    7980    data_runs['fBoardTriggerRateRatioAboveThreshold'] = np.nan
    8081
    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):
    8290        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
    8398        mask = (
    8499            (trigger_rates['Time'] > fjd(this_run['fRunStart'])) *
    85100            (trigger_rates['Time'] < fjd(this_run['fRunStop']))
    86101            )
    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
    88109
    89110        N = this_board_rates.shape[0]
     
    109130def main(night_int):
    110131    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)
    114134    return data_runs
    115135
Note: See TracChangeset for help on using the changeset viewer.