def testFakeSeds(self): """ Test GalSim catalog with alternate Seds """ catName = os.path.join(self.scratch_dir, 'testFakeSedCat.sav') m5 = [22.0, 23.0, 25.0] seeing = [0.6, 0.5, 0.7] bandpassNames = ['x', 'y', 'z'] obs_metadata = ObservationMetaData( pointingRA=self.obs_metadata.pointingRA, pointingDec=self.obs_metadata.pointingDec, rotSkyPos=self.obs_metadata.rotSkyPos, mjd=self.obs_metadata.mjd, bandpassName=bandpassNames, m5=m5, seeing=seeing) stars = testStarsDBObj(driver=self.driver, database=self.dbName) cat = testFakeSedCatalog(stars, obs_metadata=obs_metadata) cat.write_catalog(catName) bandpassDir = os.path.join(getPackageDir('sims_catUtils'), 'tests', 'testThroughputs') sedDir = os.path.join(getPackageDir('sims_catUtils'), 'tests', 'testSeds') self.catalogTester(catName=catName, catalog=cat, nameRoot='fakeBandpass', bandpassDir=bandpassDir, bandpassRoot='fakeTotal_', sedDir=sedDir) if os.path.exists(catName): os.unlink(catName)
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) displacedRA = numpy.array([72.0/3600.0, 55.0/3600.0, 75.0/3600.0]) displacedDec = numpy.array([0.0, 15.0/3600.0, -15.0/3600.0]) obs_metadata = makePhoSimTestDB(filename=dbName, size=1, displacedRA=displacedRA, displacedDec=displacedDec, 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)
def testStellarPhotometricUncertainties(self): """ Test in the case of a catalog of stars """ lsstDefaults = LSSTdefaults() starDB = testStarsDBObj(driver=self.driver, host=self.host, database=self.dbName) starCat = testStarCatalog(starDB, obs_metadata=self.obs_metadata) phot = PhotometryStars() ct = 0 for line in starCat.iter_catalog(): starSed = Sed() starSed.readSED_flambda(os.path.join(lsst.utils.getPackageDir('sims_sed_library'), defaultSpecMap[line[14]])) imsimband = Bandpass() imsimband.imsimBandpass() fNorm = starSed.calcFluxNorm(line[15], imsimband) starSed.multiplyFluxNorm(fNorm) aV = numpy.float(line[16]) a_int, b_int = starSed.setupCCMab() starSed.addCCMDust(a_int, b_int, A_v=aV) for i in range(len(self.bandpasses)): controlSigma = calcMagError_sed(starSed, self.totalBandpasses[i], self.skySeds[i], self.hardwareBandpasses[i], FWHMeff=lsstDefaults.FWHMeff(self.bandpasses[i]), photParams=PhotometricParameters()) testSigma = line[8+i] self.assertAlmostEqual(controlSigma, testSigma, 4) ct += 1 self.assertGreater(ct, 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)
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 ]
def testFakeSeds(self): """ Test GalSim catalog with alternate Seds """ catName = 'testFakeSedCat.sav' m5 = [22.0, 23.0, 25.0] seeing = [0.6, 0.5, 0.7] bandpassNames = ['x', 'y', 'z'] obs_metadata = ObservationMetaData( unrefractedRA=self.obs_metadata.unrefractedRA, unrefractedDec=self.obs_metadata.unrefractedDec, rotSkyPos=self.obs_metadata.rotSkyPos, mjd=self.obs_metadata.mjd, bandpassName=bandpassNames, m5=m5, seeing=seeing) stars = testStarsDBObj(driver=self.driver, database=self.dbName) cat = testFakeSedCatalog(stars, obs_metadata=obs_metadata) cat.write_catalog(catName) bandpassDir = os.path.join(lsst.utils.getPackageDir('sims_catUtils'), 'tests', 'testThroughputs') sedDir = os.path.join(lsst.utils.getPackageDir('sims_catUtils'), 'tests', 'testSeds') self.catalogTester(catName=catName, catalog=cat, nameRoot='fakeBandpass', bandpassDir=bandpassDir, bandpassRoot='fakeTotal_', sedDir=sedDir) if os.path.exists(catName): os.unlink(catName)
def testFakeSeds(self): """ Test GalSim catalog with alternate Seds """ catName = "testFakeSedCat.sav" m5 = [22.0, 23.0, 25.0] seeing = [0.6, 0.5, 0.7] bandpassNames = ["x", "y", "z"] obs_metadata = ObservationMetaData( pointingRA=self.obs_metadata.pointingRA, pointingDec=self.obs_metadata.pointingDec, rotSkyPos=self.obs_metadata.rotSkyPos, mjd=self.obs_metadata.mjd, bandpassName=bandpassNames, m5=m5, seeing=seeing, ) stars = testStarsDBObj(driver=self.driver, database=self.dbName) cat = testFakeSedCatalog(stars, obs_metadata=obs_metadata) cat.write_catalog(catName) bandpassDir = os.path.join(lsst.utils.getPackageDir("sims_catUtils"), "tests", "testThroughputs") sedDir = os.path.join(lsst.utils.getPackageDir("sims_catUtils"), "tests", "testSeds") self.catalogTester( catName=catName, catalog=cat, nameRoot="fakeBandpass", bandpassDir=bandpassDir, bandpassRoot="fakeTotal_", sedDir=sedDir, ) if os.path.exists(catName): os.unlink(catName)
def setUp(self): self.obs_metadata = makePhoSimTestDB(size=10) self.bulgeDB = testGalaxyBulgeDBObj(driver='sqlite', database='PhoSimTestDatabase.db') self.diskDB = testGalaxyDiskDBObj(driver='sqlite', database='PhoSimTestDatabase.db') self.agnDB = testGalaxyAgnDBObj(driver='sqlite', database='PhoSimTestDatabase.db') self.starDB = testStarsDBObj(driver='sqlite', database='PhoSimTestDatabase.db') baseLineFileName = lsst.utils.getPackageDir('sims_catUtils')+'/tests/testData/phoSimControlCatalog.txt' self.baseLineFile = open(baseLineFileName,'r')
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)
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)
def testStars(self): """ Test that GalSimInterpreter puts the right number of counts on images of stars """ catName = 'testStarCat.sav' stars = testStarsDBObj(driver=self.driver, database=self.dbName) cat = testStarCatalog(stars, obs_metadata = self.obs_metadata) cat.write_catalog(catName) self.catalogTester(catName=catName, catalog=cat, nameRoot='stars') if os.path.exists(catName): os.unlink(catName)
def setUp(cls): cls.dbName = 'PhoSimVariabilityDatabase.db' if os.path.exists(cls.dbName): os.unlink(cls.dbName) cls.obs_metadata = makePhoSimTestDB(size=10, filename=cls.dbName) 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)
def testStars(self): """ Test that GalSimInterpreter puts the right number of counts on images of stars """ catName = os.path.join(self.scratch_dir, 'testStarCat.sav') stars = testStarsDBObj(driver=self.driver, database=self.dbName) cat = testStarCatalog(stars, obs_metadata=self.obs_metadata) cat.write_catalog(catName) self.catalogTester(catName=catName, catalog=cat, nameRoot='stars') if os.path.exists(catName): os.unlink(catName)
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)
def test_stellar_astrometry_radians(self): """ Test that we can go from raPhoSim, decPhoSim to ICRS coordinates in the case of stars (in radians) """ cat_name = os.path.join(self.scratch_dir, 'phosim_ast_star_cat_rad.txt') if os.path.exists(cat_name): os.unlink(cat_name) db = testStarsDBObj(driver='sqlite', database=self.db_name) cat = StarTestCatalog(db, obs_metadata=self.obs) cat.write_catalog(cat_name) dtype = np.dtype([('raICRS', float), ('decICRS', float), ('raPhoSim', float), ('decPhoSim', float)]) data = np.genfromtxt(cat_name, dtype=dtype) self.assertGreater(len(data), 100) ra_pho_rad = np.radians(data['raPhoSim']) dec_pho_rad = np.radians(data['decPhoSim']) # verify that, when transforming back to ICRS, we are within # 10^-3 arcsec ra_icrs, dec_icrs = PhoSimAstrometryBase._icrsFromPhoSim( ra_pho_rad, dec_pho_rad, self.obs) dist = _angularSeparation(np.radians(data['raICRS']), np.radians(data['decICRS']), ra_icrs, dec_icrs) dist = arcsecFromRadians(dist) self.assertLess(dist.max(), 0.001) # verify that the distance between raPhoSim, decPhoSim and # raICRS, decICRS is greater than the distance between # the original raICRS, decICRS and the newly-calculated # raICRS, decICRS dist_bad = _angularSeparation(ra_pho_rad, dec_pho_rad, np.radians(data['raICRS']), np.radians(data['decICRS'])) dist_bad = arcsecFromRadians(dist_bad) self.assertGreater(dist_bad.min(), dist.max()) if os.path.exists(cat_name): os.unlink(cat_name) del db
def test_stellar_astrometry_radians(self): """ Test that we can go from raPhoSim, decPhoSim to ICRS coordinates in the case of stars (in radians) """ db = testStarsDBObj(driver='sqlite', database=self.db_name) cat = StarTestCatalog(db, obs_metadata=self.obs) with lsst.utils.tests.getTempFilePath('.txt') as cat_name: cat.write_catalog(cat_name) dtype = np.dtype([('raICRS', float), ('decICRS', float), ('raPhoSim', float), ('decPhoSim', float), ('raJ2000', float), ('decJ2000', float), ('pmRA', float), ('pmDec', float), ('parallax', float), ('vRad', float)]) data = np.genfromtxt(cat_name, dtype=dtype) self.assertGreater(len(data), 100) ra_pho_rad = np.radians(data['raPhoSim']) dec_pho_rad = np.radians(data['decPhoSim']) # verify that, when transforming back to ICRS, we are within # 10^-3 arcsec ra_icrs, dec_icrs = PhoSimAstrometryBase._icrsFromPhoSim(ra_pho_rad, dec_pho_rad, self.obs) dist = _angularSeparation(np.radians(data['raICRS']), np.radians(data['decICRS']), ra_icrs, dec_icrs) dist = arcsecFromRadians(dist) self.assertLess(dist.max(), 0.001) # verify that the distance between raPhoSim, decPhoSim and # raICRS, decICRS is greater than the distance between # the original raICRS, decICRS and the newly-calculated # raICRS, decICRS dist_bad = _angularSeparation(ra_pho_rad, dec_pho_rad, np.radians(data['raICRS']), np.radians(data['decICRS'])) dist_bad = arcsecFromRadians(dist_bad) self.assertGreater(dist_bad.min(), dist.max()) del db
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)
def setUp(self): self.obs_metadata = makePhoSimTestDB(size=10) self.bulgeDB = testGalaxyBulgeDBObj(driver='sqlite', database='PhoSimTestDatabase.db') self.diskDB = testGalaxyDiskDBObj(driver='sqlite', database='PhoSimTestDatabase.db') self.agnDB = testGalaxyAgnDBObj(driver='sqlite', database='PhoSimTestDatabase.db') self.starDB = testStarsDBObj(driver='sqlite', database='PhoSimTestDatabase.db') filter_translation={'u':0,'g':1, 'r':2, 'i':3, 'z':4, 'y':5} self.control_header = ['Opsim_moondec %.9g\n' % numpy.degrees(self.obs_metadata.phoSimMetaData['Opsim_moondec'][0]), 'Opsim_rottelpos %.9g\n' % numpy.degrees(self.obs_metadata.phoSimMetaData['Opsim_rottelpos'][0]), 'Unrefracted_Dec %.9g\n' % numpy.degrees(self.obs_metadata.phoSimMetaData['pointingDec'][0]), 'Opsim_moonalt %.9g\n' % numpy.degrees(self.obs_metadata.phoSimMetaData['Opsim_moonalt'][0]), 'Opsim_rotskypos %.9g\n' % numpy.degrees(self.obs_metadata.phoSimMetaData['Opsim_rotskypos'][0]), 'Opsim_moonra %.9g\n' % numpy.degrees(self.obs_metadata.phoSimMetaData['Opsim_moonra'][0]), 'Opsim_sunalt %.9g\n' % numpy.degrees(self.obs_metadata.phoSimMetaData['Opsim_sunalt'][0]), 'Opsim_expmjd %.9g\n' % self.obs_metadata.phoSimMetaData['Opsim_expmjd'][0], 'Unrefracted_Azimuth %.9g\n' % numpy.degrees(self.obs_metadata.phoSimMetaData['Unrefracted_Azimuth'][0]), 'Unrefracted_RA %.9g\n' % numpy.degrees(self.obs_metadata.phoSimMetaData['pointingRA'][0]), 'Opsim_dist2moon %.9g\n' % numpy.degrees(self.obs_metadata.phoSimMetaData['Opsim_dist2moon'][0]), 'Opsim_filter %d\n' % filter_translation[self.obs_metadata.phoSimMetaData['Opsim_filter'][0]], 'Unrefracted_Altitude %.9g\n' % numpy.degrees(self.obs_metadata.phoSimMetaData['Unrefracted_Altitude'][0])]
def test_stellar_observed_degrees(self): """ Test ability to go all the way to observed RA, Dec from PhoSim (this is necessary for the ImSim software that DESC is working on) """ db = testStarsDBObj(driver='sqlite', database=self.db_name) cat = StarTestCatalog(db, obs_metadata=self.obs) with lsst.utils.tests.getTempFilePath('.txt') as cat_name: cat.write_catalog(cat_name) dtype = np.dtype([('raICRS', float), ('decICRS', float), ('raPhoSim', float), ('decPhoSim', float), ('raJ2000', float), ('decJ2000', float), ('pmRA', float), ('pmDec', float), ('parallax', float), ('vRad', float)]) data = np.genfromtxt(cat_name, dtype=dtype) self.assertGreater(len(data), 100) (ra_obs, dec_obs) = observedFromICRS(np.degrees(data['raJ2000']), np.degrees(data['decJ2000']), obs_metadata=self.obs, pm_ra=arcsecFromRadians(data['pmRA']), pm_dec=arcsecFromRadians(data['pmDec']), parallax=arcsecFromRadians(data['parallax']), v_rad=data['vRad'], includeRefraction=True, epoch=2000.0) (ra_appGeo, dec_appGeo) = PhoSimAstrometryBase.appGeoFromPhoSim(data['raPhoSim'], data['decPhoSim'], self.obs) (ra_obs_2, dec_obs_2) = observedFromAppGeo(ra_appGeo, dec_appGeo, obs_metadata=self.obs, includeRefraction=True) dd = 3600.0*angularSeparation(ra_obs, dec_obs, ra_obs_2, dec_obs_2) self.assertLess(dd.max(), 1.0e-5)
def test_stellar_observed_radians(self): """ Test ability to go all the way to observed RA, Dec from PhoSim (this is necessary for the ImSim software that DESC is working on) """ db = testStarsDBObj(driver='sqlite', database=self.db_name) cat = StarTestCatalog(db, obs_metadata=self.obs) with lsst.utils.tests.getTempFilePath('.txt') as cat_name: cat.write_catalog(cat_name) dtype = np.dtype([('raICRS', float), ('decICRS', float), ('raPhoSim', float), ('decPhoSim', float), ('raJ2000', float), ('decJ2000', float), ('pmRA', float), ('pmDec', float), ('parallax', float), ('vRad', float)]) data = np.genfromtxt(cat_name, dtype=dtype) self.assertGreater(len(data), 100) (ra_obs, dec_obs) = _observedFromICRS(data['raJ2000'], data['decJ2000'], obs_metadata=self.obs, pm_ra=data['pmRA'], pm_dec=data['pmDec'], parallax=data['parallax'], v_rad=data['vRad'], includeRefraction=True, epoch=2000.0) (ra_appGeo, dec_appGeo) = PhoSimAstrometryBase._appGeoFromPhoSim( np.radians(data['raPhoSim']), np.radians(data['decPhoSim']), self.obs) (ra_obs_2, dec_obs_2) = _observedFromAppGeo(ra_appGeo, dec_appGeo, obs_metadata=self.obs, includeRefraction=True) dd = arcsecFromRadians( _angularSeparation(ra_obs, dec_obs, ra_obs_2, dec_obs_2)) self.assertLess(dd.max(), 1.0e-5)
def test_stellar_astrometry_degrees(self): """ Test that we can go from raPhoSim, decPhoSim to ICRS coordinates in the case of stars (in degrees) """ db = testStarsDBObj(driver='sqlite', database=self.db_name) cat = StarTestCatalog(db, obs_metadata=self.obs) with lsst.utils.tests.getTempFilePath('.txt') as cat_name: cat.write_catalog(cat_name) dtype = np.dtype([('raICRS', float), ('decICRS', float), ('raPhoSim', float), ('decPhoSim', float), ('raJ2000', float), ('decJ2000', float), ('pmRA', float), ('pmDec', float), ('parallax', float), ('vRad', float)]) data = np.genfromtxt(cat_name, dtype=dtype) self.assertGreater(len(data), 100) # verify that, when transforming back to ICRS, we are within # 10^-3 arcsec ra_icrs, dec_icrs = PhoSimAstrometryBase.icrsFromPhoSim( data['raPhoSim'], data['decPhoSim'], self.obs) dist = angularSeparation(data['raICRS'], data['decICRS'], ra_icrs, dec_icrs) dist = 3600.0 * dist self.assertLess(dist.max(), 0.001) # verify that the distance between raPhoSim, decPhoSim and # raICRS, decICRS is greater than the distance between # the original raICRS, decICRS and the newly-calculated # raICRS, decICRS dist_bad = angularSeparation(data['raPhoSim'], data['decPhoSim'], data['raICRS'], data['decICRS']) dist_bad = 3600.0 * dist_bad self.assertGreater(dist_bad.min(), dist.max()) del db
def testStellarPhotometricUncertainties(self): """ Test in the case of a catalog of stars """ lsstDefaults = LSSTdefaults() starDB = testStarsDBObj(driver=self.driver, host=self.host, database=self.dbName) starCat = testStarCatalog(starDB, obs_metadata=self.obs_metadata) ct = 0 for line in starCat.iter_catalog(): starSed = Sed() starSed.readSED_flambda( os.path.join(getPackageDir('sims_sed_library'), defaultSpecMap[line[14]])) imsimband = Bandpass() imsimband.imsimBandpass() fNorm = starSed.calcFluxNorm(line[15], imsimband) starSed.multiplyFluxNorm(fNorm) aV = np.float(line[16]) a_int, b_int = starSed.setupCCMab() starSed.addCCMDust(a_int, b_int, A_v=aV) for i in range(len(self.bandpasses)): controlSigma = calcMagError_sed( starSed, self.totalBandpasses[i], self.skySeds[i], self.hardwareBandpasses[i], FWHMeff=lsstDefaults.FWHMeff(self.bandpasses[i]), photParams=PhotometricParameters()) testSigma = line[8 + i] self.assertAlmostEqual(controlSigma, testSigma, 4) ct += 1 self.assertGreater(ct, 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]
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)
def testPlacement(self): """ Test that GalSimInterpreter puts objects on the right detectors. Do so by creating a catalog of 10 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 numpy.random.seed(32) catSize = 10 dbName = 'galSimPlacementTestDB.db' driver = 'sqlite' if os.path.exists(dbName): os.unlink(dbName) displacedRA = (-40.0 + numpy.random.sample(catSize)*(120.0))/3600.0 displacedDec = (-20.0 + numpy.random.sample(catSize)*(80.0))/3600.0 obs_metadata = makePhoSimTestDB(filename=dbName, displacedRA=displacedRA, displacedDec=displacedDec, bandpass=self.bandpassNameList, m5=self.m5, seeing=self.seeing) catName = 'testPlacementCat.sav' 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): galSimType = line[0] xPupil = line[5] yPupil = line[6] majorAxis = line[8] minorAxis = line[9] sindex = line[10] halfLightRadius = line[11] positionAngle = line[12] if firstLine: sedList = cat._calculateGalSimSeds() for detector in cat.galSimInterpreter.detectors: for bandpass in cat.galSimInterpreter.bandpasses: controlImages['placementControl_' + \ cat.galSimInterpreter._getFileName(detector=detector, bandpassName=bandpass)] = \ cat.galSimInterpreter.blankImage(detector=detector) firstLine = False spectrum = galsim.SED(spec=lambda ll: numpy.interp(ll, sedList[i].wavelen, sedList[i].flambda), flux_type='flambda') for bp in cat.galSimInterpreter.bandpasses: bandpass = cat.galSimInterpreter.bandpasses[bp] for detector in cat.galSimInterpreter.detectors: centeredObj = cat.galSimInterpreter.PSF.applyPSF(xPupil=xPupil, yPupil=yPupil, bandpass=bandpass) xPix, yPix = pixelCoordsFromPupilCoords(numpy.array([radiansFromArcsec(xPupil)]), numpy.array([radiansFromArcsec(yPupil)]), chipNames = [detector.name], camera = detector.afwCamera) dx = xPix[0] - detector.xCenterPix dy = yPix[0] - detector.yCenterPix obj = centeredObj*spectrum localImage = cat.galSimInterpreter.blankImage(detector=detector) localImage = obj.drawImage(bandpass=bandpass, wcs=detector.wcs, method='phot', gain=detector.photParams.gain, image=localImage, offset=galsim.PositionD(dx, dy)) controlImages['placementControl_' + \ cat.galSimInterpreter._getFileName(detector=detector, bandpassName=bp)] += \ localImage 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.assertTrue(controlName in controlImages, msg=msg) #make sure that the test and control images agree to some tolerance ignored = 0 zeroFlux = 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() msg = '%s: controlFlux = %e, testFlux = %e' % (controlName, controlFlux, testFlux) if controlFlux>1000.0: #the randomness of photon shooting means that faint images won't agree self.assertTrue(numpy.abs(controlFlux/testFlux - 1.0)<0.1, msg=msg) 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.assertTrue(controlFlux<1.0, msg=msg) self.assertTrue(ignored<len(testNames)/2) self.assertTrue(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)
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)