Skip to content

Commit

Permalink
Add checks to ensure algMetdata is set correctly
Browse files Browse the repository at this point in the history
This commit modifies the existing KronPhotometryTestCase by making the
'measureFree' and 'measureForced' functions class methods that check
that the algorithm metadata object is populated correctly by the
measurement algorithm.
  • Loading branch information
AstroVPK committed Jul 25, 2016
1 parent 4933fe8 commit 8a08488
Showing 1 changed file with 44 additions and 28 deletions.
72 changes: 44 additions & 28 deletions tests/Kron.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import lsst.meas.base as measBase
# importing this package registers essential code
import lsst.meas.extensions.photometryKron
from lsst.daf.base import PropertyList

try:
type(verbose)
Expand Down Expand Up @@ -138,29 +139,6 @@ def makeMeasurementConfig(forced=False, nsigma=6.0, nIterForRadius=1, kfac=2.5):
msConfig.plugins["ext_photometryKron_KronFlux"].enforceMinimumRadius = False
return msConfig

def measureFree(exposure, center, msConfig):
"""Unforced measurement"""
schema = afwTable.SourceTable.makeMinimalSchema()
task = measBase.SingleFrameMeasurementTask(schema, config=msConfig)
measCat = afwTable.SourceCatalog(schema)
source = measCat.addNew()
ss = afwDetection.FootprintSet(exposure.getMaskedImage(), afwDetection.Threshold(0.1))
fp = ss.getFootprints()[0]
source.setFootprint(fp)
task.run(measCat, exposure)
return source

def measureForced(exposure, source, refWcs, msConfig):
"""Forced measurement"""
refCat = afwTable.SourceCatalog(source.table)
refCat.append(source)
schema = afwTable.SourceTable.makeMinimalSchema()
task = measBase.ForcedMeasurementTask(schema, config=msConfig)
measCat = task.generateMeasCat(exposure, refCat, refWcs)
task.attachTransformedFootprints(measCat, refCat, exposure, refWcs)
task.run(measCat, exposure, refCat, refWcs)
return measCat[0]

class KronPhotometryTestCase(tests.TestCase):
"""A test case for measuring Kron quantities"""

Expand All @@ -173,6 +151,44 @@ def tearDown(self):
if self.objImg:
del self.objImg

def checkAlgMeta(self, algMeta):
self.assertTrue(algMeta.exists('ext_photometryKron_KronFlux_fixed'))
self.assertTrue(algMeta.exists('ext_photometryKron_KronFlux_nSigmaForRadius'))
self.assertTrue(algMeta.exists('ext_photometryKron_KronFlux_nIterForRadius'))
self.assertTrue(algMeta.exists('ext_photometryKron_KronFlux_nRadiusForFlux'))
self.assertTrue(algMeta.exists('ext_photometryKron_KronFlux_maxSincRadius'))
self.assertTrue(algMeta.exists('ext_photometryKron_KronFlux_minimumRadius'))
self.assertTrue(algMeta.exists('ext_photometryKron_KronFlux_enforceMinimumRadius'))
self.assertTrue(algMeta.exists('ext_photometryKron_KronFlux_useFootprintRadius'))
self.assertTrue(algMeta.exists('ext_photometryKron_KronFlux_smoothingSigma'))

def measureFree(self, exposure, center, msConfig):
"""Unforced measurement"""
schema = afwTable.SourceTable.makeMinimalSchema()
algMeta = PropertyList()
task = measBase.SingleFrameMeasurementTask(schema, config=msConfig, algMetadata=algMeta)
measCat = afwTable.SourceCatalog(schema)
source = measCat.addNew()
ss = afwDetection.FootprintSet(exposure.getMaskedImage(), afwDetection.Threshold(0.1))
fp = ss.getFootprints()[0]
source.setFootprint(fp)
task.run(measCat, exposure)
self.checkAlgMeta(algMeta)
return source

def measureForced(self, exposure, source, refWcs, msConfig):
"""Forced measurement"""
refCat = afwTable.SourceCatalog(source.table)
refCat.append(source)
schema = afwTable.SourceTable.makeMinimalSchema()
algMeta = PropertyList()
task = measBase.ForcedMeasurementTask(schema, config=msConfig, algMetadata=algMeta)
measCat = task.generateMeasCat(exposure, refCat, refWcs)
task.attachTransformedFootprints(measCat, refCat, exposure, refWcs)
task.run(measCat, exposure, refCat, refWcs)
self.checkAlgMeta(algMeta)
return measCat[0]

def makeAndMeasure(self, measureKron, a, b, theta, dx=0.0, dy=0.0, nsigma=6, kfac=2, nIterForRadius=1,
xcen=None, ycen=None,
makeImage=True):
Expand Down Expand Up @@ -228,7 +244,7 @@ def measureKron(self, objImg, xcen, ycen, nsigma, kfac, nIterForRadius):
#
center = afwGeom.Point2D(xcen, ycen)
msConfig = makeMeasurementConfig(False, nsigma, nIterForRadius, kfac)
source = measureFree(objImg, center, msConfig)
source = self.measureFree(objImg, center, msConfig)

R_K = source.get("ext_photometryKron_KronFlux_radius")
flux_K = source.get("ext_photometryKron_KronFlux_flux")
Expand All @@ -237,7 +253,7 @@ def measureKron(self, objImg, xcen, ycen, nsigma, kfac, nIterForRadius):
if not flags_K:
# Forced measurement on the same image should produce exactly the same result
msConfig = makeMeasurementConfig(True, nsigma, nIterForRadius, kfac)
forced = measureForced(objImg, source, objImg.getWcs(), msConfig)
forced = self.measureForced(objImg, source, objImg.getWcs(), msConfig)
for field in (
"ext_photometryKron_KronFlux_flux",
"ext_photometryKron_KronFlux_fluxSigma",
Expand Down Expand Up @@ -284,7 +300,7 @@ def measureKronInPython(self, objImg, xcen, ycen, nsigma, kfac, nIterForRadius,
# Note: this code was converted to the new meas_framework, but is not exercised.
msConfig = makeMeasurementConfig(False, nsigma, nIterForRadius, kfac)
center = afwGeom.Point2D(xcen, ycen)
source = measureFree(objImg, center, msConfig)
source = self.measureFree(objImg, center, msConfig)

Mxx = source.getIxx()
Mxy = source.getIxy()
Expand Down Expand Up @@ -517,7 +533,7 @@ def testForced(self):
center = afwGeom.Point2D(0.5*width, 0.5*height)
original = makeGalaxy(width, height, 1000.0, a, b, theta)
msConfig = makeMeasurementConfig(forced=False, kfac=kfac)
source = measureFree(original, center, msConfig)
source = self.measureFree(original, center, msConfig)
if source.get("ext_photometryKron_KronFlux_flag"):
continue

Expand All @@ -539,7 +555,7 @@ def testForced(self):
if warped.getPsf() == None:
warped.setPsf(afwDetection.GaussianPsf(11, 11, 0.01))
msConfig = makeMeasurementConfig(kfac=kfac, forced=True)
forced = measureForced(warped, source, original.getWcs(), msConfig)
forced = self.measureForced(warped, source, original.getWcs(), msConfig)

if display:
ds9.mtv(original, frame=1)
Expand Down

0 comments on commit 8a08488

Please sign in to comment.