#!/usr/bin/python from rts2saf.log import Logger from rts2saf.rts2exec import Rts2Exec from rts2.json import JSONProxy class Args(object): def __init__(self): pass args=Args() args.toPath='/var/log' args.logfile= 'rts2-debug' args.level='DEBUG' debug=False logger= Logger(debug=debug, args=args ).logger proxy=JSONProxy() ex= Rts2Exec(debug=debug, proxy=proxy, logger=logger) ex.reeanableEXEC() logger.info('rts2saf_reenable_exec.py: reenabled EXEC')
#!/usr/bin/python from rts2saf.log import Logger from rts2saf.rts2exec import Rts2Exec from rts2.json import JSONProxy class Args(object): def __init__(self): pass args = Args() args.toPath = '/var/log' args.logfile = 'rts2-debug' args.level = 'DEBUG' debug = False logger = Logger(debug=debug, args=args).logger proxy = JSONProxy() ex = Rts2Exec(debug=debug, proxy=proxy, logger=logger) ex.reeanableEXEC() logger.info('rts2saf_reenable_exec.py: reenabled EXEC')
except Exception, e: logger.error('rts2saf_focus: no JSON connection for: {0}, {1}, {2}'.format(rt.cfg['URL'],rt.cfg['RTS2_HTTPD_USERNAME'],rt.cfg['PASSWORD'])) sys.exit(1) # create all devices # attention: .create() at the end # filters are not yet devices # check always True, we need to set limits either from device or from configuration foc= CreateFocuser(debug=args.debug, proxy=proxy, check=True, rangeFocToff=args.focRange, blind=args.blind, verbose=args.verbose, rt=rt, logger=logger).create() if foc==None or not isinstance(foc, Focuser): logger.error('rts2saf_focus: could not create object for focuser: {}, exiting'.format(rt.cfg['FOCUSER_NAME'])) sys.exit(1) if args.focDef: foc.writeFocDef(proxy=proxy, focDef=args.focDef) logger.info('rts2saf_focus: {0} FOC_DEF: {1} set'.format(foc.name,args.focDef)) filters= CreateFilters(debug=args.debug, proxy=proxy, check=args.checkConfig, verbose=args.verbose, rt=rt, logger=logger).create() ftwc = CreateFilterWheels(filters=filters, foc=foc, debug=args.debug, proxy=proxy, check=args.checkConfig, blind=args.blind, verbose=args.verbose, rt=rt, logger=logger) ftws = ftwc.create() # at least one even if it is FAKE_FTW if ftws==None or not isinstance(ftws[0], FilterWheel): logger.error('rts2saf_focus: could not create object for filter wheel: {}, exiting'.format(rt.cfg['FILTER WHEELS INUSE'])) sys.exit(1) # offsets must be fetched at this point, but not in unittest ccd= CreateCCD(debug=args.debug, proxy=proxy, ftws=ftws, check=args.checkConfig, fetchOffsets=True, verbose=args.verbose, rt=rt, logger=logger).create() if ccd==None or not isinstance(ccd, CCD): logger.error('rts2saf_focus: could not create object for CCD: {}, exiting'.format(rt.cfg['CCD_NAME'])) sys.exit(1) # filter wheel offsets are at this point read back from CCD
proxy=proxy, check=True, rangeFocToff=args.focRange, blind=args.blind, verbose=args.verbose, rt=rt, logger=logger).create() if foc == None or not isinstance(foc, Focuser): logger.error( 'rts2saf_focus: could not create object for focuser: {}, exiting'. format(rt.cfg['FOCUSER_NAME'])) sys.exit(1) if args.focDef: foc.writeFocDef(proxy=proxy, focDef=args.focDef) logger.info('rts2saf_focus: {0} FOC_DEF: {1} set'.format( foc.name, args.focDef)) filters = CreateFilters(debug=args.debug, proxy=proxy, check=args.checkConfig, verbose=args.verbose, rt=rt, logger=logger).create() ftwc = CreateFilterWheels(filters=filters, foc=foc, debug=args.debug, proxy=proxy, check=args.checkConfig, blind=args.blind, verbose=args.verbose, rt=rt,
except Exception, e: logger.error('rts2af_fwhm: sextractor failed on file: {0}\nerror from sex.sextract: {1}\nexiting'.format(args.fitsFn, e)) sys.exit(1) fwhmTreshold=rt.cfg['FWHM_LOWER_THRESH'] if args.fwhmThreshold: fwhmTreshold=args.fwhmThreshold if dataSxtr is None: logger.error('rts2af_fwhm: failed on file: {0}, exiting'.format(args.fitsFn)) sys.exit(1) if( dataSxtr.fwhm <= fwhmTreshold): try: logger.info('rts2af_fwhm: no focus run queued, fwhm: {0:5.2f} < {1:5.2f} (thershold)'.format(float(dataSxtr.fwhm), float(fwhmTreshold))) except Exception, e: logger.info('rts2af_fwhm: no focus run queued, no FWHM calculated, error: {}'.format(e)) q = None rts2.createProxy(url=rt.cfg['URL'], username=rt.cfg['RTS2_HTTPD_USERNAME'], password=rt.cfg['PASSWORD']) try: q = rts2.Queue(rts2.json.getProxy(), args.queue) except Exception, e: logger.error('rts2af_fwhm: no queue named: {0}, doing nothing'.format(args.queue)) if q is not None: q.load() for x in q.entries: if x.get_target().name and 'OnTargetFocus' in x.get_target().name: q.clear()
# # if I can get the freaking modified cfg file to stop saying the syntax is wrong I can do this # # TODO double check to make sure astropy dir exists inside ASTROPY_XDG_CONFIG_HOME # # if rt.cfg['ASTROPY_XDG_CONFIG_HOME'] == None or rt.cfg['ASTROPY_XDG_CACHE_HOME'] == None: # # logger.error('Astropy problem: HOME env var does not exist and ASTROPY_XDG_CONFIG_HOME or ASTROPY_XDG_CACHE_Home not defined in config') # # sys.exit(1) # # else: # logger.error('Setting Astropy XDG paths') # os.environ['XDG_CONFIG_HOME'] = '/root/' # os.environ['XDG_CACHE_HOME'] = '/root/' # # from astropy.io.fits import getheader # if in config file is nothing specified it is a str if isinstance(rt.cfg['FILTERS_TO_EXCLUDE'], dict): ftNameS=rt.cfg['FILTERS_TO_EXCLUDE'].keys() # fitsHeaderName are in reality names of filter wheels # in the notation of CCD driver (FILTA, FILTB, ...) hdr = pyfits.open(fitsFn,'readonly')[0].header for fitsHeaderName in set(rt.cfg['FILTERS_TO_EXCLUDE'].values()): try: hdrv = hdr[fitsHeaderName] except Exception, e: continue if hdrv in ftNameS: logger.info('{0}: skipping FITS file: {1} due to filter wheel:{2}, contains filter:{3} (see config file)'.format(script, fitsFn, fitsHeaderName, hdrv)) sys.exit(1) imgp_analysis.run()
help=': %(default)s, calculate weighted means') args = parser.parse_args() if args.debug: args.level = 'DEBUG' args.toconsole = True # logger logger = Logger( debug=args.debug, args=args).logger # if you need to chage the log format do it here # hint to the user if defaultCfg in args.config: logger.info( 'rts2saf_focus: using default configuration file: {0}'.format( args.config)) # config rtc = Configuration(logger=logger) if not rtc.readConfiguration(fileName=args.config): logger.error( 'rts2saf_focus: exiting, wrong syntax, check the configuration file: {0}' .format(args.config)) sys.exit(1) # overwrite config defaults rtc.cfg['ANALYZE_FLUX'] = args.flux rtc.cfg['ANALYZE_ASSOC'] = args.associate rtc.cfg['ANALYZE_ASSOC_FRACTION'] = args.fractObjs rtc.cfg['FOCUSER_INTERVAL'] = args.focuserInterval
sys.exit(1) fwhmTreshold = rt.cfg['FWHM_LOWER_THRESH'] if args.fwhmThreshold: fwhmTreshold = args.fwhmThreshold if dataSxtr is None: logger.error('rts2af_fwhm: failed on file: {0}, exiting'.format( args.fitsFn)) sys.exit(1) if (dataSxtr.fwhm <= fwhmTreshold): try: logger.info( 'rts2af_fwhm: no focus run queued, fwhm: {0:5.2f} < {1:5.2f} (thershold)' .format(float(dataSxtr.fwhm), float(fwhmTreshold))) except Exception, e: logger.info( 'rts2af_fwhm: no focus run queued, no FWHM calculated, error: {}' .format(e)) q = None rts2.createProxy(url=rt.cfg['URL'], username=rt.cfg['USERNAME'], password=rt.cfg['PASSWORD']) try: q = rts2.Queue(rts2.json.getProxy(), args.queue) except Exception, e: logger.error( 'rts2af_fwhm: no queue named: {0}, doing nothing'.format(
parser.add_argument('--emptySlots', dest = 'emptySlots', action = 'store', default = None, type = str, nargs = '+', help = ': %(default)s, list of SPACE separated names of the empty slots') parser.add_argument('--focuser-interval', dest = 'focuserInterval', action = 'store', default = list(), type = int, nargs = '+', help = ': %(default)s, focuser position interval, positions out side this interval will be ignored') # ToDo parser.add_argument('--display-failures', dest = 'display_failures', action = 'store_true', default = False, help = ': %(default)s, display focus run where the fit failed') parser.add_argument('--means', dest = 'means', action = 'store_true', default = False, help = ': %(default)s, calculate weighted means') args = parser.parse_args() if args.debug: args.level = 'DEBUG' args.toconsole = True # logger logger = Logger(debug = args.debug, args = args).logger # if you need to chage the log format do it here # hint to the user if defaultCfg in args.config: logger.info('rts2saf_focus: using default configuration file: {0}'.format(args.config)) # config rtc = Configuration(logger = logger) if not rtc.readConfiguration(fileName=args.config): logger.error('rts2saf_focus: exiting, wrong syntax, check the configuration file: {0}'.format(args.config)) sys.exit(1) # overwrite config defaults rtc.cfg['ANALYZE_FLUX'] = args.flux rtc.cfg['ANALYZE_ASSOC'] = args.associate rtc.cfg['ANALYZE_ASSOC_FRACTION'] = args.fractObjs rtc.cfg['FOCUSER_INTERVAL'] = args.focuserInterval rtc.cfg['WEIGHTED_MEANS'] = args.means