Commit f2e34d6c authored by Monica Rainer's avatar Monica Rainer
Browse files

Docopt implemented

parent ac028189
""" """
GOFIO DRS GOFIO DRS
Last modified: 2017-03-07
Written by Monica Rainer Written by Monica Rainer
Usage:
gofioDRS.py -h
gofioDRS.py [-g=<gofio_config>]
gofioDRS.py <date> [--dark --flat --une --fp --only_calib --use_flat=<flag>]
gofioDRS.py <date> <calib_date> [--dark --flat --une --fp --only_calib --use_flat=<flag>]
Options:
-h,--help : show this screen
-g,--cfg : path of the configuration file (optional)
date : date to be reduced, no configuration file possible (always first input)
calib_date : calibration date to be used (always second input)
--dark : darks are reduced
--flat : flats are reduced
--une : U-Ne lamps are reduced
--fp : FP lamps are reduced
--only_calib : only calibration are reduced, no science images
--use_flat=<flag> : flat-field is removed, options are global/order/nor [Default: order]
""" """
import os, glob, sys, time import os, glob, sys, time
from drslib.config import CONFIG from docopt import docopt
from drslib.config import CONFIG, read_usr_config
from logger.logger import DrsLogger from logger.logger import DrsLogger
from drslib import db, rawfiles, darkframes, flatframes, wlframes, nodding, stare, varie from drslib import db, rawfiles, darkframes, flatframes, wlframes, nodding, stare, varie
...@@ -15,11 +35,43 @@ from drslib import db, rawfiles, darkframes, flatframes, wlframes, nodding, star ...@@ -15,11 +35,43 @@ from drslib import db, rawfiles, darkframes, flatframes, wlframes, nodding, star
from watchdog.observers import Observer from watchdog.observers import Observer
from watchdog.events import PatternMatchingEventHandler from watchdog.events import PatternMatchingEventHandler
# first argument: night to be reduced, using the calibration in the database
# to be used at the end of the night, after the calibration lamp has been # read docopt_arg and act accordingly
# observed and put in the database
try: docopt_args = docopt(__doc__)
CONFIG['DATE'] = sys.argv[1] #print docopt_args
if docopt_args['--cfg']:
try:
USRCONFIG = read_usr_config(docopt_args['-g'])
except:
try:
USRCONFIG = read_usr_config(docopt_args['--cfg'])
except:
USRCONFIG = {}
USRCONFIG['OFFLINE'] = False
if USRCONFIG['OFFLINE']:
for key in USRCONFIG.keys():
CONFIG[key] = USRCONFIG[key]
CONFIG['RAW_DIR'] = os.path.join(CONFIG['BASE_RAW'],CONFIG['DATE'])
CONFIG['OFFLINE_DIR'] = os.path.join(CONFIG['BASE_RED_DIR'],CONFIG['DATE'])
CONFIG['RED_DIR'] = os.path.join(CONFIG['OFFLINE_DIR'],'offline')
CONFIG['RED_CALIB'] = os.path.join(CONFIG['RED_DIR'],'CALIB')
CONFIG['RED_STR'] = os.path.join(CONFIG['RED_DIR'],'STR')
CONFIG['LOG_FILE'] = os.path.join(CONFIG['RED_DIR'], 'drs.log')
CONFIG['RAMP_NAME'] = 'ramps' + CONFIG['DATE'] + '.db'
CONFIG['DB_RAMP'] = os.path.join(CONFIG['BASE_RAMP'],CONFIG['RAMP_NAME'])
CONFIG['DB_OFFLINE'] = ''.join(('db_',CONFIG['DATE'],'_offline.db'))
CONFIG['DB_OFFLINE_PATH'] = os.path.join(CONFIG['WEBUI_DB_DIR'], CONFIG['DB_OFFLINE'])
CONFIG['DB_NIGHT'] = CONFIG['DB_OFFLINE']
CONFIG['DB_NIGHT_PATH'] = CONFIG['DB_OFFLINE_PATH']
if docopt_args['<date>']:
CONFIG['DATE'] = docopt_args['<date>']
CONFIG['OFFLINE'] = True CONFIG['OFFLINE'] = True
CONFIG['RAW_DIR'] = os.path.join(CONFIG['BASE_RAW'],CONFIG['DATE']) CONFIG['RAW_DIR'] = os.path.join(CONFIG['BASE_RAW'],CONFIG['DATE'])
CONFIG['OFFLINE_DIR'] = os.path.join(CONFIG['BASE_RED_DIR'],CONFIG['DATE']) CONFIG['OFFLINE_DIR'] = os.path.join(CONFIG['BASE_RED_DIR'],CONFIG['DATE'])
...@@ -27,9 +79,18 @@ try: ...@@ -27,9 +79,18 @@ try:
CONFIG['RED_CALIB'] = os.path.join(CONFIG['RED_DIR'],'CALIB') CONFIG['RED_CALIB'] = os.path.join(CONFIG['RED_DIR'],'CALIB')
CONFIG['RED_STR'] = os.path.join(CONFIG['RED_DIR'],'STR') CONFIG['RED_STR'] = os.path.join(CONFIG['RED_DIR'],'STR')
CONFIG['LOG_FILE'] = os.path.join(CONFIG['RED_DIR'], 'drs.log') CONFIG['LOG_FILE'] = os.path.join(CONFIG['RED_DIR'], 'drs.log')
CONFIG['DO_CALIB'] = {'dark': docopt_args['--dark'], 'flat': docopt_args['--flat'], 'une': docopt_args['--une'], 'fp': docopt_args['--fp'], 'only_calib': docopt_args['--only_calib']}
#CONFIG['DO_CALIB'] = {'dark':True,'flat':True,'une':True,'fp':True,'only_calib':True} #CONFIG['DO_CALIB'] = {'dark':True,'flat':True,'une':True,'fp':True,'only_calib':True}
CONFIG['DO_CALIB'] = {'dark':False,'flat':False,'une':False,'fp':False,'only_calib':False} #CONFIG['DO_CALIB'] = {'dark':False,'flat':False,'une':False,'fp':False,'only_calib':False}
#CONFIG['USE_FLAT'] = {'global':False, 'order':False, 'nor':False} #CONFIG['USE_FLAT'] = {'global':False, 'order':False, 'nor':False}
if docopt_args['--use_flat'] == 'global':
CONFIG['USE_FLAT'] = {'global':True, 'order':False, 'nor':False}
elif docopt_args['--use_flat'] == 'order':
CONFIG['USE_FLAT'] = {'global':False, 'order':True, 'nor':False}
elif docopt_args['--use_flat'] == 'nor':
CONFIG['USE_FLAT'] = {'global':False, 'order':False, 'nor':True}
else:
CONFIG['USE_FLAT'] = {'global':False, 'order':False, 'nor':False}
maskc = ''.join(('GIANOB_MASKC_',CONFIG['DATE'],'.fits')) maskc = ''.join(('GIANOB_MASKC_',CONFIG['DATE'],'.fits'))
CONFIG['MASK_C'] = os.path.join(CONFIG['RES_DIR'], maskc) CONFIG['MASK_C'] = os.path.join(CONFIG['RES_DIR'], maskc)
...@@ -39,17 +100,18 @@ try: ...@@ -39,17 +100,18 @@ try:
CONFIG['DB_NIGHT'] = CONFIG['DB_OFFLINE'] CONFIG['DB_NIGHT'] = CONFIG['DB_OFFLINE']
CONFIG['DB_NIGHT_PATH'] = CONFIG['DB_OFFLINE_PATH'] CONFIG['DB_NIGHT_PATH'] = CONFIG['DB_OFFLINE_PATH']
except:
pass
# second argument: how to query the calibration database # second argument: how to query the calibration database
# to be set if the the user wants to reduce the night using # to be set if the the user wants to reduce the night using
# another night's calibrations # another night's calibrations
try: if docopt_args['<calib_date>']:
CONFIG['DATE'] = sys.argv[2] CONFIG['DATE'] = docopt_args['<calib_date>']
except:
pass
#print docopt_args
print CONFIG['DATE']
print CONFIG['DO_CALIB']
print CONFIG['USE_FLAT']
# remove the mask with the order position (if it exists) # remove the mask with the order position (if it exists)
# it will be re-build with the correct flat-field # it will be re-build with the correct flat-field
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment