Coverage for python/lsst/faro/measurement/MatchedCatalogMeasurement.py: 67%
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/>.
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, dimensions=("tract", "patch", "band", "instrument", "skymap")
51):
52 matchedCatalog = pipeBase.connectionTypes.Input(
53 doc="Input matched catalog.",
54 dimensions=("tract", "patch", "instrument", "band"),
55 storageClass="SimpleCatalog",
56 name="matchedCatalogPatch",
57 )
58 measurement = pipeBase.connectionTypes.Output(
59 doc="Resulting matched catalog.",
60 dimensions=("tract", "patch", "instrument", "band"),
61 storageClass="MetricValue",
62 name="metricvalue_{package}_{metric}",
63 )
66class PatchMatchedMeasurementConfig(
67 CatalogMeasurementBaseConfig, pipelineConnections=PatchMatchedMeasurementConnections
68):
69 pass
72class PatchMatchedMeasurementTask(CatalogMeasurementBaseTask):
73 ConfigClass = PatchMatchedMeasurementConfig
74 _DefaultName = "patchMatchedMeasurementTask"
77class TractMatchedMeasurementConnections(
78 PatchMatchedMeasurementConnections,
79 dimensions=("tract", "instrument", "band", "skymap"),
80):
81 matchedCatalog = pipeBase.connectionTypes.Input(
82 doc="Input matched catalog.",
83 dimensions=("tract", "instrument", "band"),
84 storageClass="SimpleCatalog",
85 name="matchedCatalogTract",
86 )
87 measurement = pipeBase.connectionTypes.Output(
88 doc="Resulting matched catalog.",
89 dimensions=("tract", "instrument", "band"),
90 storageClass="MetricValue",
91 name="metricvalue_{package}_{metric}",
92 )
95class TractMatchedMeasurementConfig(
96 CatalogMeasurementBaseConfig, pipelineConnections=TractMatchedMeasurementConnections
97):
98 pass
101class TractMatchedMeasurementTask(CatalogMeasurementBaseTask):
102 ConfigClass = TractMatchedMeasurementConfig
103 _DefaultName = "tractMatchedMeasurementTask"
106class PatchMatchedMultiBandMeasurementConnections(
107 CatalogMeasurementBaseConnections, dimensions=("tract", "patch", "band", "instrument", "skymap")
108):
109 matchedCatalogMulti = pipeBase.connectionTypes.Input(
110 doc="Input matched catalog.",
111 dimensions=("tract", "patch", "instrument"),
112 storageClass="SimpleCatalog",
113 name="matchedCatalogPatchMultiBand",
114 )
115 measurement = pipeBase.connectionTypes.Output(
116 doc="Resulting matched catalog.",
117 dimensions=("tract", "patch", "instrument", "band"),
118 storageClass="MetricValue",
119 name="metricvalue_{package}_{metric}",
120 )
123class PatchMatchedMultiBandMeasurementConfig(
124 CatalogMeasurementBaseConfig,
125 pipelineConnections=PatchMatchedMultiBandMeasurementConnections,
126):
127 pass
130class PatchMatchedMultiBandMeasurementTask(CatalogMeasurementBaseTask):
131 ConfigClass = PatchMatchedMultiBandMeasurementConfig
132 _DefaultName = "patchMatchedMultiBandMeasurementTask"
134 def run(self, matchedCatalogMulti, in_id, out_id):
135 return self.measure.run(self.config.connections.metric, matchedCatalogMulti, in_id, out_id)
137 def runQuantum(self, butlerQC, inputRefs, outputRefs):
138 """Do Butler I/O to provide in-memory objects for run.
139 This specialization of runQuantum performs error-handling specific to
140 MetricTasks. Most or all of this functionality may be moved to
141 activators in the future.
142 """
143 try:
144 in_id = butlerQC.registry.expandDataId(inputRefs.matchedCatalogMulti.dataId)
145 out_id = butlerQC.registry.expandDataId(outputRefs.measurement.dataId)
146 inputs = butlerQC.get(inputRefs)
147 inputs["in_id"] = in_id
148 inputs["out_id"] = out_id
149 outputs = self.run(**inputs)
150 if outputs.measurement is not None:
151 butlerQC.put(outputs, outputRefs)
152 else:
153 self.log.debug(
154 "Skipping measurement of {!r} on {} " "as not applicable.",
155 self,
156 inputRefs,
157 )
158 except MetricComputationError as e:
159 self.log.error(
160 "Measurement of {!r} failed on {}->{}\n{}\n,%s",
161 self,
162 inputRefs,
163 outputRefs,
164 traceback.format_exc(),
165 e.msg,
166 )