Changeset 18203 for trunk


Ignore:
Timestamp:
06/11/15 21:53:29 (9 years ago)
Author:
dneise
Message:
made it mor quiet. added 'all' mode. inserted Zd angle into plot, and time.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/DataCheck/DataCheck/plot_ratescan.py

    r18202 r18203  
    1414
    1515Usage:
    16   plot_ratescan.py [-d DATE]
     16  plot_ratescan.py [-d DATE] [--cronjob | --verbose]
    1717  plot_ratescan.py (-h | --help)
    1818  plot_ratescan.py --version
     19  plot_ratescan.py all [--verbose]
    1920
    2021Options:
    21   -h --help     Show this screen.
     22  -h --help       Show this screen.
    2223  -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
    2326"""
    2427from docopt import docopt
     
    2730from astropy.io import fits
    2831import numpy as np
     32import glob
    2933
    3034# import matplotlib, without a running X server.
     
    3539outpath = '/loc_data/analysis/ratescan_plots/{y:04d}/{m:02d}/{d:02d}/{y:04d}{m:02d}{d:02d}.png'
    3640infile_path = '/loc_data/aux/{y:04d}/{m:02d}/{d:02d}/{y:04d}{m:02d}{d:02d}.RATE_SCAN_DATA.fits'
     41pointing_file_path_template = '/loc_data/aux/{y:04d}/{m:02d}/{d:02d}/{y:04d}{m:02d}{d:02d}.DRIVE_CONTROL_POINTING_POSITION.fits'
    3742
    3843def make_outpath(file_path):
     
    4146    os.makedirs(directory)
    4247
    43 def plot_ratescan(datetime_instance):
     48def plot_ratescan(datetime_instance, arguments):
    4449    dt = datetime_instance
    4550    year, month, day = dt.year, dt.month, dt.day
    4651
    4752    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
    4957    try:
    5058        f = fits.open(file_path)
    51    
     59        p_file = fits.open(pointing_file_path)
    5260        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       
    5468        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()
    5689        plt.grid()
     90        plt.legend()
    5791
    5892        plt.xlabel('Threshold [DAC]')
     
    6498        make_outpath(file_path)
    6599        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"
    67103
    68104    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
    70109
    71110if __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
    74132    date = arguments['--date']
    75133    now = datetime.datetime.utcnow()
     
    78136        # need to get y,m,d of yesterday.
    79137        yesterday = now - datetime.timedelta(hours=24)
    80         plot_ratescan(yesterday)
     138        plot_ratescan(yesterday, arguments)
    81139    else:
    82140        # The user supplied a date-string, which we need to parse
     
    92150                print "Please choose a better date"
    93151       
    94             plot_ratescan(date)
     152            plot_ratescan(date, arguments)
    95153        except ValueError as e:
    96154            print e
Note: See TracChangeset for help on using the changeset viewer.