Coverage for python/lsst/sims/skybrightness/allSkyDB.py : 11%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1from builtins import zip
2import numpy as np
3import sqlalchemy as sqla
4import os
5from lsst.utils import getPackageDir
7# Tools for using an all-sky sqlite DB with cannon and photodiode data from the site.
10def allSkyDB(dateID, sqlQ=None, dtypes=None, dbAddress=None, filt='R'):
11 """
12 Take in a dateID (that corresponds to a single MJD, and
13 return the star and sky magnitudes in a numpy structured array.
14 """
15 if dbAddress is None:
16 dataPath = getPackageDir('sims_skybrightness_data')
17 dbAddress = 'sqlite:///'+os.path.join(dataPath, 'photometry', 'skydata.sqlite')
18 if sqlQ is None:
19 sqlQ = 'select stars.ra, stars.dec, obs.alt, obs.starMag, obs.sky, obs.filter from obs, stars where obs.starID = stars.ID and obs.filter = "%s" and obs.dateID = %i;' % (
20 filt, dateID)
21 if dtypes is None:
22 names = ['ra', 'dec', 'alt', 'starMag', 'sky', 'filter']
23 types = [float, float, float, float, float, '|S1']
24 dtypes = list(zip(names, types))
26 engine = sqla.create_engine(dbAddress)
27 connection = engine.raw_connection()
28 cursor = connection.cursor()
29 cursor.execute(sqlQ)
30 data = cursor.fetchall()
31 data = np.asarray(data, dtype=dtypes)
33 q2 = 'select mjd from dates where ID = %i'%dateID
34 cursor.execute(q2)
36 mjd = cursor.fetchall()
37 if len(mjd) == 0:
38 mjd = None
39 else:
40 mjd = mjd[0][0]
41 return data, mjd
44def diodeSkyDB(midMJD, sqlQ=None, dtypes=None, dbAddress=None, clean=True):
45 if dbAddress is None:
46 dataPath = os.getenv('SIMS_SKYBRIGHTNESS_DATA_DIR')
47 dbAddress = 'sqlite:///'+os.path.join(dataPath, 'photometry', 'skydata.sqlite')
48 if sqlQ is None:
49 sqlQ = 'select mjd, R, Y, Z from photdiode where mjd > %f-1 and mjd < %f+1' % (midMJD, midMJD)
50 if dtypes is None:
51 names = ['mjd', 'r', 'y', 'z']
52 types = [float]*4
53 dtypes = list(zip(names, types))
55 engine = sqla.create_engine(dbAddress)
56 connection = engine.raw_connection()
57 cursor = connection.cursor()
58 cursor.execute(sqlQ)
59 data = cursor.fetchall()
60 data = np.asarray(data, dtype=dtypes)
62 if clean:
63 data = data[np.where((data['r'] > 0) & (data['z'] > 0) &
64 (data['y'] > 0))]
66 return data