Coverage for python/lsst/faro/measurement/TractTableMeasurement.py: 40%
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/>.
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", "deblend_nChild"],
73 )
75 columnsBand = pexConfig.ListField(
76 doc="Band-specific columns from objectTable_tract to load.",
77 dtype=str,
78 default=["psfFlux", "psfFluxErr", "extendedness", "ixx", "iyy", "ixy",
79 "ixxPSF", "iyyPSF", "ixyPSF"],
80 )
82 instrument = pexConfig.Field(
83 doc="Instrument.",
84 dtype=str,
85 default='hsc',
86 )
89class TractTableMeasurementTask(CatalogMeasurementBaseTask):
90 """Base class for per-band science performance metrics measured on single-tract object catalogs."""
92 ConfigClass = TractTableMeasurementConfig
93 _DefaultName = "tractTableMeasurementTask"
95 def runQuantum(self, butlerQC, inputRefs, outputRefs):
96 inputs = butlerQC.get(inputRefs)
97 kwargs = {"band": butlerQC.quantum.dataId['band']}
99 columns = self.config.columns.list()
100 for column in self.config.columnsBand:
101 columns.append(kwargs["band"] + "_" + column)
102 kwargs["catalog"] = inputs["catalog"].get(parameters={"columns": columns})
104 if self.config.connections.refDataset != "":
105 refCats = inputs.pop("refCat")
106 filter_map = FilterMap()
107 filterList = filter_map.getFilters(self.config.instrument,
108 [kwargs["band"]])
110 # TODO: add capability to select the reference epoch
111 epoch = None
112 refCat, refCatCorrected = self._getReferenceCatalog(
113 butlerQC,
114 [ref.datasetRef.dataId for ref in inputRefs.refCat],
115 refCats,
116 filterList,
117 epoch,
118 )
119 kwargs["refCat"] = refCat
120 kwargs["refCatCorrected"] = refCatCorrected
122 outputs = self.run(**kwargs)
123 if outputs.measurement is not None:
124 butlerQC.put(outputs, outputRefs)
125 else:
126 self.log.debugf(
127 "Skipping measurement of {!r} on {} " "as not applicable.",
128 self,
129 inputRefs,
130 )
133class TractMultiBandTableMeasurementConnections(
134 TractTableMeasurementConnections,
135 dimensions=("tract", "skymap"),
136):
138 catalog = pipeBase.connectionTypes.Input(
139 doc="Object table in parquet format, per tract.",
140 dimensions=("tract", "skymap"),
141 storageClass="DataFrame",
142 name="objectTable_tract",
143 deferLoad=True,
144 )
146 measurement = pipeBase.connectionTypes.Output(
147 doc="Per-tract measurement.",
148 dimensions=("tract", "skymap"),
149 storageClass="MetricValue",
150 name="metricvalue_{package}_{metric}",
151 )
154class TractMultiBandTableMeasurementConfig(
155 TractTableMeasurementConfig,
156 pipelineConnections=TractMultiBandTableMeasurementConnections,
157):
158 """Configuration for TractMultiBandTableMeasurementTask."""
160 bands = pexConfig.ListField(
161 doc="Bands for band-specific column loading from objectTable_tract.",
162 dtype=str,
163 default=["g", "r", "i", "z", "y"],
164 )
167class TractMultiBandTableMeasurementTask(TractTableMeasurementTask):
169 """Base class for science performance metrics measured on single-tract object catalogs, multi-band."""
171 ConfigClass = TractMultiBandTableMeasurementConfig
172 _DefaultName = "tractMultiBandTableMeasurementTask"
174 def runQuantum(self, butlerQC, inputRefs, outputRefs):
175 inputs = butlerQC.get(inputRefs)
177 kwargs = {"bands": self.config.bands.list()}
179 columns = self.config.columns.list()
180 for band in self.config.bands:
181 for column in self.config.columnsBand:
182 columns.append(band + "_" + column)
183 kwargs["catalog"] = inputs["catalog"].get(parameters={"columns": columns})
185 if self.config.connections.refDataset != "":
186 refCats = inputs.pop("refCat")
187 filter_map = FilterMap()
188 filterList = filter_map.getFilters(self.config.instrument,
189 self.config.bands)
191 # TODO: add capability to select the reference epoch
192 epoch = None
193 refCat, refCatCorrected = self._getReferenceCatalog(
194 butlerQC,
195 [ref.datasetRef.dataId for ref in inputRefs.refCat],
196 refCats,
197 filterList,
198 epoch,
199 )
200 kwargs["refCat"] = refCat
201 kwargs["refCatCorrected"] = refCatCorrected
203 outputs = self.run(**kwargs)
204 if outputs.measurement is not None:
205 butlerQC.put(outputs, outputRefs)
206 else:
207 self.log.debugf(
208 "Skipping measurement of {!r} on {} " "as not applicable.",
209 self,
210 inputRefs,
211 )