Esempio n. 1
0
    def setUpClass(cls):

        cls.write_star_txt()
        cls.write_galaxy_txt()

        cls.dbName = os.path.join(getPackageDir('sims_catalogs_measures'),
                                  'tests', 'scratchSpace',
                                  'ConnectionPassingTestDB.db')

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

        galDtype = np.dtype([('id', np.int), ('raJ2000', np.float),
                             ('decJ2000', np.float), ('redshift', np.float),
                             ('umag', np.float), ('gmag', np.float)])

        starDtype = np.dtype([('id', np.int), ('raJ2000', np.float),
                              ('decJ2000', np.float), ('umag', np.float),
                              ('gmag', np.float)])

        dbo = fileDBObject(cls.star_txt_name,
                           database=cls.dbName,
                           driver='sqlite',
                           runtable='stars',
                           idColKey='id',
                           dtype=starDtype)

        dbo = fileDBObject(cls.gal_txt_name,
                           database=cls.dbName,
                           driver='sqlite',
                           runtable='galaxies',
                           idColKey='id',
                           dtype=galDtype)
    def setUpClass(cls):

        cls.write_star_txt()
        cls.write_galaxy_txt()

        cls.dbName = os.path.join(getPackageDir('sims_catalogs_measures'), 'tests',
                                  'scratchSpace', 'ConnectionPassingTestDB.db')

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

        galDtype = np.dtype([('id', np.int),
                             ('raJ2000', np.float), ('decJ2000', np.float),
                             ('redshift', np.float), ('umag', np.float),
                             ('gmag', np.float)])

        starDtype = np.dtype([('id', np.int), ('raJ2000', np.float),
                              ('decJ2000', np.float), ('umag', np.float),
                              ('gmag', np.float)])


        dbo = fileDBObject(cls.star_txt_name,
                           database=cls.dbName, driver='sqlite',
                           runtable='stars', idColKey='id',
                           dtype=starDtype)

        dbo = fileDBObject(cls.gal_txt_name,
                           database=cls.dbName, driver='sqlite',
                           runtable='galaxies', idColKey='id',
                           dtype=galDtype)
    def setUpClass(cls):

        cls.obs = ObservationMetaData(bandpassName=['u', 'g', 'r', 'i', 'z', 'y'],
                                      m5 = [22.0, 23.0, 24.0, 25.0, 26.0, 27.0])

        baselineDtype = np.dtype([(name, np.float) for name in baselineStarCatalog.column_outputs])

        dbdtype = np.dtype([
                           ('id', np.int),
                           ('raJ2000', np.float),
                           ('decJ2000', np.float),
                           ('sedFilename', str, 100),
                           ('magNorm', np.float),
                           ('galacticAv', np.float)
                           ])

        inputDir = os.path.join(getPackageDir('sims_catUtils'), 'tests', 'testData')
        inputFile = os.path.join(inputDir, 'IndicesTestCatalogStars.txt')

        cls.db = fileDBObject(inputFile, runtable='test',
                              idColKey='id', dtype=dbdtype)

        cat = baselineStarCatalog(cls.db, obs_metadata=cls.obs)
        cls.catName = os.path.join(getPackageDir('sims_catUtils'), 'tests',
                                   'scratchSpace', 'indicesStarsControlCat.txt')

        cat.write_catalog(cls.catName)
        cls.controlData = np.genfromtxt(cls.catName, dtype=baselineDtype, delimiter=',')
    def setUpClass(cls):
        cls.dbFile = os.path.join(getPackageDir('sims_catUtils'),
                        'tests', 'testData', 'SSMphotometryCatalog.txt')

        cls.dtype = np.dtype([('id', np.int), ('sedFilename', str, 100), ('magNorm', np.float),
                              ('velRa', np.float), ('velDec', np.float)])

        cls.photDB = fileDBObject(cls.dbFile, runtable='test', dtype=cls.dtype, idColKey='id')
    def setUpClass(cls):
        cls.dbFile = os.path.join(getPackageDir('sims_catUtils'),
                        'tests', 'testData', 'SSMastrometryCatalog.txt')

        cls.dtype = np.dtype([('id', np.int), ('raJ2000', np.float), ('decJ2000', np.float),
                              ('velRa', np.float), ('velDec', np.float)])

        cls.astDB = fileDBObject(cls.dbFile, runtable='test', dtype=cls.dtype, idColKey='id')
    def setUpClass(cls):
        cls.baseDir = os.path.join(getPackageDir('sims_catalogs_generation'),
                                   'tests', 'scratchSpace')


        cls.textFileName = os.path.join(cls.baseDir, 'compound_obs_metadata_text_data.txt')

        numpy.random.seed(42)
        nSamples = 100
        raList = numpy.random.random_sample(nSamples)*360.0
        decList = numpy.random.random_sample(nSamples)*180.0 - 90.0
        magList = numpy.random.random_sample(nSamples)*15.0 + 7.0

        dtype = numpy.dtype([
                            ('ra', numpy.float),
                            ('dec', numpy.float),
                            ('mag', numpy.float)
                            ])

        cls.controlArray = numpy.rec.fromrecords([
                                                  (r, d, m) \
                                                  for r, d, m in \
                                                  zip(raList, decList, magList)
                                                  ], dtype=dtype)

        dbDtype = numpy.dtype([
                              ('id', numpy.int),
                              ('ra', numpy.float),
                              ('dec', numpy.float),
                              ('mag', numpy.float)
                              ])

        if os.path.exists(cls.textFileName):
            os.unlink(cls.textFileName)

        with open(cls.textFileName, 'w') as output:
            output.write('# id ra dec mag\n')
            for ix, (r, d, m) in enumerate(zip(raList, decList, magList)):
                output.write('%d %.20f %.20f %.20f\n' % (ix, r, d, m))

        cls.dbName = os.path.join(cls.baseDir, 'compound_obs_metadata_db.db')

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

        fdbo = fileDBObject(cls.textFileName, runtable='test',
                            database=cls.dbName, dtype=dbDtype,
                            idColKey='id')
Esempio n. 7
0
def write_star_file_db(file_name):

    np.random.seed(88)
    nstars = 10000
    ra = np.random.random_sample(nstars)*360.0
    dec = (np.random.random_sample(nstars)-0.5)*180.0
    umag = np.random.random_sample(nstars)*10.0 + 15.0
    gmag = np.random.random_sample(nstars)*10.0 + 15.0
    rmag = np.random.random_sample(nstars)*10.0 + 15.0
    imag = np.random.random_sample(nstars)*10.0 + 15.0
    zmag = np.random.random_sample(nstars)*10.0 + 15.0
    ymag = np.random.random_sample(nstars)*10.0 + 15.0

    with open(file_name, 'w') as output_file:
        for ix, (rr, dd, um, gm, rm, im, zm, ym) in \
            enumerate(zip(ra, dec, umag, gmag, rmag, imag, zmag, ymag)):

            output_file.write('%d %.12f %.12f %.12f %.12f %.12f %.12f %.12f %.12f\n' %
                              (ix, rr, dd, um, gm, rm, im, zm, ym))

    starDtype = np.dtype([
                          ('id', np.int),
                          ('raJ2000', np.float),
                          ('decJ2000', np.float),
                          ('umag', np.float),
                          ('gmag', np.float),
                          ('rmag', np.float),
                          ('imag', np.float),
                          ('zmag', np.float),
                          ('ymag', np.float)
                        ])


    starDB = fileDBObject(file_name, runtable='stars', dtype=starDtype, idColKey='id')
    starDB.raColName = 'raJ2000'
    starDB.decColName = 'decJ2000'

    controlData = np.genfromtxt(file_name, dtype=starDtype)

    return starDB, controlData
    def setUpClass(cls):

        cls.obs = ObservationMetaData(bandpassName=['u', 'g', 'r', 'i', 'z', 'y'],
                                      m5=[24.0, 25.0, 26.0, 27.0, 28.0, 29.0])

        dtype = np.dtype([
                         ('id', np.int),
                         ('sedFilenameBulge', str, 100),
                         ('magNormBulge', np.float),
                         ('sedFilenameDisk', str, 100),
                         ('magNormDisk', np.float),
                         ('sedFilenameAgn', str, 100),
                         ('magNormAgn', np.float),
                         ('internalAvBulge', np.float),
                         ('internalAvDisk', np.float),
                         ('galacticAv', np.float),
                         ('redshift', np.float)
                         ])

        inputDir = os.path.join(getPackageDir('sims_catUtils'), 'tests', 'testData')
        inputFile = os.path.join(inputDir, 'IndicesTestCatalogGalaxies.txt')
        cls.db = fileDBObject(inputFile, dtype=dtype, runtable='test',
                               idColKey='id')

        cls.db.objectTypeId = 44

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

        cat = baselineGalaxyCatalog(cls.db, obs_metadata=cls.obs)
        cat.write_catalog(catName)

        dtype = np.dtype([(name, np.float) for name in cat.column_outputs])

        cls.controlData = np.genfromtxt(catName, dtype=dtype, delimiter=',')

        if os.path.exists(catName):
            os.unlink(catName)
    def setUpClass(cls):
        numpy.random.seed(42)
        dtype = numpy.dtype([
                            ('a', numpy.float),
                            ('b', numpy.float),
                            ('c', numpy.float),
                            ('d', str, 20)
                            ])

        nSamples=100
        aList = numpy.random.random_sample(nSamples)*10.0
        bList = numpy.random.random_sample(nSamples)*(-1.0)
        cList = numpy.random.random_sample(nSamples)*10.0-5.0
        ww = 'a'
        dList = []
        for ix in range(nSamples):
            ww += 'b'
            dList.append(ww)

        cls.controlArray = numpy.rec.fromrecords([
                                                 (aa, bb, cc, dd) \
                                                 for aa, bb, cc ,dd in \
                                                 zip(aList, bList, cList, dList)
                                                 ], dtype=dtype)


        baseDir = os.path.join(getPackageDir('sims_catalogs_generation'),
                               'tests', 'scratchSpace')

        cls.textFileName = os.path.join(baseDir, 'compound_test_data.txt')
        if os.path.exists(cls.textFileName):
            os.unlink(cls.textFileName)

        with open(cls.textFileName, 'w') as output:
            output.write('# id a b c d\n')
            for ix, (aa, bb, cc, dd) in enumerate(zip(aList, bList, cList, dList)):
                output.write('%d %e %e %e %s\n' % (ix, aa, bb, cc, dd))



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

        cls.otherDbName = os.path.join(baseDir, 'otherDb.db')
        if os.path.exists(cls.otherDbName):
            os.unlink(cls.otherDbName)

        dtype = numpy.dtype([
                            ('id', numpy.int),
                            ('a', numpy.float),
                            ('b', numpy.float),
                            ('c', numpy.float),
                            ('d', str, 20)
                            ])

        fdbo = fileDBObject(cls.textFileName, runtable='test',
                            database=cls.dbName, dtype=dtype,
                            idColKey='id')

        fdbo = fileDBObject(cls.textFileName, runtable='test',
                            database=cls.otherDbName, dtype=dtype,
                            idColKey='id')

        fdbo = fileDBObject(cls.textFileName, runtable='otherTest',
                            database=cls.dbName, dtype=dtype,
                            idColKey='id')
    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.bandpassNames = self.obs.bandpass
        gs_cat.PSF = SNRdocumentPSF()
        gs_cat.write_catalog(galsim_cat_name)

        gs_cat_0 = gs_cat

        ps_cat = PhoSimCatalogSersic2D(db, obs_metadata=self.obs)
        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+5)
                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)
    def setUpClass(cls):
        cls.baseDir = os.path.join(getPackageDir('sims_catalogs_measures'),
                               'tests', 'scratchSpace')

        cls.table1FileName = os.path.join(cls.baseDir, 'compound_table1.txt')
        cls.table2FileName = os.path.join(cls.baseDir, 'compound_table2.txt')

        if os.path.exists(cls.table1FileName):
            os.unlink(cls.table1FileName)
        if os.path.exists(cls.table2FileName):
            os.unlink(cls.table2FileName)

        dtype1 = numpy.dtype([
                           ('ra', numpy.float),
                           ('dec', numpy.float),
                           ('mag', numpy.float),
                           ('dmag', numpy.float),
                           ('dra', numpy.float),
                           ('ddec', numpy.float)
                           ])

        dbDtype1 = numpy.dtype([
                           ('id', numpy.int),
                           ('ra', numpy.float),
                           ('dec', numpy.float),
                           ('mag', numpy.float),
                           ('dmag', numpy.float),
                           ('dra', numpy.float),
                           ('ddec', numpy.float)
                           ])

        nPts = 100
        numpy.random.seed(42)
        raList = numpy.random.random_sample(nPts)*360.0
        decList = numpy.random.random_sample(nPts)*180.0-90.0
        magList = numpy.random.random_sample(nPts)*10.0+15.0
        dmagList = numpy.random.random_sample(nPts)*10.0 - 5.0
        draList = numpy.random.random_sample(nPts)*5.0 - 2.5
        ddecList = numpy.random.random_sample(nPts)*(-2.0) - 4.0

        cls.table1Control = numpy.rec.fromrecords([
                                                  (r, d, mm, dm, dr, dd) \
                                                  for r, d, mm, dm, dr, dd \
                                                  in zip(raList, decList,
                                                         magList, dmagList,
                                                         draList, ddecList)],
                                                  dtype=dtype1
                                                  )

        with open(cls.table1FileName, 'w') as output:
            output.write("# id ra dec mag dmag dra ddec\n")
            for ix, (r, d, mm, dm, dr, dd) in \
            enumerate(zip(raList, decList, magList, dmagList, draList, ddecList)):

                output.write('%d %.12f %.12f %.12f %.12f %.12f %.12f\n' \
                             % (ix, r, d, mm, dm, dr, dd))


        dtype2 = numpy.dtype([
                            ('ra', numpy.float),
                            ('dec', numpy.float),
                            ('mag', numpy.float)
                            ])

        dbDtype2 = numpy.dtype([
                            ('id', numpy.int),
                            ('ra', numpy.float),
                            ('dec', numpy.float),
                            ('mag', numpy.float)
                            ])

        ra2List = numpy.random.random_sample(nPts)*360.0
        dec2List = numpy.random.random_sample(nPts)*180.0-90.0
        mag2List = numpy.random.random_sample(nPts)*10+18.0

        cls.table2Control = numpy.rec.fromrecords([
                                                  (r, d, m) \
                                                  for r, d, m in \
                                                  zip(ra2List, dec2List, mag2List)
                                                  ], dtype=dtype2)

        with open(cls.table2FileName, 'w') as output:
            output.write('# id ra dec mag\n')
            for ix, (r, d, m) in enumerate(zip(ra2List, dec2List, mag2List)):
                output.write('%d %.12f %.12f %.12f\n' % (ix, r, d, m))

        cls.dbName = cartoonDBbase().database
        if os.path.exists(cls.dbName):
            os.unlink(cls.dbName)

        fdbo = fileDBObject(cls.table1FileName, runtable='table1',
                            database=cls.dbName, dtype=dbDtype1,
                            idColKey='id')

        fdbo = fileDBObject(cls.table2FileName, runtable='table2',
                            database=cls.dbName, dtype=dbDtype2,
                            idColKey='id')
    def setUpClass(cls):
        cls.baseDir = os.path.join(getPackageDir('sims_catalogs_measures'),
                                   'tests', 'scratchSpace')

        cls.table1FileName = os.path.join(cls.baseDir, 'compound_table1.txt')
        cls.table2FileName = os.path.join(cls.baseDir, 'compound_table2.txt')

        if os.path.exists(cls.table1FileName):
            os.unlink(cls.table1FileName)
        if os.path.exists(cls.table2FileName):
            os.unlink(cls.table2FileName)

        dtype1 = numpy.dtype([('ra', numpy.float), ('dec', numpy.float),
                              ('mag', numpy.float), ('dmag', numpy.float),
                              ('dra', numpy.float), ('ddec', numpy.float)])

        dbDtype1 = numpy.dtype([('id', numpy.int), ('ra', numpy.float),
                                ('dec', numpy.float), ('mag', numpy.float),
                                ('dmag', numpy.float), ('dra', numpy.float),
                                ('ddec', numpy.float)])

        nPts = 100
        numpy.random.seed(42)
        raList = numpy.random.random_sample(nPts) * 360.0
        decList = numpy.random.random_sample(nPts) * 180.0 - 90.0
        magList = numpy.random.random_sample(nPts) * 10.0 + 15.0
        dmagList = numpy.random.random_sample(nPts) * 10.0 - 5.0
        draList = numpy.random.random_sample(nPts) * 5.0 - 2.5
        ddecList = numpy.random.random_sample(nPts) * (-2.0) - 4.0

        cls.table1Control = numpy.rec.fromrecords([
                                                  (r, d, mm, dm, dr, dd) \
                                                  for r, d, mm, dm, dr, dd \
                                                  in zip(raList, decList,
                                                         magList, dmagList,
                                                         draList, ddecList)],
                                                  dtype=dtype1
                                                  )

        with open(cls.table1FileName, 'w') as output:
            output.write("# id ra dec mag dmag dra ddec\n")
            for ix, (r, d, mm, dm, dr, dd) in \
            enumerate(zip(raList, decList, magList, dmagList, draList, ddecList)):

                output.write('%d %.12f %.12f %.12f %.12f %.12f %.12f\n' \
                             % (ix, r, d, mm, dm, dr, dd))

        dtype2 = numpy.dtype([('ra', numpy.float), ('dec', numpy.float),
                              ('mag', numpy.float)])

        dbDtype2 = numpy.dtype([('id', numpy.int), ('ra', numpy.float),
                                ('dec', numpy.float), ('mag', numpy.float)])

        ra2List = numpy.random.random_sample(nPts) * 360.0
        dec2List = numpy.random.random_sample(nPts) * 180.0 - 90.0
        mag2List = numpy.random.random_sample(nPts) * 10 + 18.0

        cls.table2Control = numpy.rec.fromrecords([
                                                  (r, d, m) \
                                                  for r, d, m in \
                                                  zip(ra2List, dec2List, mag2List)
                                                  ], dtype=dtype2)

        with open(cls.table2FileName, 'w') as output:
            output.write('# id ra dec mag\n')
            for ix, (r, d, m) in enumerate(zip(ra2List, dec2List, mag2List)):
                output.write('%d %.12f %.12f %.12f\n' % (ix, r, d, m))

        cls.dbName = cartoonDBbase().database
        if os.path.exists(cls.dbName):
            os.unlink(cls.dbName)

        fdbo = fileDBObject(cls.table1FileName,
                            runtable='table1',
                            database=cls.dbName,
                            dtype=dbDtype1,
                            idColKey='id')

        fdbo = fileDBObject(cls.table2FileName,
                            runtable='table2',
                            database=cls.dbName,
                            dtype=dbDtype2,
                            idColKey='id')