Coverage for python/lsst/faro/measurement/MatchedCatalogTableMeasurement.py: 28%
64 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-03-19 02:30 -0700
« prev ^ index » next coverage.py v7.4.4, created at 2024-03-19 02:30 -0700
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/>.
23import lsst.pipe.base as pipeBase
24import lsst.pex.config as pexConfig
26from lsst.faro.base.CatalogMeasurementBase import (
27 CatalogMeasurementBaseConnections,
28 CatalogMeasurementBaseConfig,
29 CatalogMeasurementBaseTask,
30)
31from lsst.faro.utils.filter_map import FilterMap
33__all__ = (
34 "TractMatchedCatalogTableMeasurementConnections",
35 "TractMatchedCatalogTableMeasurementConfig",
36 "TractMatchedCatalogTableMeasurementTask",
37 "TractMatchedCatalogMultiBandTableMeasurementConnections",
38 "TractMatchedCatalogMultiBandTableMeasurementConfig",
39 "TractMatchedCatalogMultiBandTableMeasurementTask",
40)
43class TractMatchedCatalogTableMeasurementConnections(
44 CatalogMeasurementBaseConnections,
45 dimensions=("tract", "skymap", "band"),
46 defaultTemplates={"individualSourceCatalogName": "isolated_star_sources"}
47):
49 individualSourceCatalog = pipeBase.connectionTypes.Input(
50 doc='Catalog of individual sources for the isolated stars',
51 name="{individualSourceCatalogName}",
52 storageClass='DataFrame',
53 dimensions=('instrument', 'tract', 'skymap'),
54 deferLoad=True,
55 )
57 measurement = pipeBase.connectionTypes.Output(
58 doc="Per-tract measurement.",
59 dimensions=("tract", "skymap", "band"),
60 storageClass="MetricValue",
61 name="metricvalue_{package}_{metric}",
62 )
65class TractMatchedCatalogTableMeasurementConfig(
66 CatalogMeasurementBaseConfig, pipelineConnections=TractMatchedCatalogTableMeasurementConnections
67):
68 """Configuration for TractMatchedCatalogTableMeasurementTask."""
70 instrument = pexConfig.Field(
71 doc="Instrument.",
72 dtype=str,
73 default='hsc',
74 )
77class TractMatchedCatalogTableMeasurementTask(CatalogMeasurementBaseTask):
78 """Base class for per-band science performance metrics measured on single-tract matched catalogs."""
80 ConfigClass = TractMatchedCatalogTableMeasurementConfig
81 _DefaultName = "tractMatchedCatalogTableMeasurementTask"
83 def runQuantum(self, butlerQC, inputRefs, outputRefs):
84 inputs = butlerQC.get(inputRefs)
85 kwargs = {"currentBands": butlerQC.quantum.dataId['band']}
87 columns = list(self.config.measure.columns.values())
88 for column in self.config.measure.columnsBand.values():
89 columns.append(kwargs["currentBands"] + '_' + column)
90 columnsWithSelectors = self._getTableColumnsSelectors(columns, kwargs["currentBands"])
91 catalog = inputs["individualSourceCatalog"].get(parameters={"columns": columnsWithSelectors})
92 sel = (catalog[self.config.measure._getColumnName("band")] == kwargs["currentBands"])
93 kwargs["catalog"] = catalog.loc[sel, :]
95 if self.config.connections.refDataset != "":
96 refCats = inputs.pop("refCat")
97 filter_map = FilterMap()
98 filterList = filter_map.getFilters(self.config.instrument,
99 [kwargs["currentBands"]])
101 # TODO: add capability to select the reference epoch
102 epoch = None
103 refCatFrame = self._getReferenceCatalog(
104 butlerQC,
105 [ref.datasetRef.dataId for ref in inputRefs.refCat],
106 refCats,
107 filterList,
108 epoch,
109 )
110 kwargs["refCatFrame"] = refCatFrame
112 outputs = self.run(**kwargs)
113 if outputs.measurement is not None:
114 butlerQC.put(outputs, outputRefs)
115 else:
116 self.log.debug(
117 "Skipping measurement of %r on %s as not applicable.",
118 self,
119 inputRefs,
120 )
123class TractMatchedCatalogMultiBandTableMeasurementConnections(
124 TractMatchedCatalogTableMeasurementConnections,
125 dimensions=("tract", "skymap"),
126 defaultTemplates={"individualSourceCatalogName": "isolated_star_sources"}
127):
129 individualSourceCatalog = pipeBase.connectionTypes.Input(
130 doc='Catalog of individual sources for the isolated stars',
131 name="{individualSourceCatalogName}",
132 storageClass='DataFrame',
133 dimensions=('instrument', 'tract', 'skymap'),
134 deferLoad=True,
135 )
137 measurement = pipeBase.connectionTypes.Output(
138 doc="Per-tract measurement.",
139 dimensions=("tract", "skymap"),
140 storageClass="MetricValue",
141 name="metricvalue_{package}_{metric}",
142 )
145class TractMatchedCatalogMultiBandTableMeasurementConfig(
146 TractMatchedCatalogTableMeasurementConfig,
147 pipelineConnections=TractMatchedCatalogMultiBandTableMeasurementConnections,
148):
149 """Configuration for TractMatchedCatalogMultiBandTableMeasurementTask."""
151 bands = pexConfig.ListField(
152 doc="Bands for band-specific column loading from objectTable_tract.",
153 dtype=str,
154 default=["g", "r", "i", "z", "y"],
155 )
158class TractMatchedCatalogMultiBandTableMeasurementTask(TractMatchedCatalogTableMeasurementTask):
160 """Base class for science performance metrics measured on single-tract object catalogs, multi-band."""
162 ConfigClass = TractMatchedCatalogMultiBandTableMeasurementConfig
163 _DefaultName = "tractMatchedCatalogMultiBandTableMeasurementTask"
165 def runQuantum(self, butlerQC, inputRefs, outputRefs):
166 inputs = butlerQC.get(inputRefs)
168 kwargs = {"currentBands": self.config.bands.list()}
170 columns = list(self.config.measure.columns.values())
171 for band in self.config.bands:
172 for column in self.config.measure.columnsBand.values():
173 columns.append(band + "_" + column)
174 columnsWithSelectors = self._getTableColumnsSelectors(columns, kwargs["currentBands"])
175 catalog = inputs["individualSourceCatalog"].get(parameters={"columns": columnsWithSelectors})
176 sel = catalog[self.config.measure._getColumnName("band")].isin(kwargs["currentBands"])
177 kwargs["catalog"] = catalog.loc[sel, :]
179 if self.config.connections.refDataset != "":
180 refCats = inputs.pop("refCat")
181 filter_map = FilterMap()
182 filterList = filter_map.getFilters(self.config.instrument,
183 self.config.bands)
185 # TODO: add capability to select the reference epoch
186 epoch = None
187 refCat = self._getReferenceCatalog(
188 butlerQC,
189 [ref.datasetRef.dataId for ref in inputRefs.refCat],
190 refCats,
191 filterList,
192 epoch,
193 )
194 kwargs["refCat"] = refCat
196 outputs = self.run(**kwargs)
197 if outputs.measurement is not None:
198 butlerQC.put(outputs, outputRefs)
199 else:
200 self.log.debug(
201 "Skipping measurement of %r on %s as not applicable.",
202 self,
203 inputRefs,
204 )