Coverage for python/lsst/faro/measurement/PatchTableMeasurement.py: 39%
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 "PatchTableMeasurementConnections",
35 "PatchTableMeasurementConfig",
36 "PatchTableMeasurementTask",
37 "PatchMultiBandTableMeasurementConnections",
38 "PatchMultiBandTableMeasurementConfig",
39 "PatchMultiBandTableMeasurementTask",
40)
43class PatchTableMeasurementConnections(
44 CatalogMeasurementBaseConnections,
45 dimensions=("tract", "patch", "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", "patch", "skymap", "band"),
59 storageClass="MetricValue",
60 name="metricvalue_{package}_{metric}",
61 )
64class PatchTableMeasurementConfig(
65 CatalogMeasurementBaseConfig, pipelineConnections=PatchTableMeasurementConnections
66):
67 """Configuration for PatchTableMeasurementTask."""
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", "patch"],
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 PatchTableMeasurementTask(CatalogMeasurementBaseTask):
89 """Base class for per-band science performance metrics measured on single-tract object catalogs."""
91 ConfigClass = PatchTableMeasurementConfig
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 catalog = inputs["catalog"].get(parameters={"columns": columns})
102 selection = (catalog["patch"] == butlerQC.quantum.dataId["patch"])
103 kwargs["catalog"] = catalog[selection]
105 if self.config.connections.refDataset != "":
106 refCats = inputs.pop("refCat")
107 filter_map = FilterMap()
108 filterList = filter_map.getFilters(self.config.instrument,
109 [kwargs["band"]])
111 # TODO: add capability to select the reference epoch
112 epoch = None
113 refCat = self._getReferenceCatalog(
114 butlerQC,
115 [ref.datasetRef.dataId for ref in inputRefs.refCat],
116 refCats,
117 filterList,
118 epoch,
119 )
120 kwargs["refCat"] = refCat
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 PatchMultiBandTableMeasurementConnections(
134 PatchTableMeasurementConnections,
135 dimensions=("tract", "patch", "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", "patch", "skymap"),
149 storageClass="MetricValue",
150 name="metricvalue_{package}_{metric}",
151 )
154class PatchMultiBandTableMeasurementConfig(
155 PatchTableMeasurementConfig,
156 pipelineConnections=PatchMultiBandTableMeasurementConnections,
157):
158 """Configuration for PatchMultiBandTableMeasurementTask."""
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 PatchMultiBandTableMeasurementTask(PatchTableMeasurementTask):
169 """Base class for science performance metrics measured on single-tract source catalogs, multi-band."""
171 ConfigClass = PatchMultiBandTableMeasurementConfig
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 catalog = inputs["catalog"].get(parameters={"columns": columns})
184 selection = (catalog["patch"] == butlerQC.quantum.dataId["patch"])
185 kwargs["catalog"] = catalog[selection]
187 if self.config.connections.refDataset != "":
188 refCats = inputs.pop("refCat")
189 filter_map = FilterMap()
190 filterList = filter_map.getFilters(self.config.instrument,
191 self.config.bands)
193 # TODO: add capability to select the reference epoch
194 epoch = None
195 refCat = self._getReferenceCatalog(
196 butlerQC,
197 [ref.datasetRef.dataId for ref in inputRefs.refCat],
198 refCats,
199 filterList,
200 epoch,
201 )
202 kwargs["refCat"] = refCat
204 outputs = self.run(**kwargs)
205 if outputs.measurement is not None:
206 butlerQC.put(outputs, outputRefs)
207 else:
208 self.log.debugf(
209 "Skipping measurement of {!r} on {} " "as not applicable.",
210 self,
211 inputRefs,
212 )