Coverage for python/lsst/faro/base/CatalogMeasurementBase.py: 48%
Shortcuts 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
Shortcuts 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
1# This file is part of faro.
2#
3# Developed for the LSST Data Management System.
4# This product includes software developed by the LSST Project
5# (https://www.lsst.org).
6# See the COPYRIGHT file at the top-level directory of this distribution
7# for details of code ownership.
8#
9# This program is free software: you can redistribute it and/or modify
10# it under the terms of the GNU General Public License as published by
11# the Free Software Foundation, either version 3 of the License, or
12# (at your option) any later version.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <https://www.gnu.org/licenses/>.
22import lsst.pipe.base as pipeBase
23import lsst.pex.config as pexConfig
24from lsst.verify.tasks import MetricTask, MetricConfig, MetricConnections
25from lsst.pipe.tasks.loadReferenceCatalog import LoadReferenceCatalogTask
26import lsst.geom
28from .BaseSubTasks import NumSourcesTask
30__all__ = (
31 "CatalogMeasurementBaseConnections",
32 "CatalogMeasurementBaseConfig",
33 "CatalogMeasurementBaseTask",
34)
37class CatalogMeasurementBaseConnections(
38 MetricConnections, defaultTemplates={"refDataset": ""}
39):
41 refCat = pipeBase.connectionTypes.PrerequisiteInput(
42 doc="Reference catalog",
43 name="{refDataset}",
44 storageClass="SimpleCatalog",
45 dimensions=("skypix",),
46 deferLoad=True,
47 multiple=True,
48 )
50 def __init__(self, *, config=None):
51 super().__init__(config=config)
52 if config.connections.refDataset == "":
53 self.prerequisiteInputs.remove("refCat")
56class CatalogMeasurementBaseConfig(
57 MetricConfig, pipelineConnections=CatalogMeasurementBaseConnections
58):
59 """Configuration for CatalogMeasurementBaseTask."""
61 measure = pexConfig.ConfigurableField(
62 # This task is meant to make measurements of various types.
63 # The default task is, therefore, a bit of a place holder.
64 # It is expected that this will be overridden in the pipeline
65 # definition in most cases.
66 target=NumSourcesTask,
67 doc="Measure task",
68 )
70 referenceCatalogLoader = pexConfig.ConfigurableField(
71 target=LoadReferenceCatalogTask, doc="Reference catalog loader",
72 )
74 def setDefaults(self):
75 self.referenceCatalogLoader.refObjLoader.ref_dataset_name = ""
76 self.referenceCatalogLoader.doApplyColorTerms = False
78 def validate(self):
79 super().validate()
80 if (
81 self.connections.refDataset
82 != self.referenceCatalogLoader.refObjLoader.ref_dataset_name
83 ):
84 msg = "The reference datasets specified in connections and reference catalog loader must match."
85 raise pexConfig.FieldValidationError(
86 CatalogMeasurementBaseConfig.referenceCatalogLoader, self, msg
87 )
90class CatalogMeasurementBaseTask(MetricTask):
91 """Base class for science performance metrics measured from source/object catalogs."""
93 ConfigClass = CatalogMeasurementBaseConfig
94 _DefaultName = "catalogMeasurementBaseTask"
96 def __init__(self, config, *args, **kwargs):
97 super().__init__(*args, config=config, **kwargs)
98 self.makeSubtask("measure")
100 def run(self, **kwargs):
101 return self.measure.run(self.config.connections.metric, **kwargs)
103 def _getReferenceCatalog(self, butlerQC, dataIds, refCats, filterList, epoch=None):
104 """Load reference catalog in sky region of interest.
106 Parameters
107 ----------
108 butlerQC : `lsst.pipe.base.butlerQuantumContext.ButlerQuantumContext`
109 Butler quantum context for a Gen3 repository.
110 dataIds: interable of `lsst.daf.butler.dataId`
111 An iterable object of dataIds that point to reference catalogs
112 in a Gen3 repository.
113 refCats : iterable of `lsst.daf.butler.DeferredDatasetHandle`
114 An iterable object of dataset refs for reference catalogs in
115 a Gen3 repository.
116 filterList : `list` [`str`]
117 List of camera physicalFilter names to apply color terms.
118 epoch : `astropy.time.Time`, optional
119 Epoch to which to correct proper motion and parallax
120 (if available), or `None` to not apply such corrections.
122 Returns
123 -------
124 refCat : `lsst.afw.table.SimpleCatalog`
125 Catalog of reference objects from region.
126 refCatCorrected : `numpy.ndarray`
127 Catalog of reference objects with proper motions and color terms
128 (optionally) applied.
129 """
130 center = lsst.geom.SpherePoint(
131 butlerQC.quantum.dataId.region.getBoundingCircle().getCenter()
132 )
133 radius = butlerQC.quantum.dataId.region.getBoundingCircle().getOpeningAngle()
135 loaderTask = LoadReferenceCatalogTask(
136 config=self.config.referenceCatalogLoader, dataIds=dataIds, refCats=refCats
137 )
139 # Get catalog with proper motion and color terms applied
140 refCatCorrected = loaderTask.getSkyCircleCatalog(
141 center, radius, filterList, epoch=epoch
142 )
144 # Get unformatted catalog w/ all columns
145 skyCircle = loaderTask.refObjLoader.loadSkyCircle(
146 center, radius, loaderTask._referenceFilter, epoch=epoch
147 )
148 refCat = skyCircle.refCat
150 return refCat, refCatCorrected