Coverage for python/lsst/faro/measurement/MatchedCatalogMeasurement.py : 67%

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 product includes software developed by the LSST Project
2# (https://www.lsst.org).
3# See the COPYRIGHT file at the top-level directory of this distribution
4# for details of code ownership.
5#
6# This program is free software: you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation, either version 3 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program. If not, see <https://www.gnu.org/licenses/>.
19import traceback
21import lsst.pipe.base as pipeBase
22from lsst.verify.tasks import MetricComputationError
24from lsst.faro.base.CatalogMeasurementBase import (
25 CatalogMeasurementBaseConnections,
26 CatalogMeasurementBaseConfig,
27 CatalogMeasurementBaseTask,
28)
30__all__ = (
31 "PatchMatchedMeasurementConnections",
32 "PatchMatchedMeasurementConfig",
33 "PatchMatchedMeasurementTask",
34 "TractMatchedMeasurementConnections",
35 "TractMatchedMeasurementConfig",
36 "TractMatchedMeasurementTask",
37 "PatchMatchedMultiBandMeasurementConnections",
38 "PatchMatchedMultiBandMeasurementConfig",
39 "PatchMatchedMultiBandMeasurementTask",
40)
42# The first thing to do is to define a Connections class. This will define all
43# the inputs and outputs that our task requires
46class PatchMatchedMeasurementConnections(
47 CatalogMeasurementBaseConnections, dimensions=("tract", "patch", "band", "instrument", "skymap")
48):
49 cat = pipeBase.connectionTypes.Input(
50 doc="Input matched catalog.",
51 dimensions=("tract", "patch", "instrument", "band"),
52 storageClass="SimpleCatalog",
53 name="matchedCatalogPatch",
54 )
55 measurement = pipeBase.connectionTypes.Output(
56 doc="Resulting matched catalog.",
57 dimensions=("tract", "patch", "instrument", "band"),
58 storageClass="MetricValue",
59 name="metricvalue_{package}_{metric}",
60 )
63class PatchMatchedMeasurementConfig(
64 CatalogMeasurementBaseConfig, pipelineConnections=PatchMatchedMeasurementConnections
65):
66 pass
69class PatchMatchedMeasurementTask(CatalogMeasurementBaseTask):
70 ConfigClass = PatchMatchedMeasurementConfig
71 _DefaultName = "patchMatchedMeasurementTask"
74class TractMatchedMeasurementConnections(
75 PatchMatchedMeasurementConnections,
76 dimensions=("tract", "instrument", "band", "skymap"),
77):
78 cat = pipeBase.connectionTypes.Input(
79 doc="Input matched catalog.",
80 dimensions=("tract", "instrument", "band"),
81 storageClass="SimpleCatalog",
82 name="matchedCatalogTract",
83 )
84 measurement = pipeBase.connectionTypes.Output(
85 doc="Resulting matched catalog.",
86 dimensions=("tract", "instrument", "band"),
87 storageClass="MetricValue",
88 name="metricvalue_{package}_{metric}",
89 )
92class TractMatchedMeasurementConfig(
93 CatalogMeasurementBaseConfig, pipelineConnections=TractMatchedMeasurementConnections
94):
95 pass
98class TractMatchedMeasurementTask(CatalogMeasurementBaseTask):
99 ConfigClass = TractMatchedMeasurementConfig
100 _DefaultName = "tractMatchedMeasurementTask"
103class PatchMatchedMultiBandMeasurementConnections(
104 CatalogMeasurementBaseConnections, dimensions=("tract", "patch", "band", "instrument", "skymap")
105):
106 cat = pipeBase.connectionTypes.Input(
107 doc="Input matched catalog.",
108 dimensions=("tract", "patch", "instrument"),
109 storageClass="SimpleCatalog",
110 name="matchedCatalogPatchMultiBand",
111 )
112 measurement = pipeBase.connectionTypes.Output(
113 doc="Resulting matched catalog.",
114 dimensions=("tract", "patch", "instrument", "band"),
115 storageClass="MetricValue",
116 name="metricvalue_{package}_{metric}",
117 )
120class PatchMatchedMultiBandMeasurementConfig(
121 CatalogMeasurementBaseConfig,
122 pipelineConnections=PatchMatchedMultiBandMeasurementConnections,
123):
124 pass
127class PatchMatchedMultiBandMeasurementTask(CatalogMeasurementBaseTask):
128 ConfigClass = PatchMatchedMultiBandMeasurementConfig
129 _DefaultName = "patchMatchedMultiBandMeasurementTask"
131 def run(self, cat, in_id, out_id):
132 return self.measure.run(cat, self.config.connections.metric, in_id, out_id)
134 def runQuantum(self, butlerQC, inputRefs, outputRefs):
135 """Do Butler I/O to provide in-memory objects for run.
136 This specialization of runQuantum performs error-handling specific to
137 MetricTasks. Most or all of this functionality may be moved to
138 activators in the future.
139 """
140 try:
141 in_id = butlerQC.registry.expandDataId(inputRefs.cat.dataId)
142 out_id = butlerQC.registry.expandDataId(outputRefs.measurement.dataId)
143 inputs = butlerQC.get(inputRefs)
144 inputs["in_id"] = in_id
145 inputs["out_id"] = out_id
146 outputs = self.run(**inputs)
147 if outputs.measurement is not None:
148 butlerQC.put(outputs, outputRefs)
149 else:
150 self.log.debug(
151 "Skipping measurement of {!r} on {} " "as not applicable.",
152 self,
153 inputRefs,
154 )
155 except MetricComputationError as e:
156 self.log.error(
157 "Measurement of {!r} failed on {}->{}\n{}\n,%s",
158 self,
159 inputRefs,
160 outputRefs,
161 traceback.format_exc(),
162 e.msg,
163 )