Exemplo n.º 1
0
    def test_findfile(self):
        night = '20150102'
        expid = 3
        camera = 'z3'
        filepath = io.findfile('simspec', night, expid)
        filepath = io.findfile('simpix', night, expid, camera)
        outdir = '/blat/foo/bar'
        filepath = io.findfile('simpix', night, expid, camera, outdir=outdir, mkdir=False)
        self.assertTrue(filepath.startswith(outdir))

        with self.assertRaises(ValueError):
            io.findfile('blat', night, expid, camera)  #- bad filetype
Exemplo n.º 2
0
    def test_newexp(self):
        night = self.night
        seed = np.random.randint(2**30)
        #- programs 'bgs' and 'bright' not yet implemented
        for expid, program in enumerate(['arc', 'flat', 'dark', 'mws']):
            sim, fibermap, meta, obsconditions, objmeta = obs.new_exposure(program, nspec=10, night=night, expid=expid, seed=seed)
            simspecfile = io.findfile('simspec', night, expid=expid)
            fibermapfile = io.findfile('simfibermap', night, expid=expid)
            self.assertTrue(os.path.exists(simspecfile))
            self.assertTrue(os.path.exists(fibermapfile))
            simspec = io.read_simspec(simspecfile)
            if program in ('arc', 'flat'):
                self.assertEqual(simspec.flavor, program)
            else:
                self.assertEqual(simspec.flavor, 'science')

            #- Check that photons are in a reasonable range
            self.assertGreater(len(simspec.cameras), 0)
            for camera in simspec.cameras.values():
                maxphot = camera.phot.max()
                self.assertTrue(maxphot > 1, 'suspiciously few {} photons ({}); wrong units?'.format(program, maxphot))
                self.assertTrue(maxphot < 1e6, 'suspiciously many {} photons ({}); wrong units?'.format(program, maxphot))
                if program not in ('arc', 'flat'):
                    self.assertTrue(camera.skyphot.max() > 1, 'suspiciously few sky photons; wrong units?')
                    self.assertTrue(camera.skyphot.max() < 1e6, 'suspiciously many sky photons; wrong units?')

            if program in ('arc', 'flat'):
                self.assertTrue(meta is None)
                self.assertTrue(obsconditions is None)
            else:
                flux, fluxhdr = fits.getdata(simspecfile, 'FLUX', header=True)
                skyflux, skyfluxhdr = fits.getdata(simspecfile, 'SKYFLUX', header=True)
                self.assertTrue(fluxhdr['BUNIT'].startswith('1e-17'))
                self.assertTrue(skyfluxhdr['BUNIT'].startswith('1e-17'))
                for i in range(flux.shape[0]):
                    objtype = simspec.truth['OBJTYPE'][i]
                    maxflux = flux[i].max()
                    maxsky = skyflux[i].max()
                    self.assertTrue(maxsky > 1, 'suspiciously low {} sky flux ({}); wrong units?'.format(objtype, maxsky))
                    self.assertTrue(maxsky < 1e5, 'suspiciously high {} sky flux ({}); wrong units?'.format(objtype, maxsky))
                    if objtype != 'SKY':
                        ### print('---> {} maxflux {}'.format(objtype, maxflux))
                        self.assertTrue(maxflux > 0.01, 'suspiciously low {} flux ({}) using seed {}; wrong units?'.format(objtype, maxflux, seed))
                        self.assertTrue(maxflux < 1e5, 'suspiciously high {} flux ({}) using seed {}; wrong units?'.format(objtype, maxflux, seed))
                    else:
                        self.assertTrue(np.all(flux[i] == 0.0))

            os.remove(simspecfile)
            os.remove(fibermapfile)

        #- confirm that night and expid are optional
        results = obs.new_exposure('arc', nspec=2)
Exemplo n.º 3
0
    def test_findfile(self):
        night = '20150102'
        expid = 3
        camera = 'z3'
        filepath = io.findfile('simspec', night, expid)
        filepath = io.findfile('simpix', night, expid, camera)
        outdir = '/blat/foo/bar'
        filepath = io.findfile('simpix',
                               night,
                               expid,
                               camera,
                               outdir=outdir,
                               mkdir=False)
        self.assertTrue(filepath.startswith(outdir))

        with self.assertRaises(ValueError):
            io.findfile('blat', night, expid, camera)  #- bad filetype
Exemplo n.º 4
0
 def test_write_simpix(self):
     outfile = io.findfile('simpix', '20150104', 5, 'z3')
     pix = np.random.uniform( (5,10) )
     meta = dict(BLAT='foo', BAR='biz')
     io.write_simpix(outfile, pix, meta)
     image, header = fits.getdata(outfile, header=True)
     self.assertEqual(image.dtype.itemsize, 4)
     self.assertTrue(np.all(pix.astype(np.float32) == image))
     for key in meta:
         self.assertTrue(meta[key] == header[key])
Exemplo n.º 5
0
 def test_write_simpix(self):
     outfile = io.findfile('simpix', '20150104', 5, 'z3')
     pix = np.random.uniform((5, 10))
     meta = dict(BLAT='foo', BAR='biz')
     io.write_simpix(outfile, pix, camera='b0', meta=meta)
     image, header = fits.getdata(outfile, 'B0', header=True)
     self.assertEqual(image.dtype.itemsize, 4)
     self.assertTrue(np.all(pix.astype(np.float32) == image))
     for key in meta:
         self.assertTrue(meta[key] == header[key])
Exemplo n.º 6
0
 def test_newexp(self):
     night = '20150101'
     for expid, flavor in enumerate(['arc', 'flat', 'science']):
         fibermap, true = obs.new_exposure(flavor, nspec=5, night=night, expid=expid)
         simspecfile = io.findfile('simspec', night, expid=expid)
         self.assertTrue(os.path.exists(simspecfile))
         simspec = io.read_simspec(simspecfile)
         self.assertEqual(simspec.flavor, flavor)
     
     #- confirm that night and expid are optional
     fibermap, true = obs.new_exposure('arc', nspec=2)
Exemplo n.º 7
0
 def tearDown(self):
     for expid in range(5):
         for filetype in ['simspec', 'simfibermap']:
             filename = io.findfile('simspec', self.night, expid)
             if os.path.exists(filename):
                 os.remove(filename)
Exemplo n.º 8
0
 def tearDown(self):
     for expid in range(5):
         for filetype in ['simspec', 'simfibermap']:
             filename = io.findfile('simspec', self.night, expid)
             if os.path.exists(filename):
                 os.remove(filename)