-
Notifications
You must be signed in to change notification settings - Fork 0
/
getDatabase.py
196 lines (182 loc) · 6.95 KB
/
getDatabase.py
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#! /usr/bin/env python
#------------------------------------------------
# This code compare the image quality measurement
# from IH and QR.
# J. Hao, 11/16/2012 @ FNAL
import psycopg2 as psy
import numpy as np
import pylab as pl
import sys
def getExpidByDate(start_date='2012-11-08',end_date='2012-11-09',fermi=False):
"""
get info from the IH database
"""
if fermi==False:
conn_str="host='server2.ctio.noao.edu' port=5442 dbname='decam_prd' user='decam_reader' password='reader'"
else:
conn_str="host='des10.fnal.gov' port=5443 dbname='decam_prd' user='decam_reader' password='reader'"
d = psy.connect(conn_str)
c = d.cursor()
cmd_str = "SELECT exposure_id FROM telemetry.image_health WHERE time_recorded BETWEEN '%s' AND '%s' GROUP BY exposure_id"%(start_date,end_date)
c.execute(cmd_str)
res = np.array(c.fetchall())
return res[:,0]
def getIHbyDate(start_date='2012-11-08',end_date='2012-11-09',fermi=False):
"""
get info from the IH database
"""
if fermi==False:
conn_str="host='server2.ctio.noao.edu' port=5442 dbname='decam_prd' user='decam_reader' password='reader'"
else:
conn_str="host='des10.fnal.gov' port=5443 dbname='decam_prd' user='decam_reader' password='reader'"
d = psy.connect(conn_str)
c = d.cursor()
cmd_str = "SELECT exposure_id,AVG(harmonic_mean_seeing[1]), AVG(median_ellipticity[1]) FROM telemetry.image_health WHERE time_recorded BETWEEN '%s' AND '%s' GROUP BY exposure_id"%(start_date,end_date)
c.execute(cmd_str)
res = np.array(c.fetchall())
expid = res[:,0].astype('i')
fwhm = res[:,1]
ellip = res[:,2]
return expid,fwhm,ellip
def getIHbyExpid(expid=None,fermi=False):
"""
get info from the IH database
"""
if fermi==False:
conn_str="host='server2.ctio.noao.edu' port=5442 dbname='decam_prd' user='decam_reader' password='reader'"
else:
conn_str="host='des10.fnal.gov' port=5443 dbname='decam_prd' user='decam_reader' password='reader'"
d = psy.connect(conn_str)
c = d.cursor()
cmd_str = "SELECT exposure_id,AVG(harmonic_mean_seeing[1]), AVG(median_ellipticity[1]) FROM telemetry.image_health WHERE exposure_id='%s' GROUP BY exposure_id"%str(expid)
c.execute(cmd_str)
res = c.fetchall()
if len(res)==0:
exposure_id = expid
fwhm = 0.
ellip = 0.
else:
exposure_id = res[0][0]
fwhm = res[0][1]
ellip = res[0][2]
return exposure_id,fwhm,ellip
def getDIMMbyDate(start_date='2012-11-08',end_date='2012-11-09',fermi=False):
"""
get info from the IH database
"""
if fermi==False:
conn_str="host='server2.ctio.noao.edu' port=5442 dbname='decam_prd' user='decam_reader' password='reader'"
else:
conn_str="host='des10.fnal.gov' port=5443 dbname='decam_prd' user='decam_reader' password='reader'"
d = psy.connect(conn_str)
c = d.cursor()
cmd_str = "SELECT en.time_recorded, en.dimm_seeing FROM telemetry.environmental_data en WHERE en.time_recorded BETWEEN '%s' AND '%s'"%(start_date,end_date)
c.execute(cmd_str)
res = np.array(c.fetchall())
return res
def getQRbyDate(start_date='2012-11-08',end_date='2012-11-09',fermi=False):
"""
get info from the Quick Reduce database
"""
if fermi==False:
conn_str="host='server2.ctio.noao.edu' port=5442 dbname='desbrdev' user='qr_reader' password='QRreader'"
else:
conn_str="host='des10.fnal.gov' port=5443 dbname='desbrdev' user='qr_reader' password='QRreader'"
d = psy.connect(conn_str)
c = d.cursor()
cmd_str = "SELECT e.expnum as exposure_id, AVG(c.fwhm), AVG(c.ellipticity) FROM exposure e, ccd c, night n where e.exposure_id = c.exposure_id AND n.date BETWEEN '%s' AND '%s' GROUP BY e.expnum"%(start_date,end_date)
c.execute(cmd_str)
res = np.array(c.fetchall())
expid = res[:,0].astype('i')
fwhm = res[:,1]
ellip = res[:,2]
return expid,fwhm,ellip
def getQRbyExpid(expid=None,fermi=False):
"""
get info from the Quick Reduce database
"""
if fermi==False:
conn_str="host='server2.ctio.noao.edu' port=5442 dbname='desbrdev' user='qr_reader' password='QRreader'"
else:
conn_str="host='des10.fnal.gov' port=5443 dbname='desbrdev' user='qr_reader' password='QRreader'"
d = psy.connect(conn_str)
c = d.cursor()
cmd_str = "SELECT e.expnum as exposure_id, AVG(c.fwhm), AVG(c.ellipticity),MAX(e.filter) FROM exposure e, ccd c WHERE e.exposure_id = c.exposure_id AND e.expnum ='%s' GROUP BY e.expnum"%str(expid)
c.execute(cmd_str)
res = c.fetchall()
if len(res)==0:
exposure_id = expid
fwhm = 0.
ellip = 0.
filter='NA'
else:
exposure_id = res[0][0]
fwhm = res[0][1]
ellip = res[0][2]
filter = res[0][3]
return exposure_id,fwhm,ellip,filter
if __name__ == "__main__":
import sys
sys.path.append('/usr/remote/user/sispi/jiangang/des-sv')
from getDatabase import *
if len(sys.argv) <2:
print 'syntax: getDatabase start_date end_date'
print 'example: getDatabase.py 2012-11-06 2012-11-07'
sys.exit()
start_date = sys.argv[1]
end_date = sys.argv[2]
expid = getExpidByDate(start_date,end_date)
nexposure = len(expid)
fltr=[]
fwhmIH = np.zeros(nexposure)
ellipIH = np.zeros(nexposure)
fwhmQR = np.zeros(nexposure)
ellipQR = np.zeros(nexposure)
for i in range(nexposure):
print i, nexposure
resQR = getQRbyExpid(expid[i])
resIH = getIHbyExpid(expid[i])
fwhmQR[i]=resQR[1]
ellipQR[i] = resQR[2]
fltr.append(resQR[3])
fwhmIH[i] = resIH[1]
ellipIH[i] = resIH[2]
fltr = np.array(fltr)
idx = np.arange(nexposure)
idxg = idx[fltr=='g']
idxr = idx[fltr=='r']
idxi = idx[fltr=='i']
idxz = idx[fltr=='z']
idxY = idx[fltr=='Y']
pl.figure(figsize=(10,10))
pl.plot(fwhmQR[idxg],fwhmIH[idxg],'g.',label='g')
pl.plot(fwhmQR[idxr],fwhmIH[idxr],'r.',label='r')
pl.plot(fwhmQR[idxi],fwhmIH[idxi],'c.',label='i')
pl.plot(fwhmQR[idxz],fwhmIH[idxz],'m.',label='z')
pl.plot(fwhmQR[idxY],fwhmIH[idxY],'b.',label='Y')
pl.grid()
pl.xlabel('FWHM from QR')
pl.ylabel('FWHM from IH')
pl.title(start_date+' -- '+end_date)
pl.legend(loc='best')
pl.plot([0.5,3],[0.5,3],'k-')
pl.xlim(0.5,3)
pl.ylim(0.5,3)
pl.savefig('fwhm_QR_IH.png')
pl.close()
pl.figure(figsize=(10,10))
pl.plot(ellipQR[idxg],ellipIH[idxg],'g.',label='g')
pl.plot(ellipQR[idxr],ellipIH[idxr],'r.',label='r')
pl.plot(ellipQR[idxi],ellipIH[idxi],'c.',label='i')
pl.plot(ellipQR[idxz],ellipIH[idxz],'m.',label='z')
pl.plot(ellipQR[idxY],ellipIH[idxY],'b.',label='Y')
pl.grid()
pl.plot([0,0.5],[0,0.5],'k-')
pl.xlim(0,0.4)
pl.ylim(0,0.4)
pl.xlabel('ELLIPTICITY from QR')
pl.ylabel('ELLIPTICITY from IH')
pl.title(start_date+' -- '+end_date)
pl.legend(loc='best')
pl.savefig('ellip_QR_IH.png')
pl.close()