Coverage for tests/test_measureApCorr.py : 21%

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-2016 AURA/LSST. # # 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 <https://www.lsstcorp.org/LegalNotices/>. #
default_coefficients = np.ones((1, 1), dtype=float) default_coefficients /= value default_apCorrMap = ChebyshevBoundedField(bbox, default_coefficients) default_fill = afwImage.ImageF(bbox) default_apCorrMap.fillImage(default_fill) return(default_fill)
sourceCat = afwTable.SourceCatalog(self.schema) fluxName = self.name + "_instFlux" flagName = self.name + "_flag" fluxErrName = self.name + "_instFluxErr" apFluxName = self.apname + "_instFlux" apFlagName = self.apname + "_flag" apFluxErrName = self.apname + "_instFluxErr" fluxKey = self.schema.find(fluxName).key flagKey = self.schema.find(flagName).key fluxErrKey = self.schema.find(fluxErrName).key apFluxKey = self.schema.find(apFluxName).key apFlagKey = self.schema.find(apFlagName).key apFluxErrKey = self.schema.find(apFluxErrName).key centroidKey = afwTable.Point2DKey(self.schema["slot_Centroid"]) inputFilterFlagKey = self.schema.find(self.meas_apCorr_task.config.sourceSelector.active.field).key x = np.random.rand(numSources)*self.exposure.getWidth() + self.exposure.getX0() y = np.random.rand(numSources)*self.exposure.getHeight() + self.exposure.getY0() for _i in range(numSources): source_test_instFlux = 5.1 source_test_centroid = lsst.geom.Point2D(x[_i], y[_i]) source = sourceCat.addNew() source.set(fluxKey, source_test_instFlux) source.set(apFluxKey, source_test_instFlux * apCorrScale) source.set(centroidKey, source_test_centroid) source.set(fluxErrKey, 0.) source.set(apFluxErrKey, 0.) source.set(flagKey, False) source.set(apFlagKey, False) source.set(inputFilterFlagKey, True) return(sourceCat)
schema = afwTable.SourceTable.makeMinimalSchema() name = "test" apname = "testAp" calib_flag_name = "cal_source_use" addApCorrName(apname) schema.addField(name + "_instFlux", type=float) schema.addField(name + "_instFluxErr", type=float) schema.addField(name + "_flag", type="Flag") schema.addField(apname + "_instFlux", type=float) schema.addField(apname + "_instFluxErr", type=float) schema.addField(apname + "_flag", type="Flag") schema.addField(calib_flag_name, type="Flag") schema.addField(name + "_Centroid_x", type=float) schema.addField(name + "_Centroid_y", type=float) schema.getAliasMap().set('slot_Centroid', name + '_Centroid') config = measureApCorr.MeasureApCorrTask.ConfigClass() config.refFluxName = name config.sourceSelector.active.field = calib_flag_name self.meas_apCorr_task = measureApCorr.MeasureApCorrTask(schema=schema, config=config) self.name = name self.apname = apname self.schema = schema self.exposure = lsst.afw.image.ExposureF(10, 10)
del self.schema del self.meas_apCorr_task del self.exposure
"""Instantiating the task should add one field to the schema.""" self.assertIn("apcorr_" + self.name + "_used", self.schema.getNames())
"""The measureApCorr task should return a structure with a single key 'apCorrMap'.""" struct = self.meas_apCorr_task.run(catalog=self.makeCatalog(), exposure=self.exposure) self.assertEqual(list(struct.getDict().keys()), ['apCorrMap'])
"""An apCorrMap structure should have two keys, based on the name supplied to addApCorrName().""" apfluxName = self.apname + "_instFlux" apfluxErrName = self.apname + "_instFluxErr" struct = self.meas_apCorr_task.run(catalog=self.makeCatalog(), exposure=self.exposure) key_names = [apfluxName, apfluxErrName] self.assertEqual(set(struct.apCorrMap.keys()), set(key_names))
""" If there are too few sources, check that an exception is raised.""" catalog = afwTable.SourceCatalog(self.schema) with self.assertRaises(RuntimeError): self.meas_apCorr_task.run(catalog=catalog, exposure=self.exposure) # With the measurement algorithm declared as something that might fail, should not get an exception self.meas_apCorr_task.config.allowFailure.append(self.apname) self.meas_apCorr_task.run(catalog=catalog, exposure=self.exposure)
""" Check that a source outside the bounding box is flagged as not used (False).""" fluxName = self.name + "_instFlux" apCorrFlagKey = self.schema.find("apcorr_" + self.name + "_used").key sourceCat = self.makeCatalog() source = sourceCat.addNew() source_test_instFlux = 5.1 source_test_centroid = lsst.geom.Point2D(15, 7.1) fluxKey = self.schema.find(fluxName).key centroidKey = afwTable.Point2DKey(self.schema["slot_Centroid"]) source.set(fluxKey, source_test_instFlux) source.set(centroidKey, source_test_centroid) self.meas_apCorr_task.run(catalog=sourceCat, exposure=self.exposure) self.assertFalse(sourceCat[apCorrFlagKey][-1])
"""Check that valid sources inside the bounding box that are used have their flags set to True.""" inputFilterFlagKey = self.schema.find(self.meas_apCorr_task.config.sourceSelector.active.field).key sourceCat = self.makeCatalog() self.meas_apCorr_task.run(catalog=sourceCat, exposure=self.exposure) self.assertTrue(sourceCat[inputFilterFlagKey].all())
""" Check that sources with aperture fluxes exactly the same as their catalog fluxes returns an aperture correction map of 1s""" apFluxName = self.apname + "_instFlux" sourceCat = self.makeCatalog() struct = self.meas_apCorr_task.run(catalog=sourceCat, exposure=self.exposure) default_fill = apCorrDefaultMap(value=1.0, bbox=self.exposure.getBBox()) test_fill = afwImage.ImageF(self.exposure.getBBox()) struct.apCorrMap[apFluxName].fillImage(test_fill) np.testing.assert_allclose(test_fill.getArray(), default_fill.getArray())
"""Check that aperture correction scales source fluxes in the correct direction.""" apCorr_factor = 10. sourceCat = self.makeCatalog(apCorrScale=apCorr_factor) apFluxName = self.apname + "_instFlux" struct = self.meas_apCorr_task.run(catalog=sourceCat, exposure=self.exposure) default_fill = apCorrDefaultMap(value=apCorr_factor, bbox=self.exposure.getBBox()) test_fill = afwImage.ImageF(self.exposure.getBBox()) struct.apCorrMap[apFluxName].fillImage(test_fill) np.testing.assert_allclose(test_fill.getArray(), default_fill.getArray())
lsst.utils.tests.init()
lsst.utils.tests.init() unittest.main() |