Hide keyboard shortcuts

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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

from builtins import zip 

import numpy as np 

import sqlalchemy as sqla 

import os 

from lsst.utils import getPackageDir 

 

# Tools for using an all-sky sqlite DB with cannon and photodiode data from the site. 

 

 

def allSkyDB(dateID, sqlQ=None, dtypes=None, dbAddress=None, filt='R'): 

""" 

Take in a dateID (that corresponds to a single MJD, and 

return the star and sky magnitudes in a numpy structured array. 

""" 

if dbAddress is None: 

dataPath = getPackageDir('sims_skybrightness_data') 

dbAddress = 'sqlite:///'+os.path.join(dataPath, 'photometry', 'skydata.sqlite') 

if sqlQ is None: 

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;' % ( 

filt, dateID) 

if dtypes is None: 

names = ['ra', 'dec', 'alt', 'starMag', 'sky', 'filter'] 

types = [float, float, float, float, float, '|S1'] 

dtypes = list(zip(names, types)) 

 

engine = sqla.create_engine(dbAddress) 

connection = engine.raw_connection() 

cursor = connection.cursor() 

cursor.execute(sqlQ) 

data = cursor.fetchall() 

data = np.asarray(data, dtype=dtypes) 

 

q2 = 'select mjd from dates where ID = %i'%dateID 

cursor.execute(q2) 

 

mjd = cursor.fetchall() 

if len(mjd) == 0: 

mjd = None 

else: 

mjd = mjd[0][0] 

return data, mjd 

 

 

def diodeSkyDB(midMJD, sqlQ=None, dtypes=None, dbAddress=None, clean=True): 

if dbAddress is None: 

dataPath = os.getenv('SIMS_SKYBRIGHTNESS_DATA_DIR') 

dbAddress = 'sqlite:///'+os.path.join(dataPath, 'photometry', 'skydata.sqlite') 

if sqlQ is None: 

sqlQ = 'select mjd, R, Y, Z from photdiode where mjd > %f-1 and mjd < %f+1' % (midMJD, midMJD) 

if dtypes is None: 

names = ['mjd', 'r', 'y', 'z'] 

types = [float]*4 

dtypes = list(zip(names, types)) 

 

engine = sqla.create_engine(dbAddress) 

connection = engine.raw_connection() 

cursor = connection.cursor() 

cursor.execute(sqlQ) 

data = cursor.fetchall() 

data = np.asarray(data, dtype=dtypes) 

 

if clean: 

data = data[np.where((data['r'] > 0) & (data['z'] > 0) & 

(data['y'] > 0))] 

 

return data