def test_ha(self): import tempfile from mosbot import main # Override the ephem.now() function to lie about the time oldnow = ephem.now ephem.now = bigben tempdir = tempfile.mkdtemp() fn1 = os.path.join(self.testdatadir, '2017-10-04-p3.json') args = ['--script', os.path.join(tempdir, 'tonight.sh')] args += [fn1, fn1, fn1] mosbot = main(cmdlineargs=args, get_mosbot=True) f = open(os.path.join(tempdir, 'seqnum.txt'), 'w') f.write('1') f.close() mosbot.Nahead = 200 mosbot.update_for_image({ 'airmass': 1.019, 'skybright': 19.372964228396995, 'transparency': 0.94911683705518535, 'zp': 26.348159194305978, 'seeing': 0.9776841626480679, 'band': 'z' }) ephem.now = oldnow
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 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_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)
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_new_file(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() fn = os.path.join(self.testdatadir, 'mos3.68488.im4.fits.fz') mosbot.process_file(fn)
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_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)