Coverage for python/lsst/analysis/tools/atools/cpVerifyQuantityProfile.py: 44%
59 statements
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-17 03:59 -0700
« prev ^ index » next coverage.py v7.4.4, created at 2024-04-17 03:59 -0700
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
23from lsst.analysis.tools.interfaces._interfaces import KeyedDataSchema
25__all__ = (
26 "CPVerifyQuantityBaseTool",
27 "CPVerifyQuantityAmpProfileScatterTool",
28 "CPVerifyQuantityAmpProfileHistTool",
29)
31from typing import cast
33from lsst.pex.config import Field
34from lsst.pex.config.configurableActions import ConfigurableActionField
36from ..actions.plot.elements import HistElement, ScatterElement
37from ..actions.plot.gridPlot import GridPanelConfig, GridPlot
38from ..interfaces import AnalysisTool, KeyedData, KeyedDataAction, PlotElement, Vector
41class PrepRepacker(KeyedDataAction):
42 """Prep action to repack data."""
44 panelKey = Field[str](
45 doc="Panel selector. Data will be separated into multiple panels based on this key.",
46 )
47 dataKey = Field[str](
48 doc="Data selector. Data will be separated into multiple groups in a single panel based on this key.",
49 )
50 quantityKey = Field[str](
51 doc="Quantity selector. The actual data quantities to be plotted.",
52 )
54 def __call__(self, data: KeyedData, **kwargs) -> KeyedData:
55 repackedData = {}
56 # Loop over the length of the data vector and repack row by row
57 for i in range(len(cast(Vector, data[self.panelKey]))):
58 panelVec = cast(Vector, data[self.panelKey])
59 dataVec = cast(Vector, data[self.dataKey])
60 quantityVec = cast(Vector, data[self.quantityKey])
61 repackedData[f"{panelVec[i]}_{dataVec[i]}_{self.quantityKey}"] = quantityVec[i]
62 return repackedData
64 def getInputSchema(self) -> KeyedDataSchema:
65 return (
66 (self.panelKey, Vector),
67 (self.dataKey, Vector),
68 (self.quantityKey, Vector),
69 )
71 def addInputSchema(self, inputSchema: KeyedDataSchema) -> None:
72 pass
75class PassThrough(KeyedDataAction):
76 def __call__(self, data: KeyedData, **kwargs) -> KeyedData:
77 return data
79 def getInputSchema(self) -> KeyedDataSchema:
80 # In general this method should be implemented, but here we are ALSO
81 # implementing the prep step. We therefore know the method results are
82 # not needed because it is doing something special with the inputs.
83 return ()
86class CPVerifyQuantityBaseTool(AnalysisTool):
87 parameterizedBand: bool = False
89 plotElement = ConfigurableActionField[PlotElement](
90 doc="Plot element.",
91 )
93 def setDefaults(self):
94 super().setDefaults()
96 # Repack the input data into a usable format
97 self.prep = PrepRepacker()
99 # A simple pass-through process action to keep the data unchanged
100 self.process = PassThrough()
102 # Plot the repacked data in a 4x4 grid
103 self.produce.plot = GridPlot()
104 self.produce.plot.panels = {}
105 self.produce.plot.numRows = 4
106 self.produce.plot.numCols = 4
108 # Values to group by to distinguish between data in differing panels
109 self.produce.plot.valsGroupBy = {
110 0: "C00",
111 1: "C01",
112 2: "C02",
113 3: "C03",
114 4: "C04",
115 5: "C05",
116 6: "C06",
117 7: "C07",
118 8: "C10",
119 9: "C11",
120 10: "C12",
121 11: "C13",
122 12: "C14",
123 13: "C15",
124 14: "C16",
125 15: "C17",
126 }
128 def finalize(self):
129 super().finalize()
131 # Configure each panel
132 for key, value in self.produce.plot.valsGroupBy.items():
133 gridPanelConfig = GridPanelConfig(
134 plotElement=self.plotElement,
135 title={"label": str(value), "fontsize": "10"},
136 titleY=0.85,
137 )
138 self.produce.plot.panels[key] = gridPanelConfig
141class CPVerifyQuantityAmpProfileScatterTool(CPVerifyQuantityBaseTool):
142 def setDefaults(self):
143 super().setDefaults()
144 self.plotElement = ScatterElement()
145 self.prep.panelKey = "amplifier"
146 self.prep.dataKey = "mjd"
149class CPVerifyQuantityAmpProfileHistTool(CPVerifyQuantityBaseTool):
150 def setDefaults(self):
151 super().setDefaults()
152 self.plotElement = HistElement()
153 self.prep.panelKey = "amplifier"
154 self.prep.dataKey = "mjd"