Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DM-12207: Add color selection for photocal #76

Merged
merged 1 commit into from
Nov 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 25 additions & 5 deletions python/lsst/meas/astrom/directMatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

from lsst.pex.config import Config, Field, ConfigurableField
from lsst.pipe.base import Task, Struct
from lsst.meas.algorithms import LoadIndexedReferenceObjectsTask
from lsst.meas.algorithms import (LoadIndexedReferenceObjectsTask, ScienceSourceSelectorTask,
ReferenceSourceSelectorTask)
import lsst.afw.table as afwTable
import lsst.afw.coord as afwCoord
from lsst.afw.geom import arcseconds
Expand All @@ -14,6 +15,10 @@ class DirectMatchConfig(Config):
"""Configuration for DirectMatchTask"""
refObjLoader = ConfigurableField(target=LoadIndexedReferenceObjectsTask, doc="Load reference objects")
matchRadius = Field(dtype=float, default=0.25, doc="Matching radius, arcsec")
sourceSelection = ConfigurableField(target=ScienceSourceSelectorTask,
doc="Selection of science sources")
referenceSelection = ConfigurableField(target=ReferenceSourceSelectorTask,
doc="Selection of reference sources")


class DirectMatchTask(Task):
Expand Down Expand Up @@ -77,6 +82,8 @@ def __init__(self, butler=None, refObjLoader=None, **kwargs):
self.makeSubtask("refObjLoader", butler=butler)
else:
self.refObjLoader = refObjLoader
self.makeSubtask("sourceSelection")
self.makeSubtask("referenceSelection")

def run(self, catalog, filterName=None):
"""!Load reference objects and match to them
Expand All @@ -88,11 +95,24 @@ def run(self, catalog, filterName=None):
"""
circle = self.calculateCircle(catalog)
matchMeta = self.refObjLoader.getMetadataCircle(circle.center, circle.radius, filterName)
emptyResult = Struct(matches=[], matchMeta=matchMeta)
sourceSelection = self.sourceSelection.selectSources(catalog)
if len(sourceSelection.sourceCat) == 0:
self.log.warn("No objects selected from %d objects in source catalog", len(catalog))
return emptyResult
refData = self.refObjLoader.loadSkyCircle(circle.center, circle.radius, filterName)
matches = afwTable.matchRaDec(refData.refCat, catalog, self.config.matchRadius*arcseconds)
self.log.info("Matched %d from %d input and %d reference sources" %
(len(matches), len(catalog), len(refData.refCat)))
return Struct(matches=matches, matchMeta=matchMeta)
refCat = refData.refCat
refSelection = self.referenceSelection.selectSources(refCat)
if len(refSelection.sourceCat) == 0:
self.log.warn("No objects selected from %d objects in reference catalog", len(refCat))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why run matches after this, if there are no ref sources? Shouldn't you also short-circuit an empty return?

return emptyResult
matches = afwTable.matchRaDec(refSelection.sourceCat, sourceSelection.sourceCat,
self.config.matchRadius*arcseconds)
self.log.info("Matched %d from %d/%d input and %d/%d reference sources" %
(len(matches), len(sourceSelection.sourceCat), len(catalog),
len(refSelection.sourceCat), len(refCat)))
return Struct(matches=matches, matchMeta=matchMeta, refCat=refCat, sourceSelection=sourceSelection,
refSelection=refSelection)

def calculateCircle(self, catalog):
"""!Calculate a circle enclosing the catalog
Expand Down
22 changes: 18 additions & 4 deletions python/lsst/meas/astrom/ref_match.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import lsst.afw.math as afwMath
import lsst.pex.config as pexConfig
import lsst.pipe.base as pipeBase
from lsst.meas.algorithms import ScienceSourceSelectorTask, ReferenceSourceSelectorTask
from .matchOptimisticB import MatchOptimisticBTask
from .display import displayAstrometry
from . import makeMatchStatistics
Expand All @@ -46,6 +47,10 @@ class RefMatchConfig(pexConfig.Config):
default=2,
min=0,
)
sourceSelection = pexConfig.ConfigurableField(target=ScienceSourceSelectorTask,
doc="Selection of science sources")
referenceSelection = pexConfig.ConfigurableField(target=ReferenceSourceSelectorTask,
doc="Selection of reference sources")

# The following block adds links to this task from the Task Documentation page.
## \addtogroup LSST_task_documentation
Expand Down Expand Up @@ -74,6 +79,8 @@ def __init__(self, refObjLoader, schema=None, **kwargs):
pipeBase.Task.__init__(self, **kwargs)
self.refObjLoader = refObjLoader
self.makeSubtask("matcher")
self.makeSubtask("sourceSelection")
self.makeSubtask("referenceSelection")

@pipeBase.timeMethod
def loadAndMatch(self, exposure, sourceCat):
Expand All @@ -95,12 +102,17 @@ def loadAndMatch(self, exposure, sourceCat):

expMd = self._getExposureMetadata(exposure)

sourceSelection = self.sourceSelection.selectSources(sourceCat)

loadRes = self.refObjLoader.loadPixelBox(
bbox=expMd.bbox,
wcs=expMd.wcs,
filterName=expMd.filterName,
calib=expMd.calib,
)

refSelection = self.referenceSelection.selectSources(loadRes.refCat)

matchMeta = self.refObjLoader.getMetadataBox(
bbox=expMd.bbox,
wcs=expMd.wcs,
Expand All @@ -109,8 +121,8 @@ def loadAndMatch(self, exposure, sourceCat):
)

matchRes = self.matcher.matchObjectsToSources(
refCat=loadRes.refCat,
sourceCat=sourceCat,
refCat=refSelection.sourceCat,
sourceCat=sourceSelection.sourceCat,
wcs=expMd.wcs,
refFluxField=loadRes.fluxField,
match_tolerance=None,
Expand All @@ -125,8 +137,8 @@ def loadAndMatch(self, exposure, sourceCat):
if debug.display:
frame = int(debug.frame)
displayAstrometry(
refCat=loadRes.refCat,
sourceCat=sourceCat,
refCat=refSelection.sourceCat,
sourceCat=sourceSelection.sourceCat,
matches=matchRes.matches,
exposure=exposure,
bbox=expMd.bbox,
Expand All @@ -136,6 +148,8 @@ def loadAndMatch(self, exposure, sourceCat):

return pipeBase.Struct(
refCat=loadRes.refCat,
refSelection=refSelection,
sourceSelection=sourceSelection,
matches=matchRes.matches,
matchMeta=matchMeta,
)
Expand Down
1 change: 1 addition & 0 deletions tests/test_astrometryTask.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ def makeSourceCat(self, distortedWcs):
sourceFluxKey = sourceSchema["slot_ApFlux_flux"].asKey()
sourceFluxSigmaKey = sourceSchema["slot_ApFlux_fluxSigma"].asKey()

sourceCat.reserve(len(refCat))
for refObj in refCat:
src = sourceCat.addNew()
src.set(sourceCentroidKey, refObj.get(refCentroidKey))
Expand Down