Skip to content

Commit 7255cdc

Browse files
committed
start work on supporting multiple quantities in CalibAmpScatterTool
1 parent cda0bd4 commit 7255cdc

2 files changed

Lines changed: 67 additions & 89 deletions

File tree

pipelines/cpCore.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,28 +44,28 @@ tasks:
4444
atools.biasMeanByDate: CalibAmpScatterTool
4545
atools.biasMeanByDate.prep.panelKey: amplifier
4646
atools.biasMeanByDate.prep.dataKey: mjd
47-
atools.biasMeanByDate.prep.quantityKey: BIAS_MEAN
47+
atools.biasMeanByDate.prep.quantityKey: ["BIAS_MEAN"]
4848
atools.biasMeanByDate.produce.plot.xAxisLabel: "MJD"
4949
atools.biasMeanByDate.produce.plot.yAxisLabel: "Residual bias mean (ADU)"
5050

5151
atools.biasStdByDate: CalibAmpScatterTool
5252
atools.biasStdByDate.prep.panelKey: amplifier
5353
atools.biasStdByDate.prep.dataKey: mjd
54-
atools.biasStdByDate.prep.quantityKey: BIAS_NOISE
54+
atools.biasStdByDate.prep.quantityKey: ["BIAS_NOISE"]
5555
atools.biasStdByDate.produce.plot.xAxisLabel: "MJD"
5656
atools.biasStdByDate.produce.plot.yAxisLabel: "Residual bias stdev (ADU)"
5757

5858
atools.biasROCornerByDate: CalibAmpScatterTool
5959
atools.biasROCornerByDate.prep.panelKey: amplifier
6060
atools.biasROCornerByDate.prep.dataKey: mjd
61-
atools.biasROCornerByDate.prep.quantityKey: BIAS_AMP_CORNER
61+
atools.biasROCornerByDate.prep.quantityKey: ["BIAS_AMP_CORNER"]
6262
atools.biasROCornerByDate.produce.plot.xAxisLabel: "MJD"
6363
atools.biasROCornerByDate.produce.plot.yAxisLabel: "Residual bias mean at RO corner (ADU)"
6464

6565
atools.biasTestsByDate: CalibAmpScatterTool
6666
atools.biasTestsByDate.prep.panelKey: amplifier
6767
atools.biasTestsByDate.prep.dataKey: mjd
68-
atools.biasTestsByDate.prep.quantityKey: BIAS_VERIFY_MEAN
68+
atools.biasTestsByDate.prep.quantityKey: ["BIAS_VERIFY_MEAN"]
6969
atools.biasTestsByDate.produce.plot.xAxisLabel: "MJD"
7070
atools.biasTestsByDate.produce.plot.yAxisLabel: "Bias Test Passing"
7171

@@ -118,21 +118,21 @@ tasks:
118118
atools.darkMeanByDate: CalibAmpScatterTool
119119
atools.darkMeanByDate.prep.panelKey: amplifier
120120
atools.darkMeanByDate.prep.dataKey: mjd
121-
atools.darkMeanByDate.prep.quantityKey: DARK_MEAN
121+
atools.darkMeanByDate.prep.quantityKey: ["DARK_MEAN"]
122122
atools.darkMeanByDate.produce.plot.xAxisLabel: "MJD"
123123
atools.darkMeanByDate.produce.plot.yAxisLabel: "Residual dark mean (ADU)"
124124

125125
atools.darkStdByDate: CalibAmpScatterTool
126126
atools.darkStdByDate.prep.panelKey: amplifier
127127
atools.darkStdByDate.prep.dataKey: mjd
128-
atools.darkStdByDate.prep.quantityKey: DARK_NOISE
128+
atools.darkStdByDate.prep.quantityKey: ["DARK_NOISE"]
129129
atools.darkStdByDate.produce.plot.xAxisLabel: "MJD"
130130
atools.darkStdByDate.produce.plot.yAxisLabel: "Residual dark std (ADU)"
131131

132132
atools.darkTestsByDate: CalibAmpScatterTool
133133
atools.darkTestsByDate.prep.panelKey: amplifier
134134
atools.darkTestsByDate.prep.dataKey: mjd
135-
atools.darkTestsByDate.prep.quantityKey: DARK_VERIFY_MEAN
135+
atools.darkTestsByDate.prep.quantityKey: ["DARK_VERIFY_MEAN"]
136136
atools.darkTestsByDate.produce.plot.xAxisLabel: "MJD"
137137
atools.darkTestsByDate.produce.plot.yAxisLabel: "Dark Test Passing"
138138

@@ -148,7 +148,7 @@ tasks:
148148
atools.flatTestsByDate: CalibAmpScatterTool
149149
atools.flatTestsByDate.prep.panelKey: amplifier
150150
atools.flatTestsByDate.prep.dataKey: mjd
151-
atools.flatTestsByDate.prep.quantityKey: FLAT_VERIFY_NOISE
151+
atools.flatTestsByDate.prep.quantityKey: ["FLAT_VERIFY_NOISE"]
152152
# TODO: DM-43878
153153
# FLAT_DET_VERIFY_SCATTER
154154
atools.flatTestsByDate.produce.plot.xAxisLabel: "MJD"
@@ -210,7 +210,7 @@ tasks:
210210
atools.ptcPlot: CalibAmpScatterTool
211211
atools.ptcPlot.prep.panelKey: amplifier
212212
atools.ptcPlot.prep.dataKey: PTC_PTC_RAW_MEANS
213-
atools.ptcPlot.prep.quantityKey: PTC_PTC_RAW_VARIANCE
213+
atools.ptcPlot.prep.quantityKey: ["PTC_PTC_RAW_VARIANCE"]
214214
atools.ptcPlot.produce.plot.xAxisLabel: "Exposure Pair Flux (ADU)"
215215
atools.ptcPlot.produce.plot.yAxisLabel: "Exposure Pair Variance (ADU^2)"
216216
python: |

python/lsst/analysis/tools/atools/calibQuantityProfile.py

Lines changed: 58 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,48 @@
3131
"CalibPtcCovarScatterTool",
3232
)
3333

34-
from typing import cast
34+
from typing import cast, TypeVar, Callable, Any
3535

36-
from lsst.pex.config import Field
36+
from lsst.pex.config import Field, ListField
3737
from lsst.pex.config.configurableActions import ConfigurableActionField
3838

3939
from ..actions.plot.elements import HistElement, ScatterElement
4040
from ..actions.plot.gridPlot import GridPanelConfig, GridPlot
4141
from ..interfaces import AnalysisTool, KeyedData, KeyedDataAction, PlotElement, Vector
4242

43+
_CALIB_AMP_NAME_DICT: dict[int, str] = {
44+
0: "C00",
45+
1: "C01",
46+
2: "C02",
47+
3: "C03",
48+
4: "C04",
49+
5: "C05",
50+
6: "C06",
51+
7: "C07",
52+
8: "C10",
53+
9: "C11",
54+
10: "C12",
55+
11: "C13",
56+
12: "C14",
57+
13: "C15",
58+
14: "C16",
59+
15: "C17",
60+
}
61+
62+
63+
RepackerT = TypeVar("RepackerT", bound=[PrepRepacker, SingleValueRepacker])
64+
RepackerLoopFun = Callable[None, [KeyedData, Any, Any, Any, Any]]
65+
def _repack_loop_helper(obj: RepackerT, repackfun: RepackerLoopFun, data: KeyedData) -> KeyedData:
66+
repackedData: dict[str, Vector] = {}
67+
quantitiesData = [data[_] for _ in obj.quantityKey]
68+
69+
for p, d in zip(data[obj.panelKey], data[obj.dataKey]):
70+
for qName, qD in zip(obj.quantityKey, quantitiesData):
71+
RepackerLoopFun(repackedData, p, d, qName, qD)
72+
return repackedData
73+
74+
75+
4376

4477
class PrepRepacker(KeyedDataAction):
4578
"""Prep action to repack data."""
@@ -50,18 +83,15 @@ class PrepRepacker(KeyedDataAction):
5083
dataKey = Field[str](
5184
doc="Data selector. Data will be separated into multiple groups in a single panel based on this key.",
5285
)
53-
quantityKey = Field[str](
86+
quantityKey = ListField[str](
5487
doc="Quantity selector. The actual data quantities to be plotted.",
55-
)
88+
minLength=1, optional=False)
5689

5790
def __call__(self, data: KeyedData, **kwargs) -> KeyedData:
58-
repackedData = {}
59-
# Loop over the length of the data vector and repack row by row
60-
for i in range(len(cast(Vector, data[self.panelKey]))):
61-
panelVec = cast(Vector, data[self.panelKey])
62-
dataVec = cast(Vector, data[self.dataKey])
63-
quantityVec = cast(Vector, data[self.quantityKey])
64-
repackedData[f"{panelVec[i]}_{dataVec[i]}_{self.quantityKey}"] = quantityVec[i]
91+
def rp_loop(rpData: KeyedData, panel, data, quantityName, quantityData):
92+
qName = f"{panel}_{data}_{quantityName}"
93+
rpData[qName] = quantityData
94+
repackedData = _repack_loop_helper(self, rp_loop, data)
6595
return repackedData
6696

6797
def getInputSchema(self) -> KeyedDataSchema:
@@ -84,27 +114,27 @@ class SingleValueRepacker(KeyedDataAction):
84114
dataKey = Field[str](
85115
doc="Data selector. Data will be separated into multiple groups in a single panel based on this key.",
86116
)
87-
quantityKey = Field[str](
117+
quantityKey = ListField[str](
88118
doc="Quantity selector. The actual data quantities to be plotted.",
89-
)
119+
minLength=1, optional=False)
90120

91121
def __call__(self, data: KeyedData, **kwargs) -> KeyedData:
92-
repackedData = {}
93-
uniquePanelKeys = list(set(data[self.panelKey]))
122+
uniquePanelKeys: list = list(set(data[self.panelKey]))
94123

95-
# Loop over data vector to repack information as it is expected.
96-
for i in range(len(uniquePanelKeys)):
97-
repackedData[f"{uniquePanelKeys[i]}_x"] = []
98-
repackedData[f"{uniquePanelKeys[i]}"] = []
124+
repackedData: dict[str, Vector] = {}
125+
uniquePanelKeys: list = list(set(data[self.panelKey]))
99126

100-
panelVec = cast(Vector, data[self.panelKey])
101-
dataVec = cast(Vector, data[self.dataKey])
102-
quantityVec = cast(Vector, data[self.quantityKey])
127+
# Loop over data vector to repack information as it is expected.
128+
for uk in uniquePanelKeys:
129+
repackedData[f"{uk}_x"] = []
130+
for q in self.quantityKey:
131+
repackedData[f"{uk}_{q}"] = []
103132

104-
for i in range(len(panelVec)):
105-
repackedData[f"{panelVec[i]}_x"].append(dataVec[i])
106-
repackedData[f"{panelVec[i]}"].append(quantityVec[i])
133+
def rp_loop(rpData: KeyedData, panel, data, quantityName, quantityData):
134+
rpData[f"{panel}_x"].append(data)
135+
rpData[f"{panel}_{quantityName}"] = quantityData
107136

137+
repackedData: KeyedData = _repack_loop_helper(self, rp_loop, data)
108138
return repackedData
109139

110140
def getInputSchema(self) -> KeyedDataSchema:
@@ -152,24 +182,7 @@ def setDefaults(self):
152182
self.produce.plot.numCols = 4
153183

154184
# Values to group by to distinguish between data in differing panels
155-
self.produce.plot.valsGroupBy = {
156-
0: "C00",
157-
1: "C01",
158-
2: "C02",
159-
3: "C03",
160-
4: "C04",
161-
5: "C05",
162-
6: "C06",
163-
7: "C07",
164-
8: "C10",
165-
9: "C11",
166-
10: "C12",
167-
11: "C13",
168-
12: "C14",
169-
13: "C15",
170-
14: "C16",
171-
15: "C17",
172-
}
185+
self.produce.plot.valsGroupBy = _CALIB_AMP_NAME_DICT
173186

174187
def finalize(self):
175188
super().finalize()
@@ -214,45 +227,10 @@ def setDefaults(self):
214227
self.produce.plot.numCols = 4
215228

216229
# Values to use for x-axis data
217-
self.produce.plot.xDataKeys = {
218-
0: "C00_x",
219-
1: "C01_x",
220-
2: "C02_x",
221-
3: "C03_x",
222-
4: "C04_x",
223-
5: "C05_x",
224-
6: "C06_x",
225-
7: "C07_x",
226-
8: "C10_x",
227-
9: "C11_x",
228-
10: "C12_x",
229-
11: "C13_x",
230-
12: "C14_x",
231-
13: "C15_x",
232-
14: "C16_x",
233-
15: "C17_x",
234-
}
230+
self.produce.plot.xDataKeys = {k : f"{v}_x" for k,v in _CALIB_AMP_NAME_DICT.items()}
235231

236232
# Values to group by to distinguish between data in differing panels
237-
self.produce.plot.valsGroupBy = {
238-
0: "C00",
239-
1: "C01",
240-
2: "C02",
241-
3: "C03",
242-
4: "C04",
243-
5: "C05",
244-
6: "C06",
245-
7: "C07",
246-
8: "C10",
247-
9: "C11",
248-
10: "C12",
249-
11: "C13",
250-
12: "C14",
251-
13: "C15",
252-
14: "C16",
253-
15: "C17",
254-
}
255-
233+
self.produce.plot.valsGroupBy = _CALIB_AMP_NAME_DICT
256234
self.prep.panelKey = "amplifier"
257235
self.prep.dataKey = "mjd"
258236

0 commit comments

Comments
 (0)