Skip to content

Commit

Permalink
Add calib_astrometryUsed flag to AstrometryTask
Browse files Browse the repository at this point in the history
Previous merge was accidental.  The actual changes are here.
Includes a quick test which only shows that the task is able
to write to the schema and sources table.
  • Loading branch information
pgee2000 committed May 10, 2017
1 parent da512c7 commit ee69e0b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 9 deletions.
11 changes: 2 additions & 9 deletions python/lsst/meas/astrom/astrometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

from builtins import range

import random

import lsst.pex.config as pexConfig
import lsst.pipe.base as pipeBase
import lsst.afw.geom as afwGeom
Expand Down Expand Up @@ -61,11 +59,6 @@ class AstrometryConfig(RefMatchConfig):
default=0.001,
min=0,
)
doWriteOutput = pexConfig.Field(
dtype=bool,
default=True,
doc="Write used flag to the schema",
)

# The following block adds links to this task from the Task Documentation page.
## \addtogroup LSST_task_documentation
Expand Down Expand Up @@ -159,9 +152,9 @@ def __init__(self, refObjLoader, schema=None, **kwargs):
"""
RefMatchTask.__init__(self, refObjLoader, schema=schema, **kwargs)

if self.config.doWriteOutput and not schema is None:
if schema is not None:
self.usedKey = schema.addField("calib_astrometryUsed", type="Flag",
doc="set if source was used in astrometric calibration")
doc="set if source was used in astrometric calibration")
else:
self.usedKey = None

Expand Down
40 changes: 40 additions & 0 deletions tests/testAstrometryTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,46 @@ def testRadial(self):
"""
self.doTest(afwGeom.RadialXYTransform([0, 1.01, 1e-7]))

def testUsedFlag(self):
"""Test that the solver will record number of sources used to table
if it is passed a schema on initialization.
"""
distortedWcs = afwImage.DistortedTanWcs(self.tanWcs, afwGeom.IdentityXYTransform())
self.exposure.setWcs(distortedWcs)
loadRes = self.refObjLoader.loadPixelBox(bbox=self.bbox, wcs=distortedWcs, filterName="r")
refCat = loadRes.refCat
refCentroidKey = afwTable.Point2DKey(refCat.schema["centroid"])
refFluxRKey = refCat.schema["r_flux"].asKey()

sourceSchema = afwTable.SourceTable.makeMinimalSchema()
measBase.SingleFrameMeasurementTask(schema=sourceSchema) # expand the schema
config = AstrometryTask.ConfigClass()
config.wcsFitter.order = 2
config.wcsFitter.numRejIter = 0
# schema must be passed to the solver task constructor
solver = AstrometryTask(config=config, refObjLoader=self.refObjLoader, schema=sourceSchema)
sourceCat = afwTable.SourceCatalog(sourceSchema)
sourceCentroidKey = afwTable.Point2DKey(sourceSchema["slot_Centroid"])
sourceFluxKey = sourceSchema["slot_ApFlux_flux"].asKey()
sourceFluxSigmaKey = sourceSchema["slot_ApFlux_fluxSigma"].asKey()

for refObj in refCat:
src = sourceCat.addNew()
src.set(sourceCentroidKey, refObj.get(refCentroidKey))
src.set(sourceFluxKey, refObj.get(refFluxRKey))
src.set(sourceFluxSigmaKey, refObj.get(refFluxRKey)/100)

results = solver.run(
sourceCat=sourceCat,
exposure=self.exposure,
)
# check that the used flag is set the right number of times
count = 0
for source in sourceCat:
if source.get('calib_astrometryUsed'):
count += 1
self.assertEqual(count, len(results.matches))

def doTest(self, pixelsToTanPixels, order=3):
"""Test using pixelsToTanPixels to distort the source positions
"""
Expand Down

0 comments on commit ee69e0b

Please sign in to comment.