Coverage for tests/test_ApplyApCorr.py : 19%

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 Data Management System # Copyright 2008-2017 LSST Corporation. # # This product includes software developed by the # LSST Project (http://www.lsst.org/). # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the LSST License Statement and # the GNU General Public License along with this program. If not, # see <http://www.lsstcorp.org/LegalNotices/>. #
instFluxName = name + "_instFlux" instFluxErrName = name + "_instFluxErr" instFluxKey = schema.find(instFluxName).key centroidKey = afwTable.Point2DKey(schema["slot_Centroid"]) sourceCat = afwTable.SourceCatalog(schema) source = sourceCat.addNew() source.set(instFluxKey, instFlux) source.set(instFluxErrName, sigma) source.set(centroidKey, centroid) return(sourceCat)
schema = afwTable.SourceTable.makeMinimalSchema() name = "test" addApCorrName(name) schema.addField(name + "_instFlux", type=np.float64) schema.addField(name + "_instFluxErr", type=np.float64) schema.addField(name + "_flag", type=np.float64) schema.addField(name + "_Centroid_x", type=np.float64) schema.addField(name + "_Centroid_y", type=np.float64) schema.getAliasMap().set('slot_Centroid', name + '_Centroid') self.ap_corr_task = applyApCorr.ApplyApCorrTask(schema=schema) self.name = name self.schema = schema
del self.schema del self.ap_corr_task
# Check that the required fields have been added to the schema self.assertIn(self.name + "_apCorr", self.schema.getNames()) self.assertIn(self.name + "_apCorrErr", self.schema.getNames()) self.assertIn(self.name + "_flag_apCorr", self.schema.getNames())
# Check that the aperture correction flag is set to False if aperture correction was successfully run flagName = self.name + "_flag_apCorr" flagKey = self.schema.find(flagName).key source_test_instFlux = 5.1 source_test_centroid = lsst.geom.Point2D(5, 7.1) sourceCat = initializeSourceCatalog(schema=self.schema, name=self.name, instFlux=source_test_instFlux, sigma=0, centroid=source_test_centroid) instFluxName = self.name + "_instFlux" instFluxErrName = self.name + "_instFluxErr"
apCorrMap = afwImage.ApCorrMap() bbox = lsst.geom.Box2I(lsst.geom.Point2I(0, 0), lsst.geom.ExtentI(10, 10)) coefficients = np.ones((1, 1), dtype=np.float64) coefficients_sigma = np.zeros((1, 1), dtype=np.float64) apCorrMap[instFluxName] = ChebyshevBoundedField(bbox, coefficients) apCorrMap[instFluxErrName] = ChebyshevBoundedField(bbox, coefficients_sigma) self.ap_corr_task.run(sourceCat, apCorrMap) self.assertFalse(sourceCat[flagKey])
# Check that aperture correction flag is set to True if aperture correction is invalid (negative) flagName = self.name + "_flag_apCorr" flagKey = self.schema.find(flagName).key source_test_instFlux = 5.2 source_test_centroid = lsst.geom.Point2D(5, 7.1) sourceCat = initializeSourceCatalog(schema=self.schema, name=self.name, instFlux=source_test_instFlux, sigma=0, centroid=source_test_centroid) instFluxName = self.name + "_instFlux" instFluxErrName = self.name + "_instFluxErr"
apCorrMap = afwImage.ApCorrMap() bbox = lsst.geom.Box2I(lsst.geom.Point2I(0, 0), lsst.geom.ExtentI(10, 10)) coefficients = -(np.ones((1, 1), dtype=np.float64)) coefficients_sigma = np.zeros((1, 1), dtype=np.float64) apCorrMap[instFluxName] = ChebyshevBoundedField(bbox, coefficients) apCorrMap[instFluxErrName] = ChebyshevBoundedField(bbox, coefficients_sigma) self.ap_corr_task.run(sourceCat, apCorrMap) self.assertTrue(sourceCat[flagKey])
# Pick arbitrary but unique values for the test case source_test_instFlux = 5.3 source_test_centroid = lsst.geom.Point2D(5, 7.1) sourceCat = initializeSourceCatalog(schema=self.schema, name=self.name, instFlux=source_test_instFlux, sigma=0, centroid=source_test_centroid) instFluxName = self.name + "_instFlux" instFluxErrName = self.name + "_instFluxErr" instFluxKey = self.schema.find(instFluxName).key
apCorrMap = afwImage.ApCorrMap() bbox = lsst.geom.Box2I(lsst.geom.Point2I(0, 0), lsst.geom.ExtentI(10, 10)) coefficients = np.ones((1, 1), dtype=np.float64) coefficients_sigma = np.zeros((1, 1), dtype=np.float64) apCorrMap[instFluxName] = ChebyshevBoundedField(bbox, coefficients) apCorrMap[instFluxErrName] = ChebyshevBoundedField(bbox, coefficients_sigma) self.ap_corr_task.run(sourceCat, apCorrMap)
self.assertEqual(sourceCat[instFluxKey], source_test_instFlux)
# Pick arbitrary but unique values for the test case source_test_instFlux = 5.4 source_test_centroid = lsst.geom.Point2D(5, 7.1) sourceCat = initializeSourceCatalog(schema=self.schema, name=self.name, instFlux=source_test_instFlux, sigma=0, centroid=source_test_centroid) instFluxName = self.name + "_instFlux" instFluxErrName = self.name + "_instFluxErr" instFluxKey = self.schema.find(instFluxName).key
apCorrMap = afwImage.ApCorrMap() bbox = lsst.geom.Box2I(lsst.geom.Point2I(0, 0), lsst.geom.ExtentI(10, 10)) coefficients = np.ones((1, 1), dtype=np.float64) coefficients /= 2. coefficients_sigma = np.zeros((1, 1), dtype=np.float64) apCorrMap[instFluxName] = ChebyshevBoundedField(bbox, coefficients) apCorrMap[instFluxErrName] = ChebyshevBoundedField(bbox, coefficients_sigma) self.ap_corr_task.run(sourceCat, apCorrMap)
self.assertAlmostEqual(sourceCat[instFluxKey], source_test_instFlux / 2)
""" Important note! This test will break if UseNaiveFluxErr = False The alternate method significantly overestimates noise, causing this test to fail. It is likely that this test will need to be modified if the noise calculation is updated. """ # Pick arbitrary but unique values for the test case source_test_instFlux = 5.5 source_test_sigma = 0.23 source_test_centroid = lsst.geom.Point2D(5, 7.3) sourceCat = initializeSourceCatalog(schema=self.schema, name=self.name, instFlux=source_test_instFlux, sigma=source_test_sigma, centroid=source_test_centroid)
instFluxName = self.name + "_instFlux" instFluxErrName = self.name + "_instFluxErr" instFluxErrKey = self.schema.find(instFluxErrName).key
apCorrMap = afwImage.ApCorrMap() bbox = lsst.geom.Box2I(lsst.geom.Point2I(0, 0), lsst.geom.ExtentI(10, 10)) coefficients = np.ones((1, 1), dtype=np.float64) coefficients_sigma = np.ones((1, 1), dtype=np.float64) apCorrMap[instFluxName] = ChebyshevBoundedField(bbox, coefficients) apCorrMap[instFluxErrName] = ChebyshevBoundedField(bbox, coefficients_sigma) self.ap_corr_task.run(sourceCat, apCorrMap)
self.assertAlmostEqual(sourceCat[instFluxErrKey], source_test_sigma)
lsst.utils.tests.init()
lsst.utils.tests.init() unittest.main() |