Coverage for tests/testSetupRoutines.py : 25%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
lsst.utils.tests.init()
""" A class with no photometry columns. Meant to be passed to setupPhotometryCatalog where it will be given photometry columns """
""" Baseline photometry catalog against which to compare testStarCatalog """
""" A class with no photometry columns. Meant to be passed to setupPhotometryCatalog where it will be given photometry columns """
""" Baseline photometry catalog against which to compare testGalaxyCatalog """
""" CatalogDBObject to map our test database of stars """ ('raJ2000', 'ra*PI()/180.'), ('decJ2000', 'decl*PI()/180.'), ('magNorm', None), ('properMotionRa', '(mura/(1000.*3600.))*PI()/180.'), ('properMotionDec', '(mudecl/(1000.*3600.))*PI()/180.'), ('parallax', 'parallax*PI()/648000000.'), ('galacticAv', '3.1*ebv'), ('radialVelocity', 'vrad'), ('variabilityParameters', 'varParamStr', str, 256), ('sedFilename', 'sedfilename', str, 40)]
#: This is the base table for the galaxies # tableid = 'final_clone_db'
('galid', None, str, 30), ('raJ2000', 'ra*PI()/180.'), ('decJ2000', 'dec*PI()/180.'), ('raJ2000Bulge', 'bra*PI()/180.'), ('decJ2000Bulge', 'bdec*PI()/180.'), ('raJ2000Disk', 'dra*PI()/180.'), ('decJ2000Disk', 'ddec*PI()/180.'), ('raJ2000Agn', 'agnra*PI()/180.'), ('decJ2000Agn', 'agndec*PI()/180.'), ('magNormBulge', 'magnorm_bulge'), ('magNormDisk', 'magnorm_disk'), ('magNormAgn', 'magnorm_agn'), ('sedFilenameBulge', 'sedname_bulge', str, 40), ('sedFilenameDisk', 'sedname_disk', str, 40), ('sedFilenameAgn', 'sedname_agn', str, 40), ('majorAxisBulge', 'a_b*PI()/648000.'), ('minorAxisBulge', 'b_b*PI()/648000.'), ('positionAngleBulge', 'pa_bulge*PI()/180.'), ('sindexBulge', 'bulge_n', int), ('majorAxisDisk', 'a_d*PI()/648000.'), ('minorAxisDisk', 'b_d*PI()/648000.'), ('positionAngleDisk', 'pa_disk*PI()/180.'), ('sindexDisk', 'disk_n', int), ('internalExtinctionModelBulge', 'ext_model_b', str, 3), ('internalAvBulge', 'av_b'), ('internalRvBulge', 'rv_b'), ('internalExtinctionModelDisk', 'ext_model_d', str, 3), ('internalAvDisk', 'av_d'), ('internalRvDisk', 'rv_d'), ('lsst_u', 'u_ab'), ('lsst_g', 'g_ab'), ('lsst_r', 'r_ab'), ('lsst_i', 'i_ab'), ('lsst_z', 'z_ab'), ('lsst_y', 'y_ab')]
def setUpClass(cls): cls.scratch_dir = tempfile.mkdtemp(dir=ROOT, prefix='InstanceCatalogSetupUnittest-')
def tearDownClass(cls): sims_clean_up() if os.path.exists(cls.scratch_dir): shutil.rmtree(cls.scratch_dir)
self.driver = 'sqlite' self.StarDBName = os.path.join(self.scratch_dir, 'testSetup_setupTestStars.db')
self.GalaxyDBName = os.path.join(self.scratch_dir, 'testSetup_setupTestGalaxies.db')
self.pointingRA = 50.0 self.pointingDec = -5.0 self.radius = 1.0 makeStarDatabase(filename=self.StarDBName, size=100, pointingRA=self.pointingRA, pointingDec=self.pointingDec, radius=self.radius)
makeGalaxyDatabase(filename=self.GalaxyDBName, size=100, pointingRA=self.pointingRA, pointingDec=self.pointingDec, radius=self.radius)
self.starDBObj = testStarDBObject(driver=self.driver, database= self.StarDBName) self.galaxyDBObj = testGalaxyDBObject(driver=self.driver, database=self.GalaxyDBName)
self.obs_metadata = ObservationMetaData(pointingRA=self.pointingRA, pointingDec=self.pointingDec, boundType='circle', boundLength=self.radius, bandpassName='g', mjd=57000.0, m5=24.5)
self.obs_metadata_compound = ObservationMetaData(pointingRA=self.pointingRA, pointingDec=self.pointingDec, boundType='circle', boundLength=self.radius, bandpassName=['g', 'i'], mjd=57000.0, m5=[24.5, 17.5])
if os.path.exists(self.StarDBName): os.unlink(self.StarDBName)
if os.path.exists(self.GalaxyDBName): os.unlink(self.GalaxyDBName)
del self.starDBObj del self.galaxyDBObj del self.StarDBName del self.GalaxyDBName del self.pointingRA del self.pointingDec del self.radius del self.obs_metadata
""" Make sure that setupPhotometryCatalog throws errors when it is supposed to """
class dummyClass(object): def __init__(self): pass
xx = dummyClass() self.assertRaises(RuntimeError, setupPhotometryCatalog, obs_metadata=xx, dbConnection=self.starDBObj, catalogClass=testStarCatalog)
self.assertRaises(RuntimeError, setupPhotometryCatalog, obs_metadata=self.obs_metadata, dbConnection=xx, catalogClass=testStarCatalog)
self.assertRaises(RuntimeError, setupPhotometryCatalog, obs_metadata=self.obs_metadata, dbConnection=self.starDBObj, catalogClass=dummyClass)
""" Make sure that catalogs instantiated by setupPhotometryCatalog contain the correct columns. """
# test case with a single bandpass cat = setupPhotometryCatalog(obs_metadata=self.obs_metadata, dbConnection=self.starDBObj, catalogClass=testStarCatalog)
self.assertIn('lsst_g', cat.iter_column_names()) self.assertNotIn('lsst_u', cat.iter_column_names()) self.assertNotIn('lsst_r', cat.iter_column_names()) self.assertNotIn('lsst_i', cat.iter_column_names()) self.assertNotIn('lsst_z', cat.iter_column_names()) self.assertNotIn('lsst_y', cat.iter_column_names()) self.assertNotIn('sigma_lsst_g', cat.iter_column_names()) self.assertNotIn('sigma_lsst_u', cat.iter_column_names()) self.assertNotIn('sigma_lsst_r', cat.iter_column_names()) self.assertNotIn('sigma_lsst_i', cat.iter_column_names()) self.assertNotIn('sigma_lsst_z', cat.iter_column_names()) self.assertNotIn('sigma_lsst_y', cat.iter_column_names())
cat = setupPhotometryCatalog(obs_metadata=self.obs_metadata, dbConnection=self.starDBObj, catalogClass=testStarCatalog, uncertainty=True)
self.assertIn('lsst_g', cat.iter_column_names()) self.assertNotIn('lsst_u', cat.iter_column_names()) self.assertNotIn('lsst_r', cat.iter_column_names()) self.assertNotIn('lsst_i', cat.iter_column_names()) self.assertNotIn('lsst_z', cat.iter_column_names()) self.assertNotIn('lsst_y', cat.iter_column_names()) self.assertIn('sigma_lsst_g', cat.iter_column_names()) self.assertNotIn('sigma_lsst_u', cat.iter_column_names()) self.assertNotIn('sigma_lsst_r', cat.iter_column_names()) self.assertNotIn('sigma_lsst_i', cat.iter_column_names()) self.assertNotIn('sigma_lsst_z', cat.iter_column_names()) self.assertNotIn('sigma_lsst_y', cat.iter_column_names())
# test case with two bandpasses cat = setupPhotometryCatalog(obs_metadata=self.obs_metadata_compound, dbConnection=self.starDBObj, catalogClass=testStarCatalog)
self.assertIn('lsst_g', cat.iter_column_names()) self.assertIn('lsst_i', cat.iter_column_names()) self.assertNotIn('lsst_u', cat.iter_column_names()) self.assertNotIn('lsst_r', cat.iter_column_names()) self.assertNotIn('lsst_z', cat.iter_column_names()) self.assertNotIn('lsst_y', cat.iter_column_names()) self.assertNotIn('sigma_lsst_g', cat.iter_column_names()) self.assertNotIn('sigma_lsst_u', cat.iter_column_names()) self.assertNotIn('sigma_lsst_r', cat.iter_column_names()) self.assertNotIn('sigma_lsst_i', cat.iter_column_names()) self.assertNotIn('sigma_lsst_z', cat.iter_column_names()) self.assertNotIn('sigma_lsst_y', cat.iter_column_names())
cat = setupPhotometryCatalog(obs_metadata=self.obs_metadata_compound, dbConnection=self.starDBObj, catalogClass=testStarCatalog, uncertainty=True)
self.assertIn('lsst_g', cat.iter_column_names()) self.assertIn('lsst_i', cat.iter_column_names()) self.assertNotIn('lsst_u', cat.iter_column_names()) self.assertNotIn('lsst_r', cat.iter_column_names()) self.assertNotIn('lsst_z', cat.iter_column_names()) self.assertNotIn('lsst_y', cat.iter_column_names()) self.assertIn('sigma_lsst_g', cat.iter_column_names()) self.assertIn('sigma_lsst_i', cat.iter_column_names()) self.assertNotIn('sigma_lsst_u', cat.iter_column_names()) self.assertNotIn('sigma_lsst_r', cat.iter_column_names()) self.assertNotIn('sigma_lsst_z', cat.iter_column_names()) self.assertNotIn('sigma_lsst_y', cat.iter_column_names())
# make sure that class default columns did not get overwritten cat = testStarCatalog(self.starDBObj, obs_metadata=self.obs_metadata)
self.assertNotIn('lsst_u', cat.iter_column_names()) self.assertNotIn('lsst_g', cat.iter_column_names()) self.assertNotIn('lsst_r', cat.iter_column_names()) self.assertNotIn('lsst_i', cat.iter_column_names()) self.assertNotIn('lsst_z', cat.iter_column_names()) self.assertNotIn('lsst_y', cat.iter_column_names())
""" Make sure that the values written to catalogs that are instantiated using setupPhotometryCatalog are correct """ msgroot = ['failed on stars; ', 'failed on galaxies; ']
testCatClasses = [testStarCatalog, testGalaxyCatalog] testCatDBs = [self.starDBObj, self.galaxyDBObj] baselineCats = [] baselineCats.append(baselineStarCatalog(self.starDBObj, obs_metadata=self.obs_metadata_compound, column_outputs=['lsst_g', 'sigma_lsst_g', 'lsst_i', 'sigma_lsst_i']))
baselineCats.append(baselineGalaxyCatalog(self.galaxyDBObj, obs_metadata=self.obs_metadata_compound, column_outputs=['lsst_g', 'sigma_lsst_g', 'lsst_i', 'sigma_lsst_i']))
basedtype = np.dtype([('raObserved', np.float), ('decObserved', np.float), ('lsst_g', np.float), ('sigma_lsst_g', np.float), ('lsst_i', np.float), ('sigma_lsst_i', np.float)])
for (testCatClass, dbo, baselineCat, msgr) in zip(testCatClasses, testCatDBs, baselineCats, msgroot):
testdtype = np.dtype([('raObserved', np.float), ('decObserved', np.float), ('lsst_g', np.float)])
testCat = setupPhotometryCatalog(obs_metadata=self.obs_metadata, dbConnection=dbo, catalogClass=testCatClass)
with lsst.utils.tests.getTempFilePath('.txt') as testName: testCat.write_catalog(testName) testData = np.genfromtxt(testName, dtype=testdtype, delimiter=',')
with lsst.utils.tests.getTempFilePath('.txt') as baseName: baselineCat.write_catalog(baseName) baseData = np.genfromtxt(baseName, dtype=basedtype, delimiter=',')
self.assertGreater(len(testData), 0) self.assertGreater(len(baseData), 0)
ct = 0 for b, t in zip(baseData, testData): self.assertAlmostEqual(b['lsst_g'], t['lsst_g'], 12, msg = '%s single column; %.12e != %.12e' % (msgr, b['lsst_g'], t['lsst_g'])) ct += 1
self.assertGreater(ct, 0)
testdtype = np.dtype([('raObserved', np.float), ('decObserved', np.float), ('lsst_g', np.float), ('lsst_i', np.float)])
testCat = setupPhotometryCatalog(obs_metadata=self.obs_metadata_compound, dbConnection=dbo, catalogClass=testCatClass) with lsst.utils.tests.getTempFilePath('.txt') as testName: testCat.write_catalog(testName) testData = np.genfromtxt(testName, dtype=testdtype, delimiter=',') self.assertGreater(len(testData), 0) ct = 0 for b, t in zip(baseData, testData): self.assertAlmostEqual(b['lsst_g'], t['lsst_g'], 12, msg = '%s double column; %.12e != %.12e ' % (msgr, b['lsst_g'], t['lsst_g'])) self.assertAlmostEqual(b['lsst_i'], t['lsst_i'], 12, msg = '%s double column; %.12e != %.12e ' % (msgr, b['lsst_i'], t['lsst_i'])) ct += 1
self.assertGreater(ct, 0)
""" Make sure that the values written to catalogs that are instantiated using setupPhotometryCatalog are correct (include photometric uncertainty) """
msgroot = ['failed on stars; ', 'failed on galaxies; ']
testCatClasses = [testStarCatalog, testGalaxyCatalog] testCatDBs = [self.starDBObj, self.galaxyDBObj] baselineCats = []
# need to set up the baseline catalogs with the compound obs_metadata so that they get the # correct m5 values for both magnitudes (otherwise, they will use LSST defaults, which # disagree with our cartoon test case) baselineCats.append(baselineStarCatalog(self.starDBObj, obs_metadata=self.obs_metadata_compound, column_outputs=['lsst_g', 'lsst_i', 'sigma_lsst_g', 'sigma_lsst_i']))
baselineCats.append(baselineGalaxyCatalog(self.galaxyDBObj, obs_metadata=self.obs_metadata_compound, column_outputs=['lsst_g', 'lsst_i', 'sigma_lsst_g', 'sigma_lsst_i']))
basedtype = np.dtype([('raObserved', np.float), ('decObserved', np.float), ('lsst_g', np.float), ('lsst_i', np.float), ('sigma_lsst_g', np.float), ('sigma_lsst_i', np.float)])
for (testCatClass, dbo, baselineCat, msgr) in zip(testCatClasses, testCatDBs, baselineCats, msgroot):
testCat = setupPhotometryCatalog(obs_metadata=self.obs_metadata, dbConnection=dbo, catalogClass=testCatClass, uncertainty=True)
testdtype = np.dtype([('raObserved', np.float), ('decObserved', np.float), ('lsst_g', np.float), ('sigma_lsst_g', np.float)])
with lsst.utils.tests.getTempFilePath('.txt') as testName: testCat.write_catalog(testName) testData = np.genfromtxt(testName, dtype=testdtype, delimiter=',') with lsst.utils.tests.getTempFilePath('.txt') as baseName: baselineCat.write_catalog(baseName) baseData = np.genfromtxt(baseName, dtype=basedtype, delimiter=',') self.assertGreater(len(testData), 0) self.assertGreater(len(baseData), 0)
ct = 0 for b, t in zip(baseData, testData): self.assertAlmostEqual(b['lsst_g'], t['lsst_g'], 12, msg = '%s single column; %.12e != %.12e ' % (msgr, b['lsst_g'], t['lsst_g'])) self.assertAlmostEqual(b['sigma_lsst_g'], t['sigma_lsst_g'], 12, msg = '%s sigle column; %.12e != %.12e ' % (msgr, b['sigma_lsst_i'], t['sigma_lsst_g'])) ct += 1
self.assertGreater(ct, 0)
testdtype = np.dtype([('raObserved', np.float), ('decObserved', np.float), ('lsst_g', np.float), ('sigma_lsst_g', np.float), ('lsst_i', np.float), ('sigma_lsst_i', np.float)])
testCat = setupPhotometryCatalog(obs_metadata=self.obs_metadata_compound, dbConnection=dbo, catalogClass=testCatClass, uncertainty=True) with lsst.utils.tests.getTempFilePath('.txt') as testName: testCat.write_catalog(testName) testData = np.genfromtxt(testName, dtype=testdtype, delimiter=',') self.assertGreater(len(testData), 0) ct = 0 for b, t in zip(baseData, testData): self.assertAlmostEqual(b['lsst_g'], t['lsst_g'], 12, msg = '%s double column; %.12e != %.12e ' % (msgr, b['lsst_g'], t['lsst_g'])) self.assertAlmostEqual(b['lsst_i'], t['lsst_i'], 12, msg = '%s double column; %.12e != %.12e ' % (msgr, b['lsst_i'], t['lsst_i'])) self.assertAlmostEqual(b['sigma_lsst_g'], t['sigma_lsst_g'], 12, msg = '%s double column; %.12e != %.12e ' % (msgr, b['sigma_lsst_g'], t['lsst_g'])) self.assertAlmostEqual(b['sigma_lsst_i'], t['sigma_lsst_i'], 12, msg = '%s double column; %.12e != %.12e ' % (msgr, b['sigma_lsst_i'], t['sigma_lsst_i'])) ct += 1
self.assertGreater(ct, 0)
lsst.utils.tests.init() unittest.main() |