def __init__(self): ''' Constructor. ''' ChimeraObject.__init__(self) # # Reading in configuration parameters # config = ConfigParser.RawConfigParser() if os.path.exists( os.path.join(os.path.expanduser('~/.chimera'), 'tao.cfg')): config.read( os.path.join(os.path.expanduser('~/.chimera'), 'tao.cfg')) else: log.warning( 'No user defined configuration found at %s. Using default values.' % (os.path.join(os.path.expanduser('~/.chimera'), 'tao.cfg'))) config.read(os.path.join(os.path.join(cfgpath, '../../tao.cfg'))) # # Setting configuration parameters # self.stdFlag = config.get('TargetsInfo', 'Standard') self.sciFlag = config.get('TargetsInfo', 'Science') self.stdUser = config.get('TargetsInfo', 'stdUser') self.sciUser = config.get('TargetsInfo', 'sciUser') self.stdFile = config.get('TargetsInfo', 'stdFile') self.sciFile = config.get('TargetsInfo', 'sciFile') self.PATH = os.path.expanduser(config.get('Local', 'PATH')) self.sitelat = float(config.get('Site', 'sitelat')) self.sitelong = float(config.get('Site', 'sitelong')) self.sunMaxAlt = float(config.get('Site', 'sunMaxAlt')) self.filters = [ i.replace(' ', '') for i in config.get('Instrument', 'Filters').split(',') ] self.nfilters = len(self.filters) self.stdExpTime = [ float(i) for i in config.get('TargetsInfo', 'stdExpTime').split(',') ] self.sciExpTime = [ float(i) for i in config.get('TargetsInfo', 'sciExpTime').split(',') ] self.stdMaxAirmass = float(config.get('TargetsInfo', 'stdMaxAirmass')) # # These are time bins, which breaks the night in timely intervals. Bins is the time at the begining of the bin # and Mask is percent full. self.obsTimeBins = [] self.obsTimeMask = [] self.isJD = False
def create(data, imageRequest=None, filename=None): if imageRequest: try: filename = imageRequest["filename"] except KeyError: if not filename: raise TypeError( "Invalid filename, you must pass filename=something" "or a valid ImageRequest object") filename = ImageUtil.makeFilename(filename) hdu = pyfits.PrimaryHDU(data) headers = [("DATE", ImageUtil.formatDate(dt.datetime.now()), "date of file creation"), ("CREATOR", _chimera_name_, _chimera_long_description_)] #TODO: Implement BITPIX support hdu.scale('int16', '', bzero=32768, bscale=1) if imageRequest: headers += imageRequest.headers for header in headers: try: hdu.header.update(*header) except Exception, e: log.warning("Couldn't add %s: %s" % (str(header), str(e)))
def create (data, imageRequest=None, filename=None): if imageRequest: try: filename = imageRequest["filename"] except KeyError: if not filename: raise TypeError("Invalid filename, you must pass filename=something" "or a valid ImageRequest object") filename = ImageUtil.makeFilename(filename) hdu = pyfits.PrimaryHDU(data) headers = [("DATE", ImageUtil.formatDate(dt.datetime.utcnow()), "date of file creation"), ("CREATOR", _chimera_name_, _chimera_long_description_)] #TODO: Implement BITPIX support hdu.scale('int16', '', bzero=32768, bscale=1) if imageRequest: headers += imageRequest.headers for header in headers: try: hdu.header.update(*header) except Exception, e: log.warning("Couldn't add %s: %s" % (str(header), str(e)))
def _getHeaders(self, manager, proxies): for proxyurl in proxies: try: proxy = manager.getProxy(proxyurl) proxyLoc = str(proxy.getLocation()) if proxyLoc not in self._accum_from: self._accum_from.append(proxyLoc) self.headers += proxy.getMetadata(self) except Exception, e: log.warning('Unable to get metadata from %s' % (proxyurl)) print ''.join(Pyro.util.getPyroTraceback(e))
def _fetchPreHeaders (self, manager): auto = [] if self.auto_collect_metadata: for cls in ('Site', 'Camera', 'Dome', 'FilterWheel', 'Focuser', 'Telescope'): locations = manager.getResourcesByClass(cls) if len(locations) == 1: auto.append(str(locations[0])) elif len(locations) == 0: log.warning("No %s available, header would be incomplete." % cls) else: log.warning("More than one %s available, header may be incorrect. Using the first %s." % (cls, cls)) auto.append(str(locations[0])) self._getHeaders(manager, auto+self.metadataPre)
def __init__(self): ''' Constructor. ''' ChimeraObject.__init__(self) # # Reading in configuration parameters # config = ConfigParser.RawConfigParser() if os.path.exists(os.path.join(os.path.expanduser('~/.chimera'),'tao.cfg')): config.read(os.path.join(os.path.expanduser('~/.chimera'),'tao.cfg')) else: log.warning('No user defined configuration found at %s. Using default values.'%(os.path.join(os.path.expanduser('~/.chimera'),'tao.cfg'))) config.read(os.path.join(os.path.join(cfgpath,'../../tao.cfg'))) # # Setting configuration parameters # self.stdFlag = config.get('TargetsInfo', 'Standard') self.sciFlag = config.get('TargetsInfo', 'Science') self.stdUser = config.get('TargetsInfo', 'stdUser') self.sciUser = config.get('TargetsInfo', 'sciUser') self.stdFile = config.get('TargetsInfo', 'stdFile') self.sciFile = config.get('TargetsInfo', 'sciFile') self.PATH = os.path.expanduser(config.get('Local', 'PATH')) self.sitelat = float(config.get('Site','sitelat')) self.sitelong = float(config.get('Site','sitelong')) self.sunMaxAlt = float(config.get('Site','sunMaxAlt')) self.filters = [i.replace(' ', '') for i in config.get('Instrument', 'Filters').split(',')] self.nfilters = len(self.filters) self.stdExpTime = [float(i) for i in config.get('TargetsInfo', 'stdExpTime').split(',')] self.sciExpTime = [float(i) for i in config.get('TargetsInfo', 'sciExpTime').split(',')] self.stdMaxAirmass = float(config.get('TargetsInfo','stdMaxAirmass')) # # These are time bins, which breaks the night in timely intervals. Bins is the time at the begining of the bin # and Mask is percent full. self.obsTimeBins = [] self.obsTimeMask = [] self.isJD = False
def _fetchPreHeaders(self, manager): auto = [] if self.auto_collect_metadata: for cls in ('Site', 'Camera', 'Dome', 'FilterWheel', 'Focuser', 'Telescope'): locations = manager.getResourcesByClass(cls) if len(locations) == 1: auto.append(str(locations[0])) elif len(locations) == 0: log.warning( "No %s available, header would be incomplete." % cls) else: log.warning( "More than one %s available, header may be incorrect. Using the first %s." % (cls, cls)) auto.append(str(locations[0])) self._getHeaders(manager, auto + self.metadataPre)
def selectStandardTargets(self,nstars=3,nairmass=3): ''' Based on configuration parameters, select 'nstars' standard stars to run scheduler on a specified Julian Day. Ideally you will select standard stars before your science targets so not to have a full queue. Usually standard stars are observed more than once a night at different airmasses. The user can control this parameter with nairmass and the script will try to take care of the rest. ''' session = Session() # First of all, standard stars can be obsered multiple times in sucessive nights. I will mark all # stars an unscheduled. targets = session.query(Targets).filter(Targets.scheduled == True).filter(Targets.type == self.stdFlag) for target in targets: target.scheduled = False session.commit() # [To be done] Reject objects that are close to the moon # Selecting standard stars is not only searching for the higher in that time but select stars than can be observed at 3 # or more (nairmass) different airmasses. It is also important to select stars with different colors (but this will be # taken care in the future). if nairmass*nstars > len(self.obsTimeBins): log.warning('Requesting more stars/observations than it will be possible to schedule. Decreasing number of requests to fit in the night.') nstars = len(self.obsTimeBins)/nairmass obsStandars = np.zeros(len(self.obsTimeBins))-1 # first selection of observable standards for tbin,time in enumerate(self.obsTimeBins): if self.obsTimeMask[tbin] < 1.0: # 1 - Select objects from database that where not scheduled yet (standard stars may be repited) # that fits our observing night targets = session.query(Targets).filter(Targets.scheduled == 0).filter(Targets.type == self.stdFlag) lst = _skysub.lst(time,self.sitelong) #*360./24. alt = np.array([_skysub.altit(target.targetDec,lst - target.targetRa,self.sitelat)[0] for target in targets]) stg = alt.argmax() log.info('Selecting %s'%(targets[stg])) # Marking target as schedule tst = session.query(Targets).filter(Targets.id == targets[stg].id) for t in tst: t.scheduled = True session.commit() obsStandars[tbin] = t.id else: log.info('Bin already filled up with observations. Skipping...') if len(obsStandars[obsStandars >= 0]) < nstars: log.warning('Could not find %i suitable standard stars in catalog. Only %i where found.'%(nstars,len(obsStandars[obsStandars >= 0]))) # # Unmarking potential targets as scheduled # for id in obsStandars[obsStandars >= 0]: target = session.query(Targets).filter(Targets.id == id) for t in target: t.scheduled = False session.commit() tbin+=1 # # Preparing a grid of altitudes for each target for each observing window # amGrid = np.zeros(len(obsStandars)*len(obsStandars)).reshape(len(obsStandars),len(obsStandars)) for i in np.arange(len(obsStandars))[obsStandars >= 0]: target = session.query(Targets).filter(Targets.id == obsStandars[i])[0] for j in range(len(obsStandars)): lst = _skysub.lst(self.obsTimeBins[j],self.sitelong) amGrid[i][j] = _skysub.true_airmass(_skysub.secant_z(_skysub.altit(target.targetDec,lst - target.targetRa,self.sitelat)[0])) if amGrid[i][j] < 0: amGrid [i][j] = 99. # # Build a grid mask that specifies the position in time each target should be observed. This means that, when # selecting a single target we ocuppy more than one, non consecutive, position in the night. This grid shows where are these # positions. # obsMask = np.zeros(len(obsStandars)*len(obsStandars),dtype=np.bool).reshape(len(obsStandars),len(obsStandars)) for i in np.arange(len(obsStandars))[obsStandars >= 0]: amObs = np.linspace(amGrid[i].min(),self.stdMaxAirmass,nairmass) # requested aimasses dam = np.mean(np.abs(amGrid[i][amGrid[i]<self.stdMaxAirmass][1:] - amGrid[i][amGrid[i]<self.stdMaxAirmass][:-1])) # how much airmass changes in average for j,am in enumerate(amObs): # Mark positions where target is at specified airmass if j == 0: obsMask[i] = np.bitwise_or(obsMask[i],amGrid[i] == am) else: obsMask[i] = np.bitwise_or(obsMask[i],np.bitwise_and(amGrid[i]>am-dam,amGrid[i]<am+dam)) #print amGrid[i][np.where(obsMask[i])] # # Now it is time to actually select the targets. It will start with the first target and then try the others # until it find enough standard stars, as specified by the user. # # Para cada bin em tempo, varro o bin em massa de ar por coisas observaveis. Se acho um, vejo se posso agendar # os outros bins. Se sim, marco o alvo para observacao, se nao, passo para o proximo. Repito ate completar a # lista de alvos # obsMaskTimeGrid = np.zeros(len(obsStandars),dtype=np.bool) nrequests = 0 reqId = np.zeros(nstars,dtype=np.int)-1 for tbin,time in enumerate(self.obsTimeBins[:-1]): # Evaluates if time slots are all available. If yes, mark orbservation and ocuppy slots. if ( (not obsMaskTimeGrid[obsMask[tbin]].any()) and (len(amGrid[tbin][obsMask[tbin]])>=nairmass) ): obsMaskTimeGrid = np.bitwise_or(obsMaskTimeGrid,obsMask[tbin]) reqId[nrequests] = tbin nrequests += 1 if nrequests >= nstars: break # Finally, requesting observations for id in reqId[reqId >= 0]: target = session.query(Targets).filter(Targets.id == obsStandars[id])[0] secz = amGrid[id][obsMask[id]] seczreq = np.zeros(nairmass,dtype=np.bool) amObs = np.linspace(amGrid[id].min(),self.stdMaxAirmass,nairmass) # requested aimasses for i,obstime in enumerate(self.obsTimeBins[obsMask[id]]): sindex = np.abs(amObs-secz[i]).argmin() if not seczreq[sindex]: log.info('Requesting observations of %s @airmass=%4.2f @mjd=%.3f...'%(target.name,secz[i],obstime-2400000.5)) seczreq[sindex] = True target.scheduled = True session.commit() self.addObservation(target,obstime) self.obsTimeMask[obsMask[id]] = 1.0 #print self.obsTimeBins[obsMask[id]] #print #print i return 0 #targets
def selectStandardTargets(self, nstars=3, nairmass=3): ''' Based on configuration parameters, select 'nstars' standard stars to run scheduler on a specified Julian Day. Ideally you will select standard stars before your science targets so not to have a full queue. Usually standard stars are observed more than once a night at different airmasses. The user can control this parameter with nairmass and the script will try to take care of the rest. ''' session = Session() # First of all, standard stars can be obsered multiple times in sucessive nights. I will mark all # stars an unscheduled. targets = session.query(Targets).filter( Targets.scheduled == True).filter(Targets.type == self.stdFlag) for target in targets: target.scheduled = False session.commit() # [To be done] Reject objects that are close to the moon # Selecting standard stars is not only searching for the higher in that time but select stars than can be observed at 3 # or more (nairmass) different airmasses. It is also important to select stars with different colors (but this will be # taken care in the future). if nairmass * nstars > len(self.obsTimeBins): log.warning( 'Requesting more stars/observations than it will be possible to schedule. Decreasing number of requests to fit in the night.' ) nstars = len(self.obsTimeBins) / nairmass obsStandars = np.zeros(len( self.obsTimeBins)) - 1 # first selection of observable standards for tbin, time in enumerate(self.obsTimeBins): if self.obsTimeMask[tbin] < 1.0: # 1 - Select objects from database that where not scheduled yet (standard stars may be repited) # that fits our observing night targets = session.query(Targets).filter( Targets.scheduled == 0).filter( Targets.type == self.stdFlag) lst = _skysub.lst(time, self.sitelong) #*360./24. alt = np.array([ _skysub.altit(target.targetDec, lst - target.targetRa, self.sitelat)[0] for target in targets ]) stg = alt.argmax() log.info('Selecting %s' % (targets[stg])) # Marking target as schedule tst = session.query(Targets).filter( Targets.id == targets[stg].id) for t in tst: t.scheduled = True session.commit() obsStandars[tbin] = t.id else: log.info( 'Bin already filled up with observations. Skipping...') if len(obsStandars[obsStandars >= 0]) < nstars: log.warning( 'Could not find %i suitable standard stars in catalog. Only %i where found.' % (nstars, len(obsStandars[obsStandars >= 0]))) # # Unmarking potential targets as scheduled # for id in obsStandars[obsStandars >= 0]: target = session.query(Targets).filter(Targets.id == id) for t in target: t.scheduled = False session.commit() tbin += 1 # # Preparing a grid of altitudes for each target for each observing window # amGrid = np.zeros(len(obsStandars) * len(obsStandars)).reshape( len(obsStandars), len(obsStandars)) for i in np.arange(len(obsStandars))[obsStandars >= 0]: target = session.query(Targets).filter( Targets.id == obsStandars[i])[0] for j in range(len(obsStandars)): lst = _skysub.lst(self.obsTimeBins[j], self.sitelong) amGrid[i][j] = _skysub.true_airmass( _skysub.secant_z( _skysub.altit(target.targetDec, lst - target.targetRa, self.sitelat)[0])) if amGrid[i][j] < 0: amGrid[i][j] = 99. # # Build a grid mask that specifies the position in time each target should be observed. This means that, when # selecting a single target we ocuppy more than one, non consecutive, position in the night. This grid shows where are these # positions. # obsMask = np.zeros(len(obsStandars) * len(obsStandars), dtype=np.bool).reshape(len(obsStandars), len(obsStandars)) for i in np.arange(len(obsStandars))[obsStandars >= 0]: amObs = np.linspace(amGrid[i].min(), self.stdMaxAirmass, nairmass) # requested aimasses dam = np.mean( np.abs(amGrid[i][amGrid[i] < self.stdMaxAirmass][1:] - amGrid[i][amGrid[i] < self.stdMaxAirmass][:-1]) ) # how much airmass changes in average for j, am in enumerate(amObs): # Mark positions where target is at specified airmass if j == 0: obsMask[i] = np.bitwise_or(obsMask[i], amGrid[i] == am) else: obsMask[i] = np.bitwise_or( obsMask[i], np.bitwise_and(amGrid[i] > am - dam, amGrid[i] < am + dam)) #print amGrid[i][np.where(obsMask[i])] # # Now it is time to actually select the targets. It will start with the first target and then try the others # until it find enough standard stars, as specified by the user. # # Para cada bin em tempo, varro o bin em massa de ar por coisas observaveis. Se acho um, vejo se posso agendar # os outros bins. Se sim, marco o alvo para observacao, se nao, passo para o proximo. Repito ate completar a # lista de alvos # obsMaskTimeGrid = np.zeros(len(obsStandars), dtype=np.bool) nrequests = 0 reqId = np.zeros(nstars, dtype=np.int) - 1 for tbin, time in enumerate(self.obsTimeBins[:-1]): # Evaluates if time slots are all available. If yes, mark orbservation and ocuppy slots. if ((not obsMaskTimeGrid[obsMask[tbin]].any()) and (len(amGrid[tbin][obsMask[tbin]]) >= nairmass)): obsMaskTimeGrid = np.bitwise_or(obsMaskTimeGrid, obsMask[tbin]) reqId[nrequests] = tbin nrequests += 1 if nrequests >= nstars: break # Finally, requesting observations for id in reqId[reqId >= 0]: target = session.query(Targets).filter( Targets.id == obsStandars[id])[0] secz = amGrid[id][obsMask[id]] seczreq = np.zeros(nairmass, dtype=np.bool) amObs = np.linspace(amGrid[id].min(), self.stdMaxAirmass, nairmass) # requested aimasses for i, obstime in enumerate(self.obsTimeBins[obsMask[id]]): sindex = np.abs(amObs - secz[i]).argmin() if not seczreq[sindex]: log.info( 'Requesting observations of %s @airmass=%4.2f @mjd=%.3f...' % (target.name, secz[i], obstime - 2400000.5)) seczreq[sindex] = True target.scheduled = True session.commit() self.addObservation(target, obstime) self.obsTimeMask[obsMask[id]] = 1.0 #print self.obsTimeBins[obsMask[id]] #print #print i return 0 #targets