Beispiel #1
0
    def testCatalog(self):
        """
        This test writes a PhoSim input catalog and compares it, one line at a time
        to a previously written catalog that should be identical.
        """
        testBulge = PhoSimCatalogSersic2D(self.bulgeDB,
                                          obs_metadata=self.obs_metadata)
        testDisk = PhoSimCatalogSersic2D(self.diskDB,
                                         obs_metadata=self.obs_metadata)
        testAgn = PhoSimCatalogZPoint(self.agnDB,
                                      obs_metadata=self.obs_metadata)
        testStar = PhoSimCatalogPoint(self.starDB,
                                      obs_metadata=self.obs_metadata)

        catName = os.path.join(getPackageDir('sims_catUtils'), 'tests',
                               'scratchSpace', 'phoSimTestCatalog.txt')

        testBulge.phoSimHeaderMap = test_header_map
        testBulge.write_catalog(catName)
        testDisk.write_catalog(catName, write_header=False, write_mode='a')
        testAgn.write_catalog(catName, write_header=False, write_mode='a')
        testStar.write_catalog(catName, write_header=False, write_mode='a')

        self.verify_catalog(catName)

        if os.path.exists(catName):
            os.unlink(catName)
    def test_default_values_in_header_map(self):
        """
        Test that default PhoSim header values in the header map get appropriately applied
        """
        test_header_map = {'lunar_distance': ('dist2moon', None), 'nsnap': 3}

        testBulge = PhoSimCatalogSersic2D(self.bulgeDB,
                                          obs_metadata=self.obs_metadata)
        testBulge.phoSimHeaderMap = test_header_map

        with lsst.utils.tests.getTempFilePath('.txt') as catName:
            testBulge.write_catalog(catName)

            with open(catName, 'r') as input_file:
                input_header = {}
                for line in input_file:
                    vv = line.split()
                    if vv[0] != 'object':
                        input_header[vv[0]] = vv[1]
                    else:
                        break

        self.assertIn('rightascension', input_header)
        self.assertIn('declination', input_header)
        self.assertIn('altitude', input_header)
        self.assertIn('azimuth', input_header)
        self.assertIn('filter', input_header)
        self.assertIn('rotskypos', input_header)
        self.assertIn('mjd', input_header)
        self.assertIn('lunar_distance', input_header)
        self.assertAlmostEqual(float(input_header['lunar_distance']),
                               self.obs_metadata.OpsimMetaData['dist2moon'], 6)
        self.assertIn('nsnap', input_header)
        self.assertEqual(int(input_header['nsnap']), 3)
        self.assertEqual(len(input_header), 9)
    def testBlankHeaderMap(self):
        """
        Test behavior of a blank header map
        """
        testBulge = PhoSimCatalogSersic2D(self.bulgeDB,
                                          obs_metadata=self.obs_metadata)
        testBulge.phoSimHeaderMap = {}

        with lsst.utils.tests.getTempFilePath('.txt') as catName:
            testBulge.write_catalog(catName)

            with open(catName, 'r') as input_file:
                input_header = {}
                for line in input_file:
                    vv = line.split()
                    if vv[0] != 'object':
                        input_header[vv[0]] = vv[1]
                    else:
                        break

        # verify that only the default header parameters are included in the
        # PhoSimInstanceCatalog, even though obs_metadata has a non-None
        # OpsimMetaData
        self.assertIn('rightascension', input_header)
        self.assertIn('declination', input_header)
        self.assertIn('altitude', input_header)
        self.assertIn('azimuth', input_header)
        self.assertIn('filter', input_header)
        self.assertIn('rotskypos', input_header)
        self.assertIn('mjd', input_header)
        self.assertEqual(len(input_header), 7)
        self.assertGreater(len(self.obs_metadata.OpsimMetaData), 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)
    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)
    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)
    def testSersicSchema(self):
        """
        Create a PhoSim InstanceCatalog of Sersic profiles (galaxy bulges).  Verify
        that the schema of the actual objects conforms to what PhoSim expects,
        as defined here

        https://bitbucket.org/phosim/phosim_release/wiki/Instance%20Catalog
        """
        cat = PhoSimCatalogSersic2D(self.bulgeDB,
                                    obs_metadata=self.obs_metadata)
        cat.phoSimHeaderMap = test_header_map

        with lsst.utils.tests.getTempFilePath('.txt') as cat_name:
            cat.write_catalog(cat_name)

            with open(cat_name, 'r') as input_file:
                cat_lines = input_file.readlines()

        n_obj = 0
        for line in cat_lines:
            params = line.split()
            if len(params) > 2:
                n_obj += 1
                self.assertEqual(len(params), 23)
                self.assertEqual(params[0], 'object')
                self.assertEqual(round(float(params[1])), float(params[1]),
                                 10)  # id
                float(params[2])  # ra
                float(params[3])  # dec
                float(params[4])  # mag norm
                self.assertIn('galaxySED', params[5])  # sed name
                self.assertGreater(float(params[6]), 0.0, 10)  # redshift
                self.assertAlmostEqual(float(params[7]), 0.0, 10)  # gamma1
                self.assertAlmostEqual(float(params[8]), 0.0, 10)  # gamma2
                self.assertAlmostEqual(float(params[9]), 0.0, 10)  # kappa
                self.assertAlmostEqual(float(params[10]), 0.0, 10)  # delta_ra
                self.assertAlmostEqual(float(params[11]), 0.0, 10)  # delta_dec
                self.assertEqual(params[12], 'sersic2d')  # source type
                self.assertGreater(float(params[13]), 0.0)  # major axis
                self.assertGreater(float(params[14]), 0.0)  # minor axis
                self.assertGreater(float(params[15]), 0.0)  # position angle
                self.assertAlmostEqual(float(params[16]), 4.0,
                                       13)  # n_s (bulges have sersic index=4)
                self.assertEqual(params[17], 'CCM')  # internal dust
                dust_msg = (
                    'It is possible you are outputting Milky Way dust parameters before '
                    'internal dust parameters; internal dust should come first'
                )
                self.assertLess(float(params[18]), 0.31, msg=dust_msg)  # Av
                self.assertLess(float(params[19]), 2.11, msg=dust_msg)  # Rv
                self.assertEqual(params[20], 'CCM')  # Milky Way dust
                self.assertGreater(float(params[21]), 0.0, msg=dust_msg)  # Av
                self.assertAlmostEqual(float(params[22]), 3.1,
                                       msg=dust_msg)  # Rv

        self.assertGreater(n_obj, 0)
    def testNoHeaderMap(self):
        """
        Test that the correct error is raised if no header map is specified
        """
        testBulge = PhoSimCatalogSersic2D(self.bulgeDB,
                                          obs_metadata=self.obs_metadata)

        with self.assertRaises(RuntimeError) as context:
            with lsst.utils.tests.getTempFilePath('.txt') as catName:
                testBulge.write_catalog(catName)

        self.assertIn("without specifying a phoSimHeaderMap",
                      context.exception.args[0])

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

        # now make sure that the exception is raised, even if ObservationMetaData
        # does not have an OpsimMetaData
        obs = ObservationMetaData(pointingRA=35.0,
                                  pointingDec=-23.0,
                                  mjd=43900.0,
                                  rotSkyPos=22.0,
                                  boundType='circle',
                                  boundLength=1.75)

        testBulge = PhoSimCatalogSersic2D(self.bulgeDB, obs_metadata=obs)
        with self.assertRaises(RuntimeError) as context:
            with lsst.utils.tests.getTempFilePath('.txt') as catName:
                testBulge.write_catalog(catName)

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

        self.assertIn("without specifying a phoSimHeaderMap",
                      context.exception.args[0])
        self.assertIn(
            "you may wish to consider adding default PhoSim parameters",
            context.exception.args[0])
    def testCatalog(self):
        """
        This test writes a PhoSim input catalog and compares it, one line at a time
        to a previously written catalog that should be identical.
        """
        testBulge = PhoSimCatalogSersic2D(self.bulgeDB,
                                          obs_metadata=self.obs_metadata)
        testDisk = PhoSimCatalogSersic2D(self.diskDB,
                                         obs_metadata=self.obs_metadata)
        testAgn = PhoSimCatalogZPoint(self.agnDB,
                                      obs_metadata=self.obs_metadata)
        testStar = PhoSimCatalogPoint(self.starDB,
                                      obs_metadata=self.obs_metadata)

        testBulge.phoSimHeaderMap = test_header_map
        with lsst.utils.tests.getTempFilePath('.txt') as catName:
            testBulge.write_catalog(catName)
            testDisk.write_catalog(catName, write_header=False, write_mode='a')
            testAgn.write_catalog(catName, write_header=False, write_mode='a')
            testStar.write_catalog(catName, write_header=False, write_mode='a')

            self.verify_catalog(catName)
Beispiel #10
0
    def testHeaderMap(self):
        """
        Test the behavior of the phoSimHeaderMap
        """
        testBulge = PhoSimCatalogSersic2D(self.bulgeDB,
                                          obs_metadata=self.obs_metadata)
        testBulge.phoSimHeaderMap = {
            'lunar_distance': ('dist2moon', None),
            'rotation_of_the_telescope': ('rottelpos', np.degrees),
            'other_rotation': ('rottelpos', lambda x: x * x)
        }

        catName = os.path.join(getPackageDir('sims_catUtils'), 'tests',
                               'scratchSpace', 'header_map_phosim_catalog.txt')
        testBulge.write_catalog(catName)

        with open(catName, 'r') as input_file:
            input_header = {}
            for line in input_file:
                vv = line.split()
                if vv[0] != 'object':
                    input_header[vv[0]] = vv[1]
                else:
                    break

        self.assertIn('rightascension', input_header)
        self.assertIn('declination', input_header)
        self.assertIn('altitude', input_header)
        self.assertIn('azimuth', input_header)
        self.assertIn('filter', input_header)
        self.assertIn('rotskypos', input_header)
        self.assertIn('mjd', input_header)
        self.assertIn('lunar_distance', input_header)
        self.assertAlmostEqual(float(input_header['lunar_distance']),
                               self.obs_metadata.OpsimMetaData['dist2moon'], 6)
        self.assertIn('rotation_of_the_telescope', input_header)
        self.assertAlmostEqual(
            float(input_header['rotation_of_the_telescope']),
            np.degrees(self.obs_metadata.OpsimMetaData['rottelpos']),
            delta=1.0e-6 *
            np.degrees(self.obs_metadata.OpsimMetaData['rottelpos']))
        self.assertIn('other_rotation', input_header)
        self.assertAlmostEqual(float(input_header['other_rotation']),
                               self.obs_metadata.OpsimMetaData['rottelpos']**2,
                               delta=1.0e-6 *
                               self.obs_metadata.OpsimMetaData['rottelpos']**2)
        self.assertEqual(len(input_header), 10)

        if os.path.exists(catName):
            os.unlink(catName)
    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)
Beispiel #12
0
    def test_default_values_in_header_map(self):
        """
        Test that default PhoSim header values in the header map get appropriately applied
        """
        test_header_map = {'lunar_distance': ('dist2moon', None), 'nsnap': 3}

        testBulge = PhoSimCatalogSersic2D(self.bulgeDB,
                                          obs_metadata=self.obs_metadata)
        testBulge.phoSimHeaderMap = test_header_map

        catName = os.path.join(getPackageDir('sims_catUtils'), 'tests',
                               'scratchSpace',
                               'default_value_header_map_phosim_catalog.txt')
        testBulge.write_catalog(catName)

        with open(catName, 'r') as input_file:
            input_header = {}
            for line in input_file:
                vv = line.split()
                if vv[0] != 'object':
                    input_header[vv[0]] = vv[1]
                else:
                    break

        self.assertIn('rightascension', input_header)
        self.assertIn('declination', input_header)
        self.assertIn('altitude', input_header)
        self.assertIn('azimuth', input_header)
        self.assertIn('filter', input_header)
        self.assertIn('rotskypos', input_header)
        self.assertIn('mjd', input_header)
        self.assertIn('lunar_distance', input_header)
        self.assertAlmostEqual(float(input_header['lunar_distance']),
                               self.obs_metadata.OpsimMetaData['dist2moon'], 6)
        self.assertIn('nsnap', input_header)
        self.assertEqual(int(input_header['nsnap']), 3)
        self.assertEqual(len(input_header), 9)

        if os.path.exists(catName):
            os.unlink(catName)
Beispiel #13
0
    def testBlankHeaderMap(self):
        """
        Test behavior of a blank header map
        """
        testBulge = PhoSimCatalogSersic2D(self.bulgeDB,
                                          obs_metadata=self.obs_metadata)
        testBulge.phoSimHeaderMap = {}

        catName = os.path.join(getPackageDir('sims_catUtils'), 'tests',
                               'scratchSpace',
                               'blank_header_map_phosim_catalog.txt')
        testBulge.write_catalog(catName)

        with open(catName, 'r') as input_file:
            input_header = {}
            for line in input_file:
                vv = line.split()
                if vv[0] != 'object':
                    input_header[vv[0]] = vv[1]
                else:
                    break

        # verify that only the default header parameters are included in the
        # PhoSimInstanceCatalog, even though obs_metadata has a non-None
        # OpsimMetaData
        self.assertIn('rightascension', input_header)
        self.assertIn('declination', input_header)
        self.assertIn('altitude', input_header)
        self.assertIn('azimuth', input_header)
        self.assertIn('filter', input_header)
        self.assertIn('rotskypos', input_header)
        self.assertIn('mjd', input_header)
        self.assertEqual(len(input_header), 7)
        self.assertGreater(len(self.obs_metadata.OpsimMetaData), 0)

        if os.path.exists(catName):
            os.unlink(catName)
    def testCompoundCatalog(self):
        """
        This test writes a PhoSim input catalog and compares it, one line at a time
        to a previously written catalog that should be identical.

        This test uses CompoundInstanceCatalog
        """

        # first, generate the catalog without a CompoundInstanceCatalog
        single_catName = tempfile.mktemp(dir=ROOT,
                                         prefix='phoSimTestCatalog_single',
                                         suffix='.txt')

        testBulge = PhoSimCatalogSersic2D(self.bulgeDB,
                                          obs_metadata=self.obs_metadata)
        testDisk = PhoSimCatalogSersic2D(self.diskDB,
                                         obs_metadata=self.obs_metadata)
        testAgn = PhoSimCatalogZPoint(self.agnDB,
                                      obs_metadata=self.obs_metadata)
        testStar = PhoSimCatalogPoint(self.starDB,
                                      obs_metadata=self.obs_metadata)

        testBulge.phoSimHeaderMap = test_header_map
        testBulge.write_catalog(single_catName)
        testDisk.write_catalog(single_catName,
                               write_header=False,
                               write_mode='a')
        testAgn.write_catalog(single_catName,
                              write_header=False,
                              write_mode='a')
        testStar.write_catalog(single_catName,
                               write_header=False,
                               write_mode='a')

        # now, generate the catalog using CompoundInstanceCatalog
        #
        # because the CompoundCatalogDBObject requires that database
        # connection parameters be set in the input CatalogDBObject
        # daughter class definitions, we have to declare dummy
        # CatalogDBObject daughter classes below

        class dummyDBbase(object):
            driver = 'sqlite'
            database = 'PhoSimTestDatabase.db'

        dummyDBbase.database = self.tempDB

        class dummyBulgeDB(dummyDBbase, testGalaxyBulgeDBObj):
            objid = 'dummy_bulge'

        class dummyDiskDB(dummyDBbase, testGalaxyDiskDBObj):
            objid = 'dummy_disk'

        class dummyAgnDB(dummyDBbase, testGalaxyAgnDBObj):
            objid = 'dummy_agn'

        class dummyStarDB(dummyDBbase, testStarsDBObj):
            objid = 'dummy_stars'

        compoundCatalog = CompoundInstanceCatalog(
            [
                PhoSimCatalogSersic2D, PhoSimCatalogSersic2D,
                PhoSimCatalogZPoint, PhoSimCatalogPoint
            ], [dummyBulgeDB, dummyDiskDB, dummyAgnDB, dummyStarDB],
            obs_metadata=self.obs_metadata)

        self.assertEqual(len(compoundCatalog._dbObjectGroupList[0]), 3)

        compound_catName = tempfile.mktemp(dir=ROOT,
                                           prefix='phoSimTestCatalog_compound',
                                           suffix='.txt')

        compoundCatalog.phoSimHeaderMap = test_header_map
        compoundCatalog.write_catalog(compound_catName)

        # verify that the compound catalog is what we expect
        self.verify_catalog(compound_catName)

        # verify that the two catalogs are equivalent
        with open(single_catName, 'r') as single_file:
            with open(compound_catName, 'r') as compound_file:
                single_lines = single_file.readlines()
                compound_lines = compound_file.readlines()

                for line in single_lines:
                    self.assertIn(line, compound_lines)

                for line in compound_lines:
                    self.assertIn(line, single_lines)

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

        if os.path.exists(single_catName):
            os.unlink(single_catName)
    def test_non_existent_values_in_header_map(self):
        """
        Test that header params that are defined in the header map but not
        in OpsimMetaData are ommitted from the header
        """
        test_header_map = {
            'lunar_distance': ('dist2moon', None),
            'nsnap': 3,
            'nonesense': ('gobbledygook', lambda x: 2.0 * x)
        }

        testBulge = PhoSimCatalogSersic2D(self.bulgeDB,
                                          obs_metadata=self.obs_metadata)
        testBulge.phoSimHeaderMap = test_header_map

        with lsst.utils.tests.getTempFilePath('.txt') as catName:
            testBulge.write_catalog(catName)

            with open(catName, 'r') as input_file:
                input_header = {}
                for line in input_file:
                    vv = line.split()
                    if vv[0] != 'object':
                        input_header[vv[0]] = vv[1]
                    else:
                        break

        self.assertIn('rightascension', input_header)
        self.assertIn('declination', input_header)
        self.assertIn('altitude', input_header)
        self.assertIn('azimuth', input_header)
        self.assertIn('filter', input_header)
        self.assertIn('rotskypos', input_header)
        self.assertIn('mjd', input_header)
        self.assertIn('lunar_distance', input_header)
        self.assertAlmostEqual(float(input_header['lunar_distance']),
                               self.obs_metadata.OpsimMetaData['dist2moon'], 6)
        self.assertIn('nsnap', input_header)
        self.assertEqual(int(input_header['nsnap']), 3)
        self.assertEqual(len(input_header), 9)

        # now try it with no OpsimMetaData at all
        obs = ObservationMetaData(pointingRA=23.0,
                                  pointingDec=-11.0,
                                  mjd=43000.0,
                                  rotSkyPos=44.0,
                                  bandpassName='g',
                                  boundType='circle',
                                  boundLength=1.0)
        testBulge = PhoSimCatalogSersic2D(self.bulgeDB, obs_metadata=obs)
        testBulge.phoSimHeaderMap = test_header_map
        with lsst.utils.tests.getTempFilePath('.txt') as catName:
            testBulge.write_catalog(catName)

            with open(catName, 'r') as input_file:
                input_header = {}
                for line in input_file:
                    vv = line.split()
                    if vv[0] != 'object':
                        input_header[vv[0]] = vv[1]
                    else:
                        break

        self.assertIn('rightascension', input_header)
        self.assertIn('declination', input_header)
        self.assertIn('altitude', input_header)
        self.assertIn('azimuth', input_header)
        self.assertIn('filter', input_header)
        self.assertIn('rotskypos', input_header)
        self.assertIn('mjd', input_header)
        self.assertIn('nsnap', input_header)
        self.assertEqual(int(input_header['nsnap']), 3)
        self.assertEqual(len(input_header), 8)
    def testGalSimPhoSimCat(self):
        """
        Run a GalSimPhoSim catalog on some data. Then, generate an ordinary PhoSim catalog using
        the same data.  Verify that the two resulting PhoSim catalogs are identical.
        """

        galsim_cat_name = os.path.join(self.dataDir,
                                       'galSimPhoSim_galsim_cat.txt')
        phosim_cat_name = os.path.join(self.dataDir,
                                       'galSimPhoSim_phosim_cat.txt')
        galsim_image_root = os.path.join(self.dataDir, 'galSimPhoSim_images')
        db = fileDBObject(self.bulge_name,
                          dtype=self.dtype,
                          runtable='test_bulges',
                          idColKey='id')
        db.raColName = 'ra_deg'
        db.decColName = 'dec_deg'
        db.objectTypeId = 55

        gs_cat = GalSimPhoSimGalaxies(db, obs_metadata=self.obs)
        gs_cat.camera_wrapper = GalSimCameraWrapper(self.camera)
        gs_cat.bandpassNames = self.obs.bandpass
        gs_cat.PSF = SNRdocumentPSF()
        gs_cat.phoSimHeaderMap = {}
        gs_cat.write_catalog(galsim_cat_name)

        gs_cat_0 = gs_cat

        ps_cat = PhoSimCatalogSersic2D(db, obs_metadata=self.obs)
        ps_cat.phoSimHeaderMap = {}
        ps_cat.write_catalog(phosim_cat_name)

        db = fileDBObject(self.disk_name,
                          dtype=self.dtype,
                          runtable='test_disks',
                          idColKey='id')
        db.raColName = 'ra_deg'
        db.decColName = 'dec_deg'
        db.objectTypeId = 155

        gs_cat = GalSimPhoSimGalaxies(db, obs_metadata=self.obs)
        gs_cat.bandpassNames = self.obs.bandpass
        gs_cat.copyGalSimInterpreter(gs_cat_0)
        gs_cat.write_catalog(galsim_cat_name,
                             write_header=False,
                             write_mode='a')

        gs_cat_0 = gs_cat

        ps_cat = PhoSimCatalogSersic2D(db, obs_metadata=self.obs)
        ps_cat.write_catalog(phosim_cat_name,
                             write_header=False,
                             write_mode='a')

        db = fileDBObject(self.agn_name,
                          dtype=self.dtype,
                          runtable='test_agn',
                          idColKey='id')
        db.raColName = 'ra_deg'
        db.decColName = 'dec_deg'
        db.objectTypeId = 255

        gs_cat = GalSimPhoSimAgn(db, obs_metadata=self.obs)
        gs_cat.bandpassNames = self.obs.bandpass
        gs_cat.copyGalSimInterpreter(gs_cat_0)
        gs_cat.write_catalog(galsim_cat_name,
                             write_header=False,
                             write_mode='a')

        gs_cat_0 = gs_cat

        ps_cat = PhoSimCatalogZPoint(db, obs_metadata=self.obs)
        ps_cat.write_catalog(phosim_cat_name,
                             write_header=False,
                             write_mode='a')

        db = fileDBObject(self.star_name,
                          dtype=self.dtype,
                          runtable='test_agn',
                          idColKey='id')
        db.raColName = 'ra_deg'
        db.decColName = 'dec_deg'
        db.objectTypeId = 255

        gs_cat = GalSimPhoSimStars(db, obs_metadata=self.obs)
        gs_cat.bandpassNames = self.obs.bandpass
        gs_cat.copyGalSimInterpreter(gs_cat_0)
        gs_cat.write_catalog(galsim_cat_name,
                             write_header=False,
                             write_mode='a')

        ps_cat = PhoSimCatalogPoint(db, obs_metadata=self.obs)
        ps_cat.write_catalog(phosim_cat_name,
                             write_header=False,
                             write_mode='a')

        written_files = gs_cat.write_images(nameRoot=galsim_image_root)
        self.assertGreater(len(written_files), 0)
        for name in written_files:
            os.unlink(name)

        with open(galsim_cat_name, 'r') as galsim_input:
            with open(phosim_cat_name, 'r') as phosim_input:
                galsim_lines = galsim_input.readlines()
                phosim_lines = phosim_input.readlines()
                self.assertEqual(len(galsim_lines), len(phosim_lines))
                self.assertEqual(len(galsim_lines), 4 * self.n_objects + 7)
                for line in galsim_lines:
                    self.assertIn(line, phosim_lines)
                for line in phosim_lines:
                    self.assertIn(line, galsim_lines)

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

        if os.path.exists(phosim_cat_name):
            os.unlink(phosim_cat_name)
Beispiel #17
0
        star_cat = MaskedPhoSimCatalogPoint(star_db, obs_metadata=obs)
        star_cat.phoSimHeaderMap = phosim_header_map
        bright_cat = BrightStarCatalog(star_db,
                                       obs_metadata=obs,
                                       cannot_be_null=['isBright'])
        star_cat.min_mag = args.min_mag
        bright_cat.min_mag = args.min_mag

        from lsst.sims.catalogs.definitions import parallelCatalogWriter
        cat_dict = {}
        cat_dict[os.path.join(out_dir, star_name)] = star_cat
        cat_dict[os.path.join(out_dir,
                              'bright_stars_%d.txt' % obshistid)] = bright_cat
        parallelCatalogWriter(cat_dict, chunk_size=100000, write_header=False)

        cat = PhoSimCatalogSersic2D(bulge_db, obs_metadata=obs)
        cat.write_catalog(os.path.join(out_dir, gal_name),
                          write_header=False,
                          chunk_size=100000)
        cat = PhoSimCatalogSersic2D(disk_db, obs_metadata=obs)
        cat.write_catalog(os.path.join(out_dir, gal_name),
                          write_header=False,
                          write_mode='a',
                          chunk_size=100000)

        cat = PhoSimCatalogZPoint(agn_db, obs_metadata=obs)
        cat.write_catalog(os.path.join(out_dir, agn_name),
                          write_header=False,
                          chunk_size=100000)

        for orig_name in (star_name, gal_name, agn_name):