def addObservation(self,target,obstime): session = Session() lineRe = re.compile('(?P<coord>(?P<ra>[\d:-]+)\s+(?P<dec>\+?[\d:-]+)\s+(?P<epoch>[\dnowNOWJjBb\.]+)\s+)?(?P<imagetype>[\w]+)' '\s+(?P<objname>\'([^\\n\'\\\\]|\\\\.)*\'|"([^\\n"\\\\]|\\\\.)*"|([^ \\n"\\\\]|\\\\.)*)\s+(?P<exposures>[\w\d\s:\*\(\),]*)') programs = [] entryFormat = '%(ra)s %(dec)s %(epoch)s %(obstype)s %(name)s %(exposures)s' p = Position.fromRaDec(target.targetRa,target.targetDec) ra = p.ra.HMS dec = p.dec.DMS filterExpt = self.sciExpTime if target.type == self.stdFlag: filterExpt = self.stdExpTime exposures = '1*(' for i in range(self.nfilters): exposures = exposures+'%s:%.0f, '%(self.filters[i],filterExpt[i]) exposures = exposures[:-2] exposures += ')' infos = { 'ra' : '%02.0f:%02.0f:%02.0f'%(ra[1],ra[2],ra[3]), 'dec': '%+03.0f:%02.0f:%02.0f'%(dec[0]*dec[1],dec[2],dec[3]), 'epoch' : 'J%.0f'%target.targetEpoch, 'obstype' : 'OBJECT', 'name' :target.name, 'exposures' : exposures } i = 0 line = entryFormat%infos matchs = lineRe.search(line) params = matchs.groupdict() position = None objname = None if params.get("coord", None): position = Position.fromRaDec(str(params['ra']), str(params['dec']), params['epoch']) imagetype = params['imagetype'].upper() objname = params['objname'].replace("\"", "") multiplier, exps = params['exposures'].split("*") try: multiplier = int(multiplier) except ValueError: multiplier = 1 exps = exps.replace("(", "").replace(")", "").strip().split(",") mjd = obstime - 2400000.5 for i in range(multiplier): program = Program(tid = target.id ,name="%s-%03d" % (objname.replace(" ", ""), i), slewAt=mjd,exposeAt=mjd+1./60./24.) self.log.info("# program: %s" % program.name) if imagetype == "OBJECT": if position: program.actions.append(Point(targetRaDec=position)) else: program.actions.append(Point(targetName=objname)) if imagetype == "FLAT": site = self._remoteManager.getProxy("/Site/0") flatPosition = Position.fromAltAz(site['flat_alt'], site['flat_az']) program.actions.append(Point(targetAltAz=flatPosition)) #if i == 0: # program.actions.append(AutoFocus(start=1500, end=3000, step=250, filter="R", exptime=10)) # program.actions.append(PointVerify(here=True)) for exp in exps: if exp.count(":") > 1: filter, exptime, frames = exp.strip().split(":") else: filter, exptime = exp.strip().split(":") frames = 1 if imagetype in ("OBJECT", "FLAT"): shutter = "OPEN" else: shutter = "CLOSE" if imagetype == "BIAS": exptime = 0 if imagetype in ("BIAS", "DARK"): filter = None self.log.info("%s %s %s filter=%s exptime=%s frames=%s" % (imagetype, objname, str(position), filter, exptime, frames)) program.actions.append(Expose(shutter=shutter, filename="%s-$DATE-$TIME" % objname.replace(" ", ""), filter=filter, frames=frames, exptime=exptime, imageType=imagetype, objectName=objname)) self.log.info("") programs.append(program) session.add_all(programs) session.commit()
def generateDatabase(options): with open(os.path.join(os.path.expanduser('~/'), options.filename), 'r') as stream: try: prgconfig = yaml.load(stream) except yaml.YAMLError as exc: manager.broadCast(exc) return -1 session = Session() programs = [] for prg in prgconfig['programs']: # process program program = Program() for key in prg.keys(): if hasattr(program,key) and key != 'actions': try: setattr(program,key,prg[key]) except: manager.broadCast('Could not set attribute %s = %s on Program' % (key,prg[key])) # self.out("# program: %s" % program.name) # process actions for actconfig in prg['actions']: act = actionDict[actconfig['action']]() # self.out('Action: %s' % actconfig['action']) if actconfig['action'] == 'point': if 'ra' in actconfig.keys() and 'dec' in actconfig.keys(): epoch = 'J2000' if 'epoch' not in actconfig.keys() else actconfig['epoch'] position = Position.fromRaDec(actconfig['ra'], actconfig['dec'], epoch) # self.out('Coords: %s' % position) act.targetRaDec = position # act = Point(targetRaDec=position) elif 'alt' in actconfig.keys() and 'az' in actconfig.keys(): position = Position.fromAltAz(actconfig['alt'], actconfig['az']) # self.out('Coords: %s' % position) act.targetAltAz = position else: # self.out('Target name: %s' % actconfig['name']) act.targetName = actconfig['name'] else: for key in actconfig.keys(): if hasattr(act,key) and key != 'action': # self.out('\t%s: %s' % (key,actconfig[key])) try: setattr(act,key,actconfig[key]) except: manager.broadCast('Could not set attribute %s = %s on action %s' % (key, actconfig[key], actconfig['action'])) program.actions.append(act) # self.out("") programs.append(program) # self.out("List contain %i programs" % len(programs)) session.add_all(programs) session.commit() return 0
def addObservation(self, target, obstime): session = Session() lineRe = re.compile( '(?P<coord>(?P<ra>[\d:-]+)\s+(?P<dec>\+?[\d:-]+)\s+(?P<epoch>[\dnowNOWJjBb\.]+)\s+)?(?P<imagetype>[\w]+)' '\s+(?P<objname>\'([^\\n\'\\\\]|\\\\.)*\'|"([^\\n"\\\\]|\\\\.)*"|([^ \\n"\\\\]|\\\\.)*)\s+(?P<exposures>[\w\d\s:\*\(\),]*)' ) programs = [] entryFormat = '%(ra)s %(dec)s %(epoch)s %(obstype)s %(name)s %(exposures)s' p = Position.fromRaDec(target.targetRa, target.targetDec) ra = p.ra.HMS dec = p.dec.DMS filterExpt = self.sciExpTime if target.type == self.stdFlag: filterExpt = self.stdExpTime exposures = '1*(' for i in range(self.nfilters): exposures = exposures + '%s:%.0f, ' % (self.filters[i], filterExpt[i]) exposures = exposures[:-2] exposures += ')' infos = { 'ra': '%02.0f:%02.0f:%02.0f' % (ra[1], ra[2], ra[3]), 'dec': '%+03.0f:%02.0f:%02.0f' % (dec[0] * dec[1], dec[2], dec[3]), 'epoch': 'J%.0f' % target.targetEpoch, 'obstype': 'OBJECT', 'name': target.name, 'exposures': exposures } i = 0 line = entryFormat % infos matchs = lineRe.search(line) params = matchs.groupdict() position = None objname = None if params.get("coord", None): position = Position.fromRaDec(str(params['ra']), str(params['dec']), params['epoch']) imagetype = params['imagetype'].upper() objname = params['objname'].replace("\"", "") multiplier, exps = params['exposures'].split("*") try: multiplier = int(multiplier) except ValueError: multiplier = 1 exps = exps.replace("(", "").replace(")", "").strip().split(",") mjd = obstime - 2400000.5 for i in range(multiplier): program = Program(tid=target.id, name="%s-%03d" % (objname.replace(" ", ""), i), slewAt=mjd, exposeAt=mjd + 1. / 60. / 24.) log.info("# program: %s" % program.name) if imagetype == "OBJECT": if position: program.actions.append(Point(targetRaDec=position)) else: program.actions.append(Point(targetName=objname)) if imagetype == "FLAT": site = self._remoteManager.getProxy("/Site/0") flatPosition = Position.fromAltAz(site['flat_alt'], site['flat_az']) program.actions.append(Point(targetAltAz=flatPosition)) #if i == 0: # program.actions.append(AutoFocus(start=1500, end=3000, step=250, filter="R", exptime=10)) # program.actions.append(PointVerify(here=True)) for exp in exps: if exp.count(":") > 1: filter, exptime, frames = exp.strip().split(":") else: filter, exptime = exp.strip().split(":") frames = 1 if imagetype in ("OBJECT", "FLAT"): shutter = "OPEN" else: shutter = "CLOSE" if imagetype == "BIAS": exptime = 0 if imagetype in ("BIAS", "DARK"): filter = None log.info("%s %s %s filter=%s exptime=%s frames=%s" % (imagetype, objname, str(position), filter, exptime, frames)) program.actions.append( Expose(shutter=shutter, filename="%s-$DATE-$TIME" % objname.replace(" ", ""), filter=filter, frames=frames, exptime=exptime, imageType=imagetype, objectName=objname)) log.info("") programs.append(program) session.add_all(programs) session.commit()
def process(check): import yaml from chimera.util.position import Position from chimera.util.coord import Coord from chimera.controllers.scheduler.model import (Session, Program, AutoFocus, AutoFlat, PointVerify, Point, Expose) actionDict = { 'autofocus': AutoFocus, 'autoflat': AutoFlat, 'pointverify': PointVerify, 'point': Point, 'expose': Expose, } manager = BaseResponse.manager # sched = ConfigureScheduler.scheduler # delete all programs session = Session() programs = session.query(Program).all() for program in programs: session.delete(program) session.commit() def generateDatabase(options): with open(os.path.join(os.path.expanduser('~/'), options.filename), 'r') as stream: try: prgconfig = yaml.load(stream) except yaml.YAMLError as exc: manager.broadCast(exc) raise except Exception, e: manager.broadCast( 'Exception trying to start scheduler: %s' % repr(e)) raise def _validateOffset(value): try: offset = Coord.fromAS(int(value)) except ValueError: offset = Coord.fromDMS(value) return offset session = Session() programs = [] for prg in prgconfig['programs']: # process program program = Program() for key in prg.keys(): if hasattr(program, key) and key != 'actions': try: setattr(program, key, prg[key]) except: manager.broadCast( 'Could not set attribute %s = %s on Program' % (key, prg[key])) # self.out("# program: %s" % program.name) # process actions for actconfig in prg['actions']: act = actionDict[actconfig['action']]() # self.out('Action: %s' % actconfig['action']) if actconfig['action'] == 'point': if 'ra' in actconfig.keys( ) and 'dec' in actconfig.keys(): epoch = 'J2000' if 'epoch' not in actconfig.keys( ) else actconfig['epoch'] position = Position.fromRaDec( actconfig['ra'], actconfig['dec'], epoch) # self.out('Coords: %s' % position) act.targetRaDec = position # act = Point(targetRaDec=position) elif 'alt' in actconfig.keys( ) and 'az' in actconfig.keys(): position = Position.fromAltAz( actconfig['alt'], actconfig['az']) # self.out('Coords: %s' % position) act.targetAltAz = position elif 'name' in actconfig: # self.out('Target name: %s' % actconfig['name']) act.targetName = actconfig['name'] elif 'offset' not in actconfig: manager.broadCast( 'Empty Point action. No target to point to or offset to perform!' ) continue if 'offset' in actconfig: if 'north' in actconfig['offset']: offset = _validateOffset( actconfig['offset']['north']) act.offsetNS = offset elif 'south' in actconfig['offset']: offset = _validateOffset( actconfig['offset']['south']) act.offsetNS = Coord.fromAS(-offset.AS) if 'west' in actconfig['offset']: offset = _validateOffset( actconfig['offset']['west']) act.offsetEW = offset elif 'east' in actconfig['offset']: offset = _validateOffset( actconfig['offset']['east']) act.offsetEW = Coord.fromAS(-offset.AS) else: for key in actconfig.keys(): if hasattr(act, key) and key != 'action': # self.out('\t%s: %s' % (key,actconfig[key])) try: setattr(act, key, actconfig[key]) except: manager.broadCast( 'Could not set attribute %s = %s on action %s' % (key, actconfig[key], actconfig['action'])) program.actions.append(act) # self.out("") programs.append(program) # self.out("List contain %i programs" % len(programs)) session.add_all(programs) session.commit() return 0