def get_data(self, date=None, timedelta='30m'): self.set_date(date) tmax = self.date tmin = self.date - pd.Timedelta(timedelta) if self.df is None: # Don't want to create the DB each time? try: db = Database() db.connect() query =""" select date, qc_fwhm as fwhm, airmass, filter from exposure where date > '%s' and date < '%s' --and filter != 'VR' and qc_fwhm is not NULL and qc_fwhm is not NULL and qc_fwhm > 0 """%(tmin, tmax) logging.debug(query) raw = db.query2rec(query) except Exception as e: logging.warn("Couldn't connect to database:\n%s"%str(e)) dtype=[('date', '<M8[ns]'), ('fwhm', '<f8'), ('airmass', '<f8'), ('filter', 'S4')] raw = np.recarray(0,dtype=dtype) else: sel = (self.df.index > tmin) & (self.df.index < tmax) raw = self.df[sel].to_records() return raw
def survey_coverage(nside=1024, bands=['g', 'r', 'i', 'z'], propid=None, exptime=30, teff=0.01): from obztak.utils.database import Database import healpy as hp bands = np.atleast_1d(bands) db = Database() db.connect() params = dict(propid='') if propid: params['propid'] = "(propid = '%s')" % propid else: params['propid'] = "(propid not like '%-9999')" params['exptime'] = "(exptime > %s)" % exptime params['teff'] = "not (qc_teff < %s)" % teff params['filter'] = "filter in (%s)" % (','.join( ["'%s'" % b for b in bands])) query = """select id as expnum, telra as ra, teldec as dec, filter, propid, exptime from exposure where discard = False and delivered = True and flavor = 'object' and %(propid)s and %(exptime)s and %(teff)s and %(filter)s; """ % params logging.debug(query) data = db.query2rec(query) out = dict() for b in bands: hpxmap = np.zeros(hp.nside2npix(nside)) d = data[data['filter'] == b] theta = np.radians(90. - d['dec']) phi = np.radians(d['ra']) vec = hp.ang2vec(theta, phi) for i, v in enumerate(vec): if i % 10000 == 0: logging.info('%i/%i' % (i, len(vec))) pix = hp.query_disc(nside, v, radius=np.radians(constants.DECAM)) hpxmap[pix] += d[i]['exptime'] hpxmap[np.where(hpxmap == 0)] = hp.UNSEEN out[b] = hpxmap return out
def get_data(self, date=None, timedelta='30m'): self.set_date(date) tmax = self.date tmin = self.date - pd.Timedelta(timedelta) if self.df is None: # Don't want to create the DB each time? db = Database(self.db) db.connect() query =""" select date, dimm2see as fwhm from exposure where date > '%s' and date < '%s' and dimm2see is not NULL """%(tmin, tmax) logging.debug(query) raw = db.query2rec(query) else: sel = (self.df.index > tmin) & (self.df.index < tmax) raw = self.df[sel].to_records() return raw