Coverage for python/lsst/faro/measurement/TractTableMeasurement.py : 31%

Hot-keys 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/>.
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 "TractTableMeasurementConnections",
35 "TractTableMeasurementConfig",
36 "TractTableMeasurementTask",
37 "TractMultiBandTableMeasurementConnections",
38 "TractMultiBandTableMeasurementConfig",
39 "TractMultiBandTableMeasurementTask",
40)
43class TractTableMeasurementConnections(
44 CatalogMeasurementBaseConnections,
45 dimensions=("tract", "skymap", "band"),
46):
48 catalog = pipeBase.connectionTypes.Input(
49 doc="Object table in parquet format, per tract",
50 dimensions=("tract", "skymap"),
51 storageClass="DataFrame",
52 name="objectTable_tract",
53 deferLoad=True,
54 )
56 measurement = pipeBase.connectionTypes.Output(
57 doc="Per-tract measurement.",
58 dimensions=("tract", "skymap", "band"),
59 storageClass="MetricValue",
60 name="metricvalue_{package}_{metric}",
61 )
64class TractTableMeasurementConfig(
65 CatalogMeasurementBaseConfig, pipelineConnections=TractTableMeasurementConnections
66):
67 """Configuration for TractTableMeasurementTask."""
69 columns = pexConfig.ListField(
70 doc="Band-independent columns from objectTable_tract to load.",
71 dtype=str,
72 default=["coord_ra", "coord_dec", "detect_isPrimary"],
73 )
75 columnsBand = pexConfig.ListField(
76 doc="Band-specific columns from objectTable_tract to load.",
77 dtype=str,
78 default=["psfFlux", "psfFluxErr"],
79 )
81 instrument = pexConfig.Field(
82 doc="Instrument.",
83 dtype=str,
84 default='hsc',
85 )
88class TractTableMeasurementTask(CatalogMeasurementBaseTask):
89 """Base class for per-band science performance metrics measured on single-tract object catalogs."""
91 ConfigClass = TractTableMeasurementConfig
92 _DefaultName = "tractTableMeasurementTask"
94 def runQuantum(self, butlerQC, inputRefs, outputRefs):
95 inputs = butlerQC.get(inputRefs)
96 kwargs = {"band": butlerQC.quantum.dataId['band']}
98 columns = self.config.columns.list()
99 for column in self.config.columnsBand:
100 columns.append(kwargs["band"] + column)
101 kwargs["catalog"] = inputs["catalog"].get(parameters={"columns": columns})
103 if self.config.connections.refDataset != "":
104 refCats = inputs.pop("refCat")
105 filter_map = FilterMap()
106 filterList = filter_map.getFilters(self.config.instrument,
107 [kwargs["band"]])
109 # TODO: add capability to select the reference epoch
110 epoch = None
111 refCat, refCatCorrected = self._getReferenceCatalog(
112 butlerQC,
113 [ref.datasetRef.dataId for ref in inputRefs.refCat],
114 refCats,
115 filterList,
116 epoch,
117 )
118 kwargs["refCat"] = refCat
119 kwargs["refCatCorrected"] = refCatCorrected
121 outputs = self.run(**kwargs)
122 if outputs.measurement is not None:
123 butlerQC.put(outputs, outputRefs)
124 else:
125 self.log.debugf(
126 "Skipping measurement of {!r} on {} " "as not applicable.",
127 self,
128 inputRefs,
129 )
132class TractMultiBandTableMeasurementConnections(
133 TractTableMeasurementConnections,
134 dimensions=("tract", "skymap"),
135):
137 catalog = pipeBase.connectionTypes.Input(
138 doc="Object table in parquet format, per tract.",
139 dimensions=("tract", "skymap"),
140 storageClass="DataFrame",
141 name="objectTable_tract",
142 deferLoad=True,
143 )
145 measurement = pipeBase.connectionTypes.Output(
146 doc="Per-tract measurement.",
147 dimensions=("tract", "skymap"),
148 storageClass="MetricValue",
149 name="metricvalue_{package}_{metric}",
150 )
153class TractMultiBandTableMeasurementConfig(
154 TractTableMeasurementConfig,
155 pipelineConnections=TractMultiBandTableMeasurementConnections,
156):
157 """Configuration for TractMultiBandTableMeasurementTask."""
159 bands = pexConfig.ListField(
160 doc="Bands for band-specific column loading from objectTable_tract.",
161 dtype=str,
162 default=["g", "r", "i", "z", "y"],
163 )
166class TractMultiBandTableMeasurementTask(TractTableMeasurementTask):
168 """Base class for science performance metrics measured on single-tract object catalogs, multi-band."""
170 ConfigClass = TractMultiBandTableMeasurementConfig
171 _DefaultName = "tractMultiBandTableMeasurementTask"
173 def runQuantum(self, butlerQC, inputRefs, outputRefs):
174 inputs = butlerQC.get(inputRefs)
176 kwargs = {"bands": self.config.bands.list()}
178 columns = self.config.columns.list()
179 for band in self.config.bands:
180 for column in self.config.columnsBand:
181 columns.append(band + column)
182 kwargs["catalog"] = inputs["catalog"].get(parameters={"columns": columns})
184 if self.config.connections.refDataset != "":
185 refCats = inputs.pop("refCat")
186 filter_map = FilterMap()
187 filterList = filter_map.getFilters(self.config.instrument,
188 self.config.bands)
190 # TODO: add capability to select the reference epoch
191 epoch = None
192 refCat, refCatCorrected = self._getReferenceCatalog(
193 butlerQC,
194 [ref.datasetRef.dataId for ref in inputRefs.refCat],
195 refCats,
196 filterList,
197 epoch,
198 )
199 kwargs["refCat"] = refCat
200 kwargs["refCatCorrected"] = refCatCorrected
202 outputs = self.run(**kwargs)
203 if outputs.measurement is not None:
204 butlerQC.put(outputs, outputRefs)
205 else:
206 self.log.debugf(
207 "Skipping measurement of {!r} on {} " "as not applicable.",
208 self,
209 inputRefs,
210 )