Exemple #1
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)
Exemple #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)