Coverage for python / lsst / analysis / tools / tasks / metricAnalysis.py: 62%
24 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-30 09:26 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-04-30 09:26 +0000
1# This file is part of analysis_tools.
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/>.
21from __future__ import annotations
23__all__ = (
24 "MetricAnalysisConfig",
25 "MetricAnalysisTask",
26)
29from lsst.pex.config import ListField
30from lsst.pipe.base import connectionTypes as ct
32from ..interfaces import AnalysisBaseConfig, AnalysisBaseConnections, AnalysisPipelineTask
35class MetricAnalysisConnections(
36 AnalysisBaseConnections,
37 dimensions=(),
38 defaultTemplates={"metricTableName": ""},
39):
41 data = ct.Input(
42 doc="A table containing metrics.",
43 name="{metricTableName}",
44 storageClass="ArrowAstropy",
45 deferLoad=True,
46 dimensions=(),
47 )
49 def __init__(self, *, config=None):
51 self.dimensions.update(frozenset(sorted(config.outputDataDimensions)))
52 super().__init__(config=config)
53 self.data = ct.Input(
54 doc=self.data.doc,
55 name=self.data.name,
56 storageClass=self.data.storageClass,
57 deferLoad=self.data.deferLoad,
58 dimensions=frozenset(sorted(config.inputDataDimensions)),
59 )
62class MetricAnalysisConfig(
63 AnalysisBaseConfig,
64 pipelineConnections=MetricAnalysisConnections,
65):
66 inputDataDimensions = ListField[str](
67 doc="Dimensions of the input data table.",
68 default=(),
69 optional=False,
70 )
71 outputDataDimensions = ListField[str](
72 doc="Dimensions of the outputs.",
73 default=(),
74 optional=False,
75 )
78class MetricAnalysisTask(AnalysisPipelineTask):
79 """Take a metric table and run an analysis tool on the
80 data it contains. This could include creating a plot
81 the metrics and/or calculating summary values of those
82 metrics, such as means, medians, etc. The analysis
83 is outlined within the analysis tool.
84 """
86 ConfigClass = MetricAnalysisConfig
87 _DefaultName = "metricAnalysis"
89 def runQuantum(self, butlerQC, inputRefs, outputRefs):
90 # Doctstring inherited
92 inputs = butlerQC.get(inputRefs)
93 dataId = butlerQC.quantum.dataId
94 plotInfo = self.parsePlotInfo(inputs, dataId)
96 data = self.loadData(inputs.pop("data"))
98 # TODO: "bands" kwarg is a workaround for DM-47941.
99 outputs = self.run(
100 data=data,
101 plotInfo=plotInfo,
102 bands=dataId["band"],
103 band=dataId["band"],
104 **inputs,
105 )
107 butlerQC.put(outputs, outputRefs)