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 MetricConnections, MetricComputationError
24from lsst.faro.base.CatalogMeasurementBase import (
25 CatalogMeasurementBaseConfig,
26 CatalogMeasurementBaseTask,
27)
29__all__ = (
30 "PatchMatchedMeasurementConnections",
31 "PatchMatchedMeasurementConfig",
32 "PatchMatchedMeasurementTask",
33 "TractMatchedMeasurementConnections",
34 "TractMatchedMeasurementConfig",
35 "TractMatchedMeasurementTask",
36 "PatchMatchedMultiBandMeasurementConnections",
37 "PatchMatchedMultiBandMeasurementConfig",
38 "PatchMatchedMultiBandMeasurementTask",
39)
41# The first thing to do is to define a Connections class. This will define all
42# the inputs and outputs that our task requires
45class PatchMatchedMeasurementConnections(
46 MetricConnections, dimensions=("tract", "patch", "band", "instrument", "skymap")
47):
48 cat = pipeBase.connectionTypes.Input(
49 doc="Input matched catalog.",
50 dimensions=("tract", "patch", "instrument", "band"),
51 storageClass="SimpleCatalog",
52 name="matchedCatalogPatch",
53 )
54 measurement = pipeBase.connectionTypes.Output(
55 doc="Resulting matched catalog.",
56 dimensions=("tract", "patch", "instrument", "band"),
57 storageClass="MetricValue",
58 name="metricvalue_{package}_{metric}",
59 )
62class PatchMatchedMeasurementConfig(
63 CatalogMeasurementBaseConfig, pipelineConnections=PatchMatchedMeasurementConnections
64):
65 pass
68class PatchMatchedMeasurementTask(CatalogMeasurementBaseTask):
69 ConfigClass = PatchMatchedMeasurementConfig
70 _DefaultName = "patchMatchedMeasurementTask"
73class TractMatchedMeasurementConnections(
74 PatchMatchedMeasurementConnections,
75 dimensions=("tract", "instrument", "band", "skymap"),
76):
77 cat = pipeBase.connectionTypes.Input(
78 doc="Input matched catalog.",
79 dimensions=("tract", "instrument", "band"),
80 storageClass="SimpleCatalog",
81 name="matchedCatalogTract",
82 )
83 measurement = pipeBase.connectionTypes.Output(
84 doc="Resulting matched catalog.",
85 dimensions=("tract", "instrument", "band"),
86 storageClass="MetricValue",
87 name="metricvalue_{package}_{metric}",
88 )
91class TractMatchedMeasurementConfig(
92 CatalogMeasurementBaseConfig, pipelineConnections=TractMatchedMeasurementConnections
93):
94 pass
97class TractMatchedMeasurementTask(CatalogMeasurementBaseTask):
98 ConfigClass = TractMatchedMeasurementConfig
99 _DefaultName = "tractMatchedMeasurementTask"
102class PatchMatchedMultiBandMeasurementConnections(
103 MetricConnections, dimensions=("tract", "patch", "band", "instrument", "skymap")
104):
105 cat = pipeBase.connectionTypes.Input(
106 doc="Input matched catalog.",
107 dimensions=("tract", "patch", "instrument"),
108 storageClass="SimpleCatalog",
109 name="matchedCatalogPatchMultiBand",
110 )
111 measurement = pipeBase.connectionTypes.Output(
112 doc="Resulting matched catalog.",
113 dimensions=("tract", "patch", "instrument", "band"),
114 storageClass="MetricValue",
115 name="metricvalue_{package}_{metric}",
116 )
119class PatchMatchedMultiBandMeasurementConfig(
120 CatalogMeasurementBaseConfig,
121 pipelineConnections=PatchMatchedMultiBandMeasurementConnections,
122):
123 pass
126class PatchMatchedMultiBandMeasurementTask(CatalogMeasurementBaseTask):
127 ConfigClass = PatchMatchedMultiBandMeasurementConfig
128 _DefaultName = "patchMatchedMultiBandMeasurementTask"
130 def run(self, cat, in_id, out_id):
131 return self.measure.run(cat, self.config.connections.metric, in_id, out_id)
133 def runQuantum(self, butlerQC, inputRefs, outputRefs):
134 """Do Butler I/O to provide in-memory objects for run.
135 This specialization of runQuantum performs error-handling specific to
136 MetricTasks. Most or all of this functionality may be moved to
137 activators in the future.
138 """
139 try:
140 in_id = butlerQC.registry.expandDataId(inputRefs.cat.dataId)
141 out_id = butlerQC.registry.expandDataId(outputRefs.measurement.dataId)
142 inputs = butlerQC.get(inputRefs)
143 inputs["in_id"] = in_id
144 inputs["out_id"] = out_id
145 outputs = self.run(**inputs)
146 if outputs.measurement is not None:
147 butlerQC.put(outputs, outputRefs)
148 else:
149 self.log.debug(
150 "Skipping measurement of {!r} on {} " "as not applicable.",
151 self,
152 inputRefs,
153 )
154 except MetricComputationError as e:
155 self.log.error(
156 "Measurement of {!r} failed on {}->{}\n{}\n,%s",
157 self,
158 inputRefs,
159 outputRefs,
160 traceback.format_exc(),
161 e.msg,
162 )