コード例 #1
0
    def testCreationOfPhoSimCatalog(self):
        """
        Make sure that we can create PhoSim input catalogs using the returned
        ObservationMetaData. This test will just make sure that all of the
        expected header entries are there.
        """

        scratch_dir = os.path.join(getPackageDir('sims_catUtils'), 'tests',
                                   'scratchSpace')
        dbName = os.path.join(scratch_dir, 'obsMetaDataGeneratorTest.db')
        catName = os.path.join(scratch_dir,
                               'testPhoSimFromObsMetaDataGenerator.txt')
        if os.path.exists(dbName):
            os.unlink(dbName)
        makePhoSimTestDB(filename=dbName)
        bulgeDB = testGalaxyBulgeDBObj(driver='sqlite', database=dbName)
        gen = self.gen
        results = gen.getObservationMetaData(fieldRA=np.degrees(1.370916),
                                             telescopeFilter='i')
        testCat = PhoSimCatalogSersic2D(bulgeDB, obs_metadata=results[0])
        testCat.phoSimHeaderMap = {}
        testCat.write_catalog(catName)

        if os.path.exists(catName):
            os.unlink(catName)

        if os.path.exists(dbName):
            os.unlink(dbName)
コード例 #2
0
    def testCreationOfPhoSimCatalog_3(self):
        """
        Make sure that we can create PhoSim input catalogs using the returned
        ObservationMetaData.

        Test that an error is actually raised if we try to build a PhoSim catalog
        with a v3 header map using a v4 ObservationMetaData
        """

        dbName = tempfile.mktemp(dir=ROOT, prefix='obsMetaDataGeneratorTest-', suffix='.db')
        makePhoSimTestDB(filename=dbName)
        bulgeDB = testGalaxyBulgeDBObj(driver='sqlite', database=dbName)
        opsim_db = os.path.join(getPackageDir('sims_data'), 'OpSimData',
                                'astro-lsst-01_2014.db')
        assert os.path.isfile(opsim_db)
        gen = ObservationMetaDataGenerator(opsim_db, driver='sqlite')
        results = gen.getObservationMetaData(fieldRA=(70.0, 85.0),
                                             telescopeFilter='i')
        self.assertGreater(len(results), 0)
        testCat = PhoSimCatalogSersic2D(bulgeDB, obs_metadata=results[0])
        testCat.phoSimHeaderMap = DefaultPhoSimHeaderMap
        with lsst.utils.tests.getTempFilePath('.txt') as catName:
            with self.assertRaises(RuntimeError):
                testCat.write_catalog(catName)

        if os.path.exists(dbName):
            os.unlink(dbName)
コード例 #3
0
    def testCompoundFitsFiles_one_empty(self):
        """
        Test that GalSimInterpreter puts the right number of counts on images
        containing different types of objects in the case where one of the
        input catalogs is empty (really, this is testing that we can
        successfully copy the GalSimInterpreter and all of the supporting
        properties from an empty GalSimCatalog to another GalSimCatalog)
        """
        driver = 'sqlite'
        dbName1 = os.path.join(self.scratch_dir, 'galSimTestCompound1DB_one_empty.db')
        if os.path.exists(dbName1):
            os.unlink(dbName1)

        deltaRA = np.array([72.0/3600.0, 55.0/3600.0, 75.0/3600.0])
        deltaDec = np.array([0.0, 15.0/3600.0, -15.0/3600.0])
        obs_metadata1 = makePhoSimTestDB(filename=dbName1, size=1,
                                         deltaRA=deltaRA, deltaDec=deltaDec,
                                         bandpass=self.bandpassNameList,
                                         m5=self.m5, seeing=self.seeing)

        dbName2 = os.path.join(self.scratch_dir, 'galSimTestCompound2DB_one_empty.db')
        if os.path.exists(dbName2):
            os.unlink(dbName2)

        deltaRA = np.array([55.0/3600.0, 60.0/3600.0, 62.0/3600.0])
        deltaDec = np.array([-3.0/3600.0, 10.0/3600.0, 10.0/3600.0])
        obs_metadata2 = makePhoSimTestDB(filename=dbName2, size=1,
                                         deltaRA=deltaRA, deltaDec=deltaDec,
                                         bandpass=self.bandpassNameList,
                                         m5=self.m5, seeing=self.seeing)

        gals = testGalaxyBulgeDBObj(driver=driver, database=dbName1)

        # shift the obs_metadata so that the catalog will not contain
        # any objects
        ra0 = obs_metadata1.pointingRA
        dec0 = obs_metadata1.pointingDec
        obs_metadata1.pointingRA = ra0 + 20.0

        cat1 = testGalaxyCatalog(gals, obs_metadata=obs_metadata1)
        cat1.camera_wrapper = GalSimCameraWrapper(self.camera)
        catName = os.path.join(self.scratch_dir, 'compoundCatalog_one_empty.sav')
        cat1.write_catalog(catName)
        with open(catName, "r") as input_file:
            input_lines = input_file.readlines()
            self.assertEqual(len(input_lines), 1)  # just the header
        self.assertFalse(hasattr(cat1, 'bandpassDict'))

        stars = testStarsDBObj(driver=driver, database=dbName2)
        cat2 = testStarCatalog(stars, obs_metadata=obs_metadata2)
        cat2.copyGalSimInterpreter(cat1)
        cat2.write_catalog(catName, write_header=False, write_mode='a')
        self.catalogTester(catName=catName, catalog=cat2, nameRoot='compound_one_empty')

        if os.path.exists(dbName1):
            os.unlink(dbName1)
        if os.path.exists(dbName2):
            os.unlink(dbName2)
        if os.path.exists(catName):
            os.unlink(catName)
コード例 #4
0
    def testCreationOfPhoSimCatalog_2(self):
        """
        Make sure that we can create PhoSim input catalogs using the returned
        ObservationMetaData.

        Use the actual DefaultPhoSimHeader map; make sure that opsim_version
        does not make it into the header.
        """

        dbName = tempfile.mktemp(dir=ROOT, prefix='obsMetaDataGeneratorTest-', suffix='.db')
        makePhoSimTestDB(filename=dbName)
        bulgeDB = testGalaxyBulgeDBObj(driver='sqlite', database=dbName)
        gen = self.gen
        results = gen.getObservationMetaData(fieldRA=np.degrees(1.370916),
                                             telescopeFilter='i')
        testCat = PhoSimCatalogSersic2D(bulgeDB, obs_metadata=results[0])
        testCat.phoSimHeaderMap = DefaultPhoSimHeaderMap
        with lsst.utils.tests.getTempFilePath('.txt') as catName:
            testCat.write_catalog(catName)
            ct_lines = 0
            with open(catName, 'r') as in_file:
                for line in in_file:
                    ct_lines += 1
                    self.assertNotIn('opsim_version', line)
                self.assertGreater(ct_lines, 10)  # check that some lines did get written

        if os.path.exists(dbName):
            os.unlink(dbName)
コード例 #5
0
    def testCompoundFitsFiles(self):
        """
        Test that GalSimInterpreter puts the right number of counts on images
        containing different types of objects
        """
        driver = "sqlite"
        dbName1 = "galSimTestCompound1DB.db"
        if os.path.exists(dbName1):
            os.unlink(dbName1)

        deltaRA = np.array([72.0 / 3600.0, 55.0 / 3600.0, 75.0 / 3600.0])
        deltaDec = np.array([0.0, 15.0 / 3600.0, -15.0 / 3600.0])
        obs_metadata1 = makePhoSimTestDB(
            filename=dbName1,
            size=1,
            deltaRA=deltaRA,
            deltaDec=deltaDec,
            bandpass=self.bandpassNameList,
            m5=self.m5,
            seeing=self.seeing,
        )

        dbName2 = "galSimTestCompound2DB.db"
        if os.path.exists(dbName2):
            os.unlink(dbName2)

        deltaRA = np.array([55.0 / 3600.0, 60.0 / 3600.0, 62.0 / 3600.0])
        deltaDec = np.array([-3.0 / 3600.0, 10.0 / 3600.0, 10.0 / 3600.0])
        obs_metadata2 = makePhoSimTestDB(
            filename=dbName2,
            size=1,
            deltaRA=deltaRA,
            deltaDec=deltaDec,
            bandpass=self.bandpassNameList,
            m5=self.m5,
            seeing=self.seeing,
        )

        gals = testGalaxyBulgeDBObj(driver=driver, database=dbName1)
        cat1 = testGalaxyCatalog(gals, obs_metadata=obs_metadata1)
        catName = "compoundCatalog.sav"
        cat1.write_catalog(catName)

        stars = testStarsDBObj(driver=driver, database=dbName2)
        cat2 = testStarCatalog(stars, obs_metadata=obs_metadata2)
        cat2.copyGalSimInterpreter(cat1)
        cat2.write_catalog(catName, write_header=False, write_mode="a")
        self.catalogTester(catName=catName, catalog=cat2, nameRoot="compound")

        if os.path.exists(dbName1):
            os.unlink(dbName1)
        if os.path.exists(dbName2):
            os.unlink(dbName2)
        if os.path.exists(catName):
            os.unlink(catName)
コード例 #6
0
    def testCompoundFitsFiles(self):
        """
        Test that GalSimInterpreter puts the right number of counts on images
        containing different types of objects
        """
        driver = 'sqlite'
        dbName1 = os.path.join(self.scratch_dir, 'galSimTestCompound1DB.db')
        if os.path.exists(dbName1):
            os.unlink(dbName1)

        deltaRA = np.array([72.0 / 3600.0, 55.0 / 3600.0, 75.0 / 3600.0])
        deltaDec = np.array([0.0, 15.0 / 3600.0, -15.0 / 3600.0])
        obs_metadata1 = makePhoSimTestDB(filename=dbName1,
                                         size=1,
                                         deltaRA=deltaRA,
                                         deltaDec=deltaDec,
                                         bandpass=self.bandpassNameList,
                                         m5=self.m5,
                                         seeing=self.seeing)

        dbName2 = os.path.join(self.scratch_dir, 'galSimTestCompound2DB.db')
        if os.path.exists(dbName2):
            os.unlink(dbName2)

        deltaRA = np.array([55.0 / 3600.0, 60.0 / 3600.0, 62.0 / 3600.0])
        deltaDec = np.array([-3.0 / 3600.0, 10.0 / 3600.0, 10.0 / 3600.0])
        obs_metadata2 = makePhoSimTestDB(filename=dbName2,
                                         size=1,
                                         deltaRA=deltaRA,
                                         deltaDec=deltaDec,
                                         bandpass=self.bandpassNameList,
                                         m5=self.m5,
                                         seeing=self.seeing)

        gals = testGalaxyBulgeDBObj(driver=driver, database=dbName1)
        cat1 = testGalaxyCatalog(gals, obs_metadata=obs_metadata1)
        cat1.camera_wrapper = GalSimCameraWrapper(self.camera)
        catName = os.path.join(self.scratch_dir, 'compoundCatalog.sav')
        cat1.write_catalog(catName)

        stars = testStarsDBObj(driver=driver, database=dbName2)
        cat2 = testStarCatalog(stars, obs_metadata=obs_metadata2)
        cat2.copyGalSimInterpreter(cat1)
        cat2.write_catalog(catName, write_header=False, write_mode='a')
        self.catalogTester(catName=catName, catalog=cat2, nameRoot='compound')

        if os.path.exists(dbName1):
            os.unlink(dbName1)
        if os.path.exists(dbName2):
            os.unlink(dbName2)
        if os.path.exists(catName):
            os.unlink(catName)
コード例 #7
0
 def setUp(self):
     self.tempDB = os.path.join(self.scratch_dir, 'PhoSimTestDatabase.db')
     self.obs_metadata = makePhoSimTestDB(size=10, filename=self.tempDB)
     self.bulgeDB = testGalaxyBulgeDBObj(driver='sqlite',
                                         database=self.tempDB)
     self.diskDB = testGalaxyDiskDBObj(driver='sqlite',
                                       database=self.tempDB)
     self.agnDB = testGalaxyAgnDBObj(driver='sqlite', database=self.tempDB)
     self.starDB = testStarsDBObj(driver='sqlite', database=self.tempDB)
     filter_translation = {'u': 0, 'g': 1, 'r': 2, 'i': 3, 'z': 4, 'y': 5}
     alt, az, pa = altAzPaFromRaDec(self.obs_metadata.pointingRA,
                                    self.obs_metadata.pointingDec,
                                    self.obs_metadata,
                                    includeRefraction=False)
     self.control_header = [
         'moondec %.7f\n' %
         np.degrees(self.obs_metadata.OpsimMetaData['moondec']),
         'rottelpos %.7f\n' %
         np.degrees(self.obs_metadata.OpsimMetaData['rottelpos']),
         'declination %.17f\n' % self.obs_metadata.pointingDec,
         'moonalt %.7f\n' %
         np.degrees(self.obs_metadata.OpsimMetaData['moonalt']),
         'rotskypos %.17f\n' % self.obs_metadata.rotSkyPos,
         'moonra %.7f\n' %
         np.degrees(self.obs_metadata.OpsimMetaData['moonra']),
         'sunalt %.7f\n' %
         np.degrees(self.obs_metadata.OpsimMetaData['sunalt']),
         'mjd %.17f\n' % (self.obs_metadata.mjd.TAI + 16.5 / 86400.0),
         'azimuth %.17f\n' % az,
         'rightascension %.17f\n' % self.obs_metadata.pointingRA,
         'dist2moon %.7f\n' %
         np.degrees(self.obs_metadata.OpsimMetaData['dist2moon']),
         'filter %d\n' % filter_translation[self.obs_metadata.bandpass],
         'altitude %.17f\n' % alt
     ]
コード例 #8
0
 def setUpClass(cls):
     cls.scratch_dir = os.path.join(getPackageDir('sims_catUtils'), 'tests',
                                    'scratchSpace')
     cls.db_name = os.path.join(cls.scratch_dir, 'PhoSimAstDB.db')
     if os.path.exists(cls.db_name):
         os.unlink(cls.db_name)
     cls.obs = makePhoSimTestDB(filename=cls.db_name, size=1000)
コード例 #9
0
    def setUpClass(cls):
        cls.dbName = tempfile.mktemp(dir=ROOT, prefix='PhoSimVariabilityDatabase-', suffix='.db')
        cls.obs_metadata = makePhoSimTestDB(size=10, filename=cls.dbName)
        cls.obs_metadata.mjd = ModifiedJulianDate(TAI=60000.0)

        cls.bulgeDB = testGalaxyBulgeDBObj(driver='sqlite', database=cls.dbName)
        cls.diskDB = testGalaxyDiskDBObj(driver='sqlite', database=cls.dbName)
        cls.agnDB = testGalaxyAgnDBObj(driver='sqlite', database=cls.dbName)
        cls.starDB = testStarsDBObj(driver='sqlite', database=cls.dbName)
コード例 #10
0
    def testCreationOfPhoSimCatalog(self):
        """
        Make sure that we can create PhoSim input catalogs using the returned
        ObservationMetaData. This test will just make sure that all of the
        expected header entries are there.
        """

        dbName = tempfile.mktemp(dir=ROOT, prefix='obsMetaDataGeneratorTest-', suffix='.db')
        makePhoSimTestDB(filename=dbName)
        bulgeDB = testGalaxyBulgeDBObj(driver='sqlite', database=dbName)
        gen = self.gen
        results = gen.getObservationMetaData(fieldRA=np.degrees(1.370916),
                                             telescopeFilter='i')
        testCat = PhoSimCatalogSersic2D(bulgeDB, obs_metadata=results[0])
        testCat.phoSimHeaderMap = {}
        with lsst.utils.tests.getTempFilePath('.txt') as catName:
            testCat.write_catalog(catName)

        if os.path.exists(dbName):
            os.unlink(dbName)
コード例 #11
0
    def testMultipleImages(self):
        """
        Test that GalSimInterpreter puts the right number of counts on images of multiple objects
        """
        dbName = os.path.join(self.scratch_dir, 'galSimTestMultipleDB.db')
        driver = 'sqlite'

        if os.path.exists(dbName):
            os.unlink(dbName)

        deltaRA = np.array([72.0 / 3600.0, 55.0 / 3600.0, 75.0 / 3600.0])
        deltaDec = np.array([0.0, 15.0 / 3600.0, -15.0 / 3600.0])
        obs_metadata = makePhoSimTestDB(filename=dbName,
                                        size=1,
                                        deltaRA=deltaRA,
                                        deltaDec=deltaDec,
                                        bandpass=self.bandpassNameList,
                                        m5=self.m5,
                                        seeing=self.seeing)

        gals = testGalaxyBulgeDBObj(driver=driver, database=dbName)
        cat = testGalaxyCatalog(gals, obs_metadata=obs_metadata)
        cat.camera_wrapper = GalSimCameraWrapper(self.camera)
        catName = os.path.join(self.scratch_dir, 'multipleCatalog.sav')
        cat.write_catalog(catName)
        self.catalogTester(catName=catName, catalog=cat, nameRoot='multiple')
        if os.path.exists(catName):
            os.unlink(catName)

        stars = testStarsDBObj(driver=driver, database=dbName)
        cat = testStarCatalog(stars, obs_metadata=obs_metadata)
        cat.camera_wrapper = GalSimCameraWrapper(self.camera)
        catName = os.path.join(self.scratch_dir, 'multipleStarCatalog.sav')
        cat.write_catalog(catName)
        self.catalogTester(catName=catName,
                           catalog=cat,
                           nameRoot='multipleStars')
        if os.path.exists(catName):
            os.unlink(catName)

        if os.path.exists(dbName):
            os.unlink(dbName)
コード例 #12
0
    def setUpClass(cls):
        cls.camera = camTestUtils.CameraWrapper().camera
        cls.scratch_dir = tempfile.mkdtemp(dir=ROOT, prefix='GalSimInterfaceTest-')
        cls.dbName = os.path.join(cls.scratch_dir, 'galSimTestDB.db')

        deltaRA = np.array([72.0/3600.0])
        deltaDec = np.array([0.0])
        defaults = LSSTdefaults()
        cls.bandpassNameList = ['u', 'g', 'r', 'i', 'z', 'y']
        cls.m5 = [16.0+ix for ix in range(len(cls.bandpassNameList))]
        cls.seeing = [defaults._FWHMeff[bb] for bb in cls.bandpassNameList]
        cls.obs_metadata = makePhoSimTestDB(filename=cls.dbName, size=1,
                                            deltaRA=deltaRA,
                                            deltaDec=deltaDec,
                                            bandpass=cls.bandpassNameList,
                                            m5=cls.m5,
                                            seeing=cls.seeing,
                                            seedVal=65)

        cls.driver = 'sqlite'
コード例 #13
0
    def testMultipleImages(self):
        """
        Test that GalSimInterpreter puts the right number of counts on images of multiple objects
        """
        dbName = "galSimTestMultipleDB.db"
        driver = "sqlite"

        if os.path.exists(dbName):
            os.unlink(dbName)

        deltaRA = np.array([72.0 / 3600.0, 55.0 / 3600.0, 75.0 / 3600.0])
        deltaDec = np.array([0.0, 15.0 / 3600.0, -15.0 / 3600.0])
        obs_metadata = makePhoSimTestDB(
            filename=dbName,
            size=1,
            deltaRA=deltaRA,
            deltaDec=deltaDec,
            bandpass=self.bandpassNameList,
            m5=self.m5,
            seeing=self.seeing,
        )

        gals = testGalaxyBulgeDBObj(driver=driver, database=dbName)
        cat = testGalaxyCatalog(gals, obs_metadata=obs_metadata)
        catName = "multipleCatalog.sav"
        cat.write_catalog(catName)
        self.catalogTester(catName=catName, catalog=cat, nameRoot="multiple")
        if os.path.exists(catName):
            os.unlink(catName)

        stars = testStarsDBObj(driver=driver, database=dbName)
        cat = testStarCatalog(stars, obs_metadata=obs_metadata)
        catName = "multipleStarCatalog.sav"
        cat.write_catalog(catName)
        self.catalogTester(catName=catName, catalog=cat, nameRoot="multipleStars")
        if os.path.exists(catName):
            os.unlink(catName)

        if os.path.exists(dbName):
            os.unlink(dbName)
コード例 #14
0
    def setUpClass(cls):
        cls.dbName = "galSimTestDB.db"
        if os.path.exists(cls.dbName):
            os.unlink(cls.dbName)

        deltaRA = np.array([72.0 / 3600.0])
        deltaDec = np.array([0.0])
        defaults = LSSTdefaults()
        cls.bandpassNameList = ["u", "g", "r", "i", "z", "y"]
        cls.m5 = defaults._m5.values()
        cls.seeing = defaults._FWHMeff.values()
        cls.obs_metadata = makePhoSimTestDB(
            filename=cls.dbName,
            size=1,
            deltaRA=deltaRA,
            deltaDec=deltaDec,
            bandpass=cls.bandpassNameList,
            m5=cls.m5,
            seeing=cls.seeing,
        )

        cls.driver = "sqlite"
コード例 #15
0
 def setUp(self):
     self.tempDB = os.path.join(self.scratch_dir, 'PhoSimTestDatabase.db')
     self.obs_metadata = makePhoSimTestDB(size=10, filename=self.tempDB)
     self.bulgeDB = testGalaxyBulgeDBObj(driver='sqlite', database=self.tempDB)
     self.diskDB = testGalaxyDiskDBObj(driver='sqlite', database=self.tempDB)
     self.agnDB = testGalaxyAgnDBObj(driver='sqlite', database=self.tempDB)
     self.starDB = testStarsDBObj(driver='sqlite', database=self.tempDB)
     filter_translation = {'u': 0, 'g': 1, 'r': 2, 'i': 3, 'z': 4, 'y': 5}
     alt, az, pa = altAzPaFromRaDec(self.obs_metadata.pointingRA,
                                    self.obs_metadata.pointingDec,
                                    self.obs_metadata, includeRefraction=False)
     self.control_header = ['moondec %.7f\n' % np.degrees(self.obs_metadata.OpsimMetaData['moondec']),
                            'rottelpos %.7f\n' % np.degrees(self.obs_metadata.OpsimMetaData['rottelpos']),
                            'declination %.17f\n' % self.obs_metadata.pointingDec,
                            'moonalt %.7f\n' % np.degrees(self.obs_metadata.OpsimMetaData['moonalt']),
                            'rotskypos %.17f\n' % self.obs_metadata.rotSkyPos,
                            'moonra %.7f\n' % np.degrees(self.obs_metadata.OpsimMetaData['moonra']),
                            'sunalt %.7f\n' % np.degrees(self.obs_metadata.OpsimMetaData['sunalt']),
                            'mjd %.17f\n' % (self.obs_metadata.mjd.TAI+16.5/86400.0),
                            'azimuth %.17f\n' % az,
                            'rightascension %.17f\n' % self.obs_metadata.pointingRA,
                            'dist2moon %.7f\n' % np.degrees(self.obs_metadata.OpsimMetaData['dist2moon']),
                            'filter %d\n' % filter_translation[self.obs_metadata.bandpass],
                            'altitude %.17f\n' % alt]
コード例 #16
0
    def setUpClass(cls):
        cls.scratch_dir = os.path.join(getPackageDir('sims_GalSimInterface'),
                                       'tests', 'scratchSpace')

        cls.dbName = os.path.join(cls.scratch_dir, 'galSimTestDB.db')
        if os.path.exists(cls.dbName):
            os.unlink(cls.dbName)

        deltaRA = np.array([72.0 / 3600.0])
        deltaDec = np.array([0.0])
        defaults = LSSTdefaults()
        cls.bandpassNameList = ['u', 'g', 'r', 'i', 'z', 'y']
        cls.m5 = [16.0 + ix for ix in range(len(cls.bandpassNameList))]
        cls.seeing = [defaults._FWHMeff[bb] for bb in cls.bandpassNameList]
        cls.obs_metadata = makePhoSimTestDB(filename=cls.dbName,
                                            size=1,
                                            deltaRA=deltaRA,
                                            deltaDec=deltaDec,
                                            bandpass=cls.bandpassNameList,
                                            m5=cls.m5,
                                            seeing=cls.seeing,
                                            seedVal=65)

        cls.driver = 'sqlite'
コード例 #17
0
    def setUpClass(cls):
        lsstDefaults = LSSTdefaults()
        cls.dbName = 'uncertaintyTestDB.db'
        if os.path.exists(cls.dbName):
            os.unlink(cls.dbName)

        default_obs_metadata = makePhoSimTestDB(filename=cls.dbName,
                                                size=10,
                                                radius=5.0)
        bandpass = ['u', 'g', 'r', 'i', 'z', 'y']
        m5 = list(lsstDefaults._m5.values())

        cls.obs_metadata = ObservationMetaData(
            pointingRA=default_obs_metadata.pointingRA,
            pointingDec=default_obs_metadata.pointingDec,
            rotSkyPos=default_obs_metadata.rotSkyPos,
            bandpassName=bandpass,
            m5=m5)

        cls.obs_metadata.setBandpassM5andSeeing(bandpassName=bandpass, m5=m5)
        cls.driver = 'sqlite'
        cls.host = ''

        cls.skySeds = []
        cls.hardwareBandpasses = []
        cls.totalBandpasses = []
        cls.bandpasses = ['u', 'g', 'r', 'i', 'z', 'y']

        components = [
            'detector.dat', 'm1.dat', 'm2.dat', 'm3.dat', 'lens1.dat',
            'lens2.dat', 'lens3.dat'
        ]

        for b in cls.bandpasses:
            bandpassDummy = Bandpass()
            bandpassDummy.readThroughput(
                os.path.join(getPackageDir('throughputs'), 'baseline',
                             'total_%s.dat' % b))
            cls.totalBandpasses.append(bandpassDummy)

        for b in cls.bandpasses:
            finalComponents = []
            for c in components:
                finalComponents.append(
                    os.path.join(getPackageDir('throughputs'), 'baseline', c))
            finalComponents.append(
                os.path.join(getPackageDir('throughputs'), 'baseline',
                             'filter_%s.dat' % b))
            bandpassDummy = Bandpass()
            bandpassDummy.readThroughputList(finalComponents)
            cls.hardwareBandpasses.append(bandpassDummy)

        for i in range(len(cls.bandpasses)):
            sedDummy = Sed()
            sedDummy.readSED_flambda(
                os.path.join(getPackageDir('throughputs'), 'baseline',
                             'darksky.dat'))
            normalizedSedDummy = setM5(cls.obs_metadata.m5[cls.bandpasses[i]],
                                       sedDummy,
                                       cls.totalBandpasses[i],
                                       cls.hardwareBandpasses[i],
                                       FWHMeff=lsstDefaults.FWHMeff(
                                           cls.bandpasses[i]),
                                       photParams=PhotometricParameters())

            cls.skySeds.append(normalizedSedDummy)
コード例 #18
0
    def testPlacement(self):
        """
        Test that GalSimInterpreter puts objects on the right detectors.

        Do so by creating a catalog of 3 closely-packed stars.  Draw test FITS
        images of them using the GalSim Catalog infrastructure.  Draw control FITS
        images of the detectors in the camera, paranoidly including every star
        in every control image (GalSim contains code such that it will not
        actually add flux to an image in cases where we try to include a
        star that does not actually fall on a detector).  Compare that

        a) the fluxes of the test and control images agree within some tolerance

        b) the fluxes of control images that have no corresponding test image
        (i.e. detectors on which no star actually fell) are effectively zero
        """

        # generate the database
        np_rng = np.random.RandomState(32)
        gs_rng = galsim.UniformDeviate(112)
        catSize = 3
        dbName = "galSimPlacementTestDB.db"
        driver = "sqlite"
        if os.path.exists(dbName):
            os.unlink(dbName)

        deltaRA = (-40.0 + np_rng.random_sample(catSize) * (120.0)) / 3600.0
        deltaDec = (-20.0 + np_rng.random_sample(catSize) * (80.0)) / 3600.0
        obs_metadata = makePhoSimTestDB(
            filename=dbName,
            deltaRA=deltaRA,
            deltaDec=deltaDec,
            bandpass=self.bandpassNameList,
            m5=self.m5,
            seeing=self.seeing,
        )

        stars = testStarsDBObj(driver=driver, database=dbName)

        # create the catalog
        cat = testStarCatalog(stars, obs_metadata=obs_metadata)
        results = cat.iter_catalog()
        firstLine = True

        # iterate over the catalog, giving every star a chance to
        # illumine every detector
        controlImages = {}
        for i, line in enumerate(results):
            xPupil = line[5]
            yPupil = line[6]

            if firstLine:
                sedList = list(cat._calculateGalSimSeds())
                for detector in cat.galSimInterpreter.detectors:
                    for bandpass in cat.galSimInterpreter.bandpassDict:
                        controlImages[
                            "placementControl_"
                            + cat.galSimInterpreter._getFileName(detector=detector, bandpassName=bandpass)
                        ] = cat.galSimInterpreter.blankImage(detector=detector)

                firstLine = False

            for bp in cat.galSimInterpreter.bandpassDict:
                bandpass = cat.galSimInterpreter.bandpassDict[bp]
                adu = sedList[i].calcADU(bandpass, cat.photParams)
                for detector in cat.galSimInterpreter.detectors:
                    centeredObj = cat.galSimInterpreter.PSF.applyPSF(xPupil=xPupil, yPupil=yPupil)

                    xPix, yPix = pixelCoordsFromPupilCoords(
                        radiansFromArcsec(xPupil),
                        radiansFromArcsec(yPupil),
                        chipName=detector.name,
                        camera=detector.afwCamera,
                    )

                    dx = xPix - detector.xCenterPix
                    dy = yPix - detector.yCenterPix
                    obj = centeredObj.withFlux(adu * detector.photParams.gain)
                    localImage = cat.galSimInterpreter.blankImage(detector=detector)
                    localImage = obj.drawImage(
                        wcs=detector.wcs,
                        method="phot",
                        gain=detector.photParams.gain,
                        image=localImage,
                        offset=galsim.PositionD(dx, dy),
                        rng=gs_rng,
                    )

                    controlImages[
                        "placementControl_" + cat.galSimInterpreter._getFileName(detector=detector, bandpassName=bp)
                    ] += localImage

        self.assertGreater(len(controlImages), 0)

        for name in controlImages:
            controlImages[name].write(file_name=name)

        # write the test images using the catalog infrastructure
        testNames = cat.write_images(nameRoot="placementTest")

        # make sure that every test image has a corresponding control image
        for testName in testNames:
            controlName = testName.replace("Test", "Control")
            msg = "%s has no counterpart " % testName
            self.assertIn(controlName, controlImages, msg=msg)

        # make sure that the test and control images agree to some tolerance
        ignored = 0
        zeroFlux = 0
        valid = 0
        for controlName in controlImages:
            controlImage = afwImage.ImageF(controlName)
            controlFlux = controlImage.getArray().sum()

            testName = controlName.replace("Control", "Test")
            if testName in testNames:
                testImage = afwImage.ImageF(testName)
                testFlux = testImage.getArray().sum()
                if controlFlux > 1000.0:
                    countSigma = np.sqrt(controlFlux / cat.photParams.gain)
                    msg = "%s: controlFlux = %e, testFlux = %e, sigma %e" % (
                        controlName,
                        controlFlux,
                        testFlux,
                        countSigma,
                    )

                    # the randomness of photon shooting means that faint images won't agree
                    self.assertLess(np.abs(controlFlux - testFlux), 4.0 * countSigma, msg=msg)
                    valid += 1
                else:
                    ignored += 1
            else:
                # make sure that controlImages that have no corresponding test image really do
                # have zero flux (because no star fell on them)
                zeroFlux += 1
                msg = "%s has flux %e but was not written by catalog" % (controlName, controlFlux)
                self.assertLess(controlFlux, 1.0, msg=msg)

        self.assertGreater(valid, 0)
        self.assertLess(ignored, len(testNames) / 2)
        self.assertGreater(zeroFlux, 0)

        for testName in testNames:
            if os.path.exists(testName):
                os.unlink(testName)

        for controlName in controlImages:
            if os.path.exists(controlName):
                os.unlink(controlName)

        if os.path.exists(dbName):
            os.unlink(dbName)
コード例 #19
0
 def setUpClass(cls):
     cls.camera = obs_lsst_phosim.PhosimMapper().camera
     cls.db_name = tempfile.mktemp(dir=ROOT,
                                   prefix='PhoSimAstDB',
                                   suffix='.db')
     cls.obs = makePhoSimTestDB(filename=cls.db_name, size=1000)
コード例 #20
0
 def setUpClass(cls):
     cls.db_name = tempfile.mktemp(dir=ROOT, prefix='PhoSimAstDB', suffix='.db')
     cls.obs = makePhoSimTestDB(filename=cls.db_name,
                                size=1000)
コード例 #21
0
    def testPlacement(self):
        """
        Test that GalSimInterpreter puts objects on the right detectors.

        Do so by creating a catalog of 3 closely-packed stars.  Draw test FITS
        images of them using the GalSim Catalog infrastructure.  Draw control FITS
        images of the detectors in the camera, paranoidly including every star
        in every control image (GalSim contains code such that it will not
        actually add flux to an image in cases where we try to include a
        star that does not actually fall on a detector).  Compare that

        a) the fluxes of the test and control images agree within some tolerance

        b) the fluxes of control images that have no corresponding test image
        (i.e. detectors on which no star actually fell) are effectively zero
        """

        # generate the database
        np_rng = np.random.RandomState(32)
        gs_rng = galsim.UniformDeviate(112)
        catSize = 3
        dbName = 'galSimPlacementTestDB.db'
        driver = 'sqlite'
        if os.path.exists(dbName):
            os.unlink(dbName)

        deltaRA = (-40.0 + np_rng.random_sample(catSize) * (120.0)) / 3600.0
        deltaDec = (-20.0 + np_rng.random_sample(catSize) * (80.0)) / 3600.0
        obs_metadata = makePhoSimTestDB(filename=dbName,
                                        deltaRA=deltaRA,
                                        deltaDec=deltaDec,
                                        bandpass=self.bandpassNameList,
                                        m5=self.m5,
                                        seeing=self.seeing)

        stars = testStarsDBObj(driver=driver, database=dbName)

        # create the catalog
        cat = testStarCatalog(stars, obs_metadata=obs_metadata)
        results = cat.iter_catalog()
        firstLine = True

        # iterate over the catalog, giving every star a chance to
        # illumine every detector
        controlImages = {}
        for i, line in enumerate(results):
            xPupil = line[5]
            yPupil = line[6]

            if firstLine:
                sedList = list(cat._calculateGalSimSeds())
                for detector in cat.galSimInterpreter.detectors:
                    for bandpass in cat.galSimInterpreter.bandpassDict:
                        controlImages['placementControl_' +
                                      cat.galSimInterpreter._getFileName(detector=detector,
                                                                         bandpassName=bandpass)] = \
                            cat.galSimInterpreter.blankImage(detector=detector)

                firstLine = False

            for bp in cat.galSimInterpreter.bandpassDict:
                bandpass = cat.galSimInterpreter.bandpassDict[bp]
                adu = sedList[i].calcADU(bandpass, cat.photParams)
                for detector in cat.galSimInterpreter.detectors:
                    centeredObj = cat.galSimInterpreter.PSF.applyPSF(
                        xPupil=xPupil, yPupil=yPupil)

                    xPix, yPix = pixelCoordsFromPupilCoords(
                        radiansFromArcsec(xPupil),
                        radiansFromArcsec(yPupil),
                        chipName=detector.name,
                        camera=detector.afwCamera)

                    dx = xPix - detector.xCenterPix
                    dy = yPix - detector.yCenterPix
                    obj = centeredObj.withFlux(adu * detector.photParams.gain)
                    localImage = cat.galSimInterpreter.blankImage(
                        detector=detector)
                    localImage = obj.drawImage(wcs=detector.wcs,
                                               method='phot',
                                               gain=detector.photParams.gain,
                                               image=localImage,
                                               offset=galsim.PositionD(dx, dy),
                                               rng=gs_rng)

                    controlImages[
                        'placementControl_' +
                        cat.galSimInterpreter._getFileName(
                            detector=detector, bandpassName=bp)] += localImage

        self.assertGreater(len(controlImages), 0)

        for name in controlImages:
            controlImages[name].write(file_name=name)

        # write the test images using the catalog infrastructure
        testNames = cat.write_images(nameRoot='placementTest')

        # make sure that every test image has a corresponding control image
        for testName in testNames:
            controlName = testName.replace('Test', 'Control')
            msg = '%s has no counterpart ' % testName
            self.assertIn(controlName, controlImages, msg=msg)

        # make sure that the test and control images agree to some tolerance
        ignored = 0
        zeroFlux = 0
        valid = 0
        for controlName in controlImages:
            controlImage = afwImage.ImageF(controlName)
            controlFlux = controlImage.getArray().sum()

            testName = controlName.replace('Control', 'Test')
            if testName in testNames:
                testImage = afwImage.ImageF(testName)
                testFlux = testImage.getArray().sum()
                if controlFlux > 1000.0:
                    countSigma = np.sqrt(controlFlux / cat.photParams.gain)
                    msg = '%s: controlFlux = %e, testFlux = %e, sigma %e' \
                          % (controlName, controlFlux, testFlux, countSigma)

                    # the randomness of photon shooting means that faint images won't agree
                    self.assertLess(np.abs(controlFlux - testFlux),
                                    4.0 * countSigma,
                                    msg=msg)
                    valid += 1
                else:
                    ignored += 1
            else:
                # make sure that controlImages that have no corresponding test image really do
                # have zero flux (because no star fell on them)
                zeroFlux += 1
                msg = '%s has flux %e but was not written by catalog' % (
                    controlName, controlFlux)
                self.assertLess(controlFlux, 1.0, msg=msg)

        self.assertGreater(valid, 0)
        self.assertLess(ignored, len(testNames) / 2)
        self.assertGreater(zeroFlux, 0)

        for testName in testNames:
            if os.path.exists(testName):
                os.unlink(testName)

        for controlName in controlImages:
            if os.path.exists(controlName):
                os.unlink(controlName)

        if os.path.exists(dbName):
            os.unlink(dbName)
コード例 #22
0
 def setUpClass(cls):
     cls.db_name = tempfile.mktemp(dir=ROOT,
                                   prefix='PhoSimAstDB',
                                   suffix='.db')
     cls.obs = makePhoSimTestDB(filename=cls.db_name, size=1000)