-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_all.py
71 lines (62 loc) · 3.06 KB
/
test_all.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
""" Pull all observations from an opsim run, and test against opsimObs.py """
import os
import useful_input as ui
import numpy
import pylab
opsim= 'output_opsim4_262'
nobs= 10000
def get_opsimObs_inputs(opsim, offset=0, drows=nobs):
conn, cursor = ui.sqlConnect()
query = 'select fieldRA*180/PI(), fieldDec*180/PI(), expmjd, filter, exptime from %s group by expmjd' %(opsim)
results = ui.sqlQueryLimited(cursor, query, offset=offset, drows=drows)
keys = ('ra', 'dec', 'expmjd', 'filter', 'exptime')
keytypes = ('float', 'float', 'float', 'str', 'int')
data = ui.assignResults(results, keys)
ui.writeDatafile('test_%s' %(opsim), data, keys)
ui.sqlEndConnect(conn, cursor)
return
def get_opsimValues(opsim, offset=0, drows=nobs):
conn, cursor = ui.sqlConnect()
query = 'select fieldRA*180/PI(), fieldDec*180/PI(), expmjd, filter, altitude*180/PI(), azimuth*180/PI(), airmass, xparency, seeing, sunAlt*180/PI(), sunAz*180/PI(), MoonAlt*180/PI(), moonPhase, moonIllum, skybrightness_modified, 5sigma_modified from %s group by expmjd' %(opsim)
results = ui.sqlQueryLimited(cursor, query, offset=offset, drows=drows)
keys = ('ra', 'dec', 'expmjd', 'filter', 'alt', 'az', 'airmass', 'cloud', 'seeing', 'sunalt', 'sunaz', 'moonalt', 'moonphase', 'moonillum',
'skybright', 'maglimit')
opsimdata = ui.assignResults(results, keys)
ui.sqlEndConnect(conn, cursor)
return opsimdata
def get_opsimObsValues(filename):
keys = ('ra', 'dec', 'expmjd', 'filter', 'alt', 'az', 'airmass', 'cloud', 'seeing', 'sunalt', 'sunaz', 'moonalt', 'moonaz', 'moonphase', 'moonillum',
'skybright', 'maglimit', 'surveynight', 'downtime')
keytypes = ('float', 'float', 'float', 'str', 'float', 'float', 'float', 'float', 'float', 'float', 'float', 'float', 'float', 'float', 'float',
'float', 'float', 'int', 'int')
opsimObsdata = ui.readDatafile(filename, keys, keytypes)
return opsimObsdata
def compare(opsim, opsimObs, nobs=nobs):
compkeys = ('alt', 'az', 'airmass', 'cloud', 'seeing', 'sunalt', 'sunaz', 'moonalt', 'moonphase', 'skybright', 'maglimit')
for k in compkeys:
pylab.figure()
if k == 'moonphase':
k2 = 'moonillum'
else:
k2 = k
print k, len(opsim[k]), len(opsimObs[k2])
diff = opsim[k] - opsimObs[k2]
pylab.hist(diff, bins=nobs / 10)
pylab.title('%s' % (k))
# Look in more depth at airmass differences.
pylab.figure()
pylab.plot(opsim['airmass'], opsimObs['airmass'], 'b.')
pylab.xlabel('opsim airmass')
pylab.ylabel('opsimObs airmass')
# Look more depth at moon phase.
pylab.figure()
pylab.plot(opsim['moonphase'], opsimObs['moonillum'], 'r.')
pylab.xlabel('opsim moon phase')
pylab.ylabel('opsimObs moon phase')
# Look more depth at sky brightness / limiting mag.
pylab.figure()
pylab.plot(opsim['skybright'], opsimObs['skybright'], 'k.')
pylab.xlabel('Opsim skybright')
pylab.ylabel('OpsimObs skybright')
pylab.title('Comparison of skybrightness estimates')
return