-
Notifications
You must be signed in to change notification settings - Fork 3
/
test_mosbot.py
311 lines (255 loc) · 10.6 KB
/
test_mosbot.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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
from __future__ import print_function
import unittest
#from django.test import TestCase
import os
class TestMosbot(unittest.TestCase):
def test_maybe_ha_flip(self):
from mosbot import maybe_ha_flip
self.assertEqual(maybe_ha_flip(86, 86, 3), False)
self.assertEqual(maybe_ha_flip(86, 88, 3), True)
self.assertEqual(maybe_ha_flip(88, 88, 3), True)
self.assertEqual(maybe_ha_flip(88, 86, 3), True)
self.assertEqual(maybe_ha_flip(90, 90, 3), True)
self.assertEqual(maybe_ha_flip(90, 94, 3), True)
self.assertEqual(maybe_ha_flip(94, 94, 3), False)
self.assertEqual(maybe_ha_flip(94, 90, 3), True)
self.assertEqual(maybe_ha_flip(90, 86, 3), True)
self.assertEqual(maybe_ha_flip(-94, 94, 3), True)
self.assertEqual(maybe_ha_flip(-86, -86, 3), False)
self.assertEqual(maybe_ha_flip(-86, -88, 3), True)
self.assertEqual(maybe_ha_flip(-88, -88, 3), True)
self.assertEqual(maybe_ha_flip(-88, -86, 3), True)
self.assertEqual(maybe_ha_flip(-90, -90, 3), True)
self.assertEqual(maybe_ha_flip(-90, -94, 3), True)
self.assertEqual(maybe_ha_flip(-94, -94, 3), False)
self.assertEqual(maybe_ha_flip(-94, -90, 3), True)
self.assertEqual(maybe_ha_flip(-90, -86, 3), True)
def set_json_files(self, start_time,
pass1='pass1.json', pass2='pass2.json', pass3='pass3.json'):
fn1 = os.path.join(self.testdatadir, pass1)
fn2 = os.path.join(self.testdatadir, pass2)
fn3 = os.path.join(self.testdatadir, pass3)
tmpfn1 = fn1 + '.tmp'
tmpfn2 = fn2 + '.tmp'
tmpfn3 = fn3 + '.tmp'
for fn,tmpfn in ((fn1,tmpfn1),(fn2,tmpfn2),(fn3,tmpfn3)):
import json
import ephem
J = json.loads(open(fn, 'r').read())
t0 = ephem.Date(str(J[0]['approx_datetime']))
print('First exposure:', t0)
for j in J:
tnew = start_time + ephem.Date(str(j['approx_datetime'])) - t0
tnew = str(ephem.Date(tnew))
j['approx_datetime'] = tnew
print('Updated datetime to', tnew)
f = open(tmpfn, 'w')
json.dump(J, f, sort_keys=True, indent=4, separators=(',', ': '))
f.close()
self.jsonfiles = [tmpfn1, tmpfn2, tmpfn3]
def setUp(self):
self.testdatadir = os.path.join(os.path.dirname(__file__),
'testdata')
import ephem
now = ephem.now()
print('Now:', now)
self.set_json_files(now)
def test_sequence(self):
from mosbot import main
import tempfile
import ephem
now = ephem.now()
print('Now:', now)
# Make the plans start one hour ago.
now -= (1./24.)
self.set_json_files(now,
pass1='2017-03-01-p1.json',
pass2='2017-03-01-p2.json',
pass3='2017-03-01-p3.json')
tempdir = tempfile.mkdtemp()
args = ['--script', os.path.join(tempdir, 'tonight.sh'),
# '--no-cut-past',
'--sequence', '--pass', '1']
args += self.jsonfiles
mosbot = main(cmdlineargs=args, get_mosbot=True)
# Touch forcepass1
f = open(os.path.join(tempdir, 'forcepass1'), 'w')
f.close()
tiles = [686811]
# BEFORE: check tile numbers -- starting after now.
for i,tile in enumerate(tiles):
fn = os.path.join(tempdir, 'expose-%i.sh' % (i+1))
txt = open(fn).read()
tilename = 'MzLS_%i_z' % tile
print('Checking for tile', tilename, 'in file', fn)
assert(tilename in txt)
print('Updating as though two hours late.')
mosbot.update_for_image({
'airmass': 1.019,
'skybright': 19.372964228396995,
'transparency': 0.94911683705518535,
'zp': 26.348159194305978,
'seeing': 0.9776841626480679,
'band': 'z'},
now = now + (3./24.))
tiles = [664120, 661867, 661868, 659585, 659586, 661869]
# AFTER: check tile numbers.
for i,tile in enumerate(tiles):
fn = os.path.join(tempdir, 'expose-%i.sh' % (i+1))
txt = open(fn).read()
tilename = 'MzLS_%i_z' % tile
print('Checking for tile', tilename, 'in file', fn)
assert(tilename in txt)
print('Updating after seqnum=3')
# Pretend that we're at seqnum=3 and assert that we proceed with the
# same set of tiles.
# write sequence number
f = open(mosbot.seqnumpath, 'w')
f.write('3\n')
f.close()
mosbot.update_for_image({
'airmass': 1.019,
'skybright': 19.372964228396995,
'transparency': 0.94911683705518535,
'zp': 26.348159194305978,
'seeing': 0.9776841626480679,
'band': 'z'},
now = now + ((3.*3600 + 3.*80)/86400.))
tiles = [664120, 661867, 661868, 659585, 659586, 661869]
# AFTER: check tile numbers.
for i,tile in enumerate(tiles):
fn = os.path.join(tempdir, 'expose-%i.sh' % (i+1))
txt = open(fn).read()
tilename = 'MzLS_%i_z' % tile
print('Checking for tile', tilename, 'in file', fn)
assert(tilename in txt)
def test_new_file(self):
from mosbot import main
import tempfile
tempdir = tempfile.mkdtemp()
args = ['--script', os.path.join(tempdir, 'tonight.sh')]
args.append('--adjust')
#args.append('--no-db')
args += self.jsonfiles
mosbot = main(cmdlineargs=args, get_mosbot=True)
# write sequence number
f = open(mosbot.seqnumpath, 'w')
f.write('10\n')
f.close()
fn = os.path.join(self.testdatadir, 'mos3.68488.im4.fits.fz')
mosbot.process_file(fn)
# Assert that entries have been added to the computed-exposure database
import obsdb
from obsdb.models import ComputedExptime, OtherPasses
c = ComputedExptime.objects.all()
for cc in c:
print(cc)
self.assertEqual(len(c), 19)
def test_new_file_blank(self):
from mosbot import main
import tempfile
tempdir = tempfile.mkdtemp()
args = ['--script', os.path.join(tempdir, 'tonight.sh')]
args += self.jsonfiles
mosbot = main(cmdlineargs=args, get_mosbot=True)
mosbot.J1 = mosbot.J1[:10]
mosbot.J2 = mosbot.J2[:10]
mosbot.J3 = mosbot.J3[:10]
mosbot.Nahead = 15
# write sequence number
f = open(mosbot.seqnumpath, 'w')
f.write('5\n')
f.close()
fn = os.path.join(self.testdatadir, 'mos3.68488.im4.fits.fz')
#mosbot.process_file(fn)
mosbot.update_for_image({
'airmass' :1.019, 'extension': 'im4', 'pixscale': 0.26,
'camera': 'mosaic3', 'ra_ccd': 102.97109434817698,
'dec_ccd': 37.53083859605576, 'band': 'z',
'zp': 26.348159194305978, 'rawsky': 3522.2537, 'ndetected': 571,
'skybright': 19.372964228396995, 'dy': -50.904994833603581,
'transparency': 0.94911683705518535, 'seeing': 0.9776841626480679,
'dx': 9.0965935687085278, 'nmatched': 199})
def test_large_slew(self):
from mosbot import main
import tempfile
tempdir = tempfile.mkdtemp()
args = ['--script', os.path.join(tempdir, 'tonight.sh')]
args += self.jsonfiles
mosbot = main(cmdlineargs=args, get_mosbot=True)
mosbot.J1[0]['RA'] = 0
mosbot.J1[0]['dec'] = -90
# write sequence number
f = open(mosbot.seqnumpath, 'w')
f.write('5\n')
f.close()
fn = os.path.join(self.testdatadir, 'mos3.68488.im4.fits.fz')
#mosbot.process_file(fn)
mosbot.update_for_image({
'airmass': 1.019,
'skybright': 19.372964228396995,
'transparency': 0.94911683705518535,
'zp': 26.348159194305978,
'seeing': 0.9776841626480679,
'band': 'z'})
def XXXtest_run(self):
from mosbot import main
import tempfile
tempdir = tempfile.mkdtemp()
args = ['--script', os.path.join(tempdir, 'tonight.sh')]
args += self.jsonfiles
mosbot = main(cmdlineargs=args, get_mosbot=True)
# write sequence number
f = open(mosbot.seqnumpath, 'w')
f.write('10\n')
f.close()
mosbot.run()
def test_no_cut_past(self):
from mosbot import main
import tempfile
import ephem
now = ephem.now()
print('Now:', now)
# Make the plans start an hour ago.
now -= (1./24.)
self.set_json_files(now)
tempdir = tempfile.mkdtemp()
args = ['--script', os.path.join(tempdir, 'tonight.sh'),
'--no-cut-past', '--pass', '1']
args += self.jsonfiles
mosbot = main(cmdlineargs=args, get_mosbot=True)
# Touch forcepass1
f = open(os.path.join(tempdir, 'forcepass1'), 'w')
f.close()
tiles = [650124, 650123, 652527, 654902, 652528,
654903, 657247, 650125, 657246, 657248]
# BEFORE: check tile numbers
for i,tile in enumerate(tiles):
fn = os.path.join(tempdir, 'expose-%i.sh' % (i+1))
txt = open(fn).read()
tilename = 'MzLS_%i_z' % tile
print('Checking for tile', tilename, 'in file', fn)
assert(tilename in txt)
# write sequence number
f = open(mosbot.seqnumpath, 'w')
f.write('5\n')
f.close()
mosbot.update_for_image({
'airmass': 1.019,
'skybright': 19.372964228396995,
'transparency': 0.94911683705518535,
'zp': 26.348159194305978,
'seeing': 0.9776841626480679,
'band': 'z'})
# AFTER: check that tile numbers remain the same!
for i,tile in enumerate(tiles):
fn = os.path.join(tempdir, 'expose-%i.sh' % (i+1))
txt = open(fn).read()
tilename = 'MzLS_%i_z' % tile
print('Checking for tile', tilename, 'in file', fn)
assert(tilename in txt)
if __name__ == '__main__':
import obsdb
from camera_mosaic import database_filename
obsdb.django_setup(database_filename=database_filename)
unittest.main()