2 __all__ = [
"DirectMatchConfig",
"DirectMatchTask",
"DirectMatchConfigWithoutLoader"]
5 from lsst.pipe.base
import Task, Struct
6 from lsst.meas.algorithms
import (LoadIndexedReferenceObjectsTask, ScienceSourceSelectorTask,
7 ReferenceSourceSelectorTask)
13 """Configuration for DirectMatchTask when an already-initialized 14 refObjLoader will be passed to this task.""" 15 matchRadius = Field(dtype=float, default=0.25, doc=
"Matching radius, arcsec")
16 sourceSelection = ConfigurableField(target=ScienceSourceSelectorTask,
17 doc=
"Selection of science sources")
18 referenceSelection = ConfigurableField(target=ReferenceSourceSelectorTask,
19 doc=
"Selection of reference sources")
23 """Configuration for DirectMatchTask""" 24 refObjLoader = ConfigurableField(target=LoadIndexedReferenceObjectsTask, doc=
"Load reference objects")
28 """Simple, brute force matching of a source catalog to a reference catalog. 32 butler : `lsst.daf.persistence.Butler` 33 Data butler containing the relevant reference catalog data. 34 refObjLoader : `lsst.meas.algorithms.LoadReferenceObjectsTask` or `None` 35 For loading reference objects 37 Other keyword arguments required for instantiating a Task (e.g., 'config') 39 ConfigClass = DirectMatchConfig
40 _DefaultName =
"directMatch" 42 def __init__(self, butler=None, refObjLoader=None, **kwargs):
43 Task.__init__(self, **kwargs)
46 if not isinstance(self.config, DirectMatchConfig):
47 raise RuntimeError(
"DirectMatchTask must be initialized with DirectMatchConfig " 48 "if a refObjLoader is not supplied at initialization")
49 self.makeSubtask(
"refObjLoader", butler=butler)
55 self.makeSubtask(
"sourceSelection")
56 self.makeSubtask(
"referenceSelection")
59 """Sets the reference object loader for the task 63 refObjLoader : `lsst.meas.algorithms.LoadReferenceObjectsTask` or 64 `lsst.meas.algorithms.ReferenceObjectLoader` 65 An instance of a reference object loader task or class. A task can be used as a subtask 66 and is generally used in gen2 middleware. The class is designed to be used with gen3 67 middleware and is initialized outside the normal task framework. 71 def run(self, catalog, filterName=None, epoch=None):
72 """Load reference objects and match to them. 76 catalog : `lsst.afw.table.SourceCatalog` 79 Name of filter loading fluxes 80 epoch : `astropy.time.Time` or `None` 81 Epoch to which to correct proper motion and parallax, 82 or `None` to not apply such corrections. 86 result : `lsst.pipe.base.Struct` 87 Result struct with components: 89 - matches : Matched sources with associated reference 90 (`lsst.afw.table.SourceMatchVector`) 91 - matchMeta : Match metadata (`lsst.meas.astrom.MatchMetadata`) 94 raise RuntimeError(
"Running matcher task with no refObjLoader set in __ini__ or setRefObjLoader")
96 matchMeta = self.
refObjLoader.getMetadataCircle(circle.center, circle.radius, filterName, epoch=epoch)
97 emptyResult = Struct(matches=[], matchMeta=matchMeta)
98 sourceSelection = self.sourceSelection.
run(catalog)
99 if len(sourceSelection.sourceCat) == 0:
100 self.log.warn(
"No objects selected from %d objects in source catalog", len(catalog))
102 refData = self.
refObjLoader.loadSkyCircle(circle.center, circle.radius, filterName, epoch=epoch)
103 refCat = refData.refCat
104 refSelection = self.referenceSelection.
run(refCat)
105 if len(refSelection.sourceCat) == 0:
106 self.log.warn(
"No objects selected from %d objects in reference catalog", len(refCat))
109 self.config.matchRadius*arcseconds)
110 self.log.info(
"Matched %d from %d/%d input and %d/%d reference sources" %
111 (len(matches), len(sourceSelection.sourceCat), len(catalog),
112 len(refSelection.sourceCat), len(refCat)))
113 return Struct(matches=matches, matchMeta=matchMeta, refCat=refCat, sourceSelection=sourceSelection,
114 refSelection=refSelection)
117 """Calculate a circle enclosing the catalog 121 catalog : `lsst.afw.table.SourceCatalog` 126 result : `lsst.pipe.base.Struct` 127 Result struct with components: 129 - center : ICRS center coordinate (`lsst.afw.geom.SpherePoint`) 130 - radius : Radius of the circle (`lsst.geom.Angle`) 132 coordList = [src.getCoord()
for src
in catalog]
133 center = averageSpherePoint(coordList)
134 radius = max(center.separation(coord)
for coord
in coordList)
135 return Struct(center=center, radius=radius + self.config.matchRadius*arcseconds)
def setRefObjLoader(self, refObjLoader)
def run(self, catalog, filterName=None, epoch=None)
template SourceMatchVector matchRaDec(SourceCatalog const &, lsst::geom::Angle, MatchControl const &)
def calculateCircle(self, catalog)
def __init__(self, butler=None, refObjLoader=None, kwargs)