Coverage for python/lsst/faro/measurement/MatchedCatalogMeasurement.py: 67%
44 statements
« prev ^ index » next coverage.py v6.5.0, created at 2023-04-05 09:10 +0000
« prev ^ index » next coverage.py v6.5.0, created at 2023-04-05 09:10 +0000
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/>.
22import traceback
24import lsst.pipe.base as pipeBase
25from lsst.verify.tasks import MetricComputationError
27from lsst.faro.base.CatalogMeasurementBase import (
28 CatalogMeasurementBaseConnections,
29 CatalogMeasurementBaseConfig,
30 CatalogMeasurementBaseTask,
31)
33__all__ = (
34 "PatchMatchedMeasurementConnections",
35 "PatchMatchedMeasurementConfig",
36 "PatchMatchedMeasurementTask",
37 "TractMatchedMeasurementConnections",
38 "TractMatchedMeasurementConfig",
39 "TractMatchedMeasurementTask",
40 "PatchMatchedMultiBandMeasurementConnections",
41 "PatchMatchedMultiBandMeasurementConfig",
42 "PatchMatchedMultiBandMeasurementTask",
43)
45# The first thing to do is to define a Connections class. This will define all
46# the inputs and outputs that our task requires
49class PatchMatchedMeasurementConnections(
50 CatalogMeasurementBaseConnections,
51 dimensions=("tract", "patch", "band", "instrument", "skymap"),
52):
53 matchedCatalog = pipeBase.connectionTypes.Input(
54 doc="Input matched catalog.",
55 dimensions=("tract", "patch", "instrument", "band"),
56 storageClass="SimpleCatalog",
57 name="matchedCatalogPatch",
58 )
59 measurement = pipeBase.connectionTypes.Output(
60 doc="Resulting matched catalog.",
61 dimensions=("tract", "patch", "instrument", "band"),
62 storageClass="MetricValue",
63 name="metricvalue_{package}_{metric}",
64 )
67class PatchMatchedMeasurementConfig(
68 CatalogMeasurementBaseConfig, pipelineConnections=PatchMatchedMeasurementConnections
69):
70 pass
73class PatchMatchedMeasurementTask(CatalogMeasurementBaseTask):
74 ConfigClass = PatchMatchedMeasurementConfig
75 _DefaultName = "patchMatchedMeasurementTask"
78class TractMatchedMeasurementConnections(
79 PatchMatchedMeasurementConnections,
80 dimensions=("tract", "instrument", "band", "skymap"),
81):
82 matchedCatalog = pipeBase.connectionTypes.Input(
83 doc="Input matched catalog.",
84 dimensions=("tract", "instrument", "band"),
85 storageClass="SimpleCatalog",
86 name="matchedCatalogTract",
87 )
88 measurement = pipeBase.connectionTypes.Output(
89 doc="Resulting matched catalog.",
90 dimensions=("tract", "instrument", "band"),
91 storageClass="MetricValue",
92 name="metricvalue_{package}_{metric}",
93 )
96class TractMatchedMeasurementConfig(
97 CatalogMeasurementBaseConfig, pipelineConnections=TractMatchedMeasurementConnections
98):
99 pass
102class TractMatchedMeasurementTask(CatalogMeasurementBaseTask):
103 ConfigClass = TractMatchedMeasurementConfig
104 _DefaultName = "tractMatchedMeasurementTask"
107class PatchMatchedMultiBandMeasurementConnections(
108 CatalogMeasurementBaseConnections,
109 dimensions=("tract", "patch", "band", "instrument", "skymap"),
110):
111 matchedCatalogMulti = pipeBase.connectionTypes.Input(
112 doc="Input matched catalog.",
113 dimensions=("tract", "patch", "instrument"),
114 storageClass="SimpleCatalog",
115 name="matchedCatalogPatchMultiBand",
116 )
117 measurement = pipeBase.connectionTypes.Output(
118 doc="Resulting matched catalog.",
119 dimensions=("tract", "patch", "instrument", "band"),
120 storageClass="MetricValue",
121 name="metricvalue_{package}_{metric}",
122 )
125class PatchMatchedMultiBandMeasurementConfig(
126 CatalogMeasurementBaseConfig,
127 pipelineConnections=PatchMatchedMultiBandMeasurementConnections,
128):
129 pass
132class PatchMatchedMultiBandMeasurementTask(CatalogMeasurementBaseTask):
133 ConfigClass = PatchMatchedMultiBandMeasurementConfig
134 _DefaultName = "patchMatchedMultiBandMeasurementTask"
136 def run(self, matchedCatalogMulti, in_id, out_id):
137 return self.measure.run(
138 self.config.connections.metric, matchedCatalogMulti, in_id, out_id
139 )
141 def runQuantum(self, butlerQC, inputRefs, outputRefs):
142 """Do Butler I/O to provide in-memory objects for run.
143 This specialization of runQuantum performs error-handling specific to
144 MetricTasks. Most or all of this functionality may be moved to
145 activators in the future.
146 """
147 try:
148 in_id = inputRefs.matchedCatalogMulti.dataId
149 out_id = outputRefs.measurement.dataId
150 inputs = butlerQC.get(inputRefs)
151 inputs["in_id"] = in_id
152 inputs["out_id"] = out_id
153 outputs = self.run(**inputs)
154 if outputs.measurement is not None:
155 butlerQC.put(outputs, outputRefs)
156 else:
157 self.log.debug(
158 "Skipping measurement of {!r} on {} " "as not applicable.",
159 self,
160 inputRefs,
161 )
162 except MetricComputationError as e:
163 self.log.error(
164 "Measurement of {!r} failed on {}->{}\n{}\n,%s",
165 self,
166 inputRefs,
167 outputRefs,
168 traceback.format_exc(),
169 e.msg,
170 )