Skip to content

Commit ac5c734

Browse files
Replace i10 ID tests that use pickle files with json (#1714)
* add i09 look up table praiser * move get_poly to lookuptable * extracted EnergyMotorLookup base class from i10EnergyMotorLookup * added new make_phase_tables function * add test for correct table output * remove_i09 * add docstring * add test for helper functions * add test for skipping * spacing fix * Refactor Lookuptable class documentation Removed outdated docstring from Lookuptable class and updated initialization docstring for I10EnergyMotorLookup class. * change lookup table schema to snake case * replace dictionary with basemodel * add tying * add gap and phase * fat finger correction * Update ID lookup logic to use type checking * Fix some tests * Improve models to not use shared defaults * undo syntax error * Fixed test to check for success on loading i10 lut * Simplified lut logic * Added back generate_lookup_table function * Fixed all tests but polarisation * Updated doc strings * Moved generic test from i10 to test_lookup_table_apple2 * Renamed lut_column_config to lut_config * Updated more doc strings * Fix default phase_file name and thus tests * Use Pol in LookupTable rather than string * Updated test_convert_csv_to_lookup_overwrite_name_convert_default to use Pol * Update tests to use Pol rather str value * Improve EnergyCoverageEntry to have a poly serializer and EnergyCoverage to use float as key * Add type checking to i10Apple2 phase * Removed commente out code * Update i10 id tests to use json files rather than pickle files so they are human readable * Remove comments * Fixed poly test * Fixed test_make_phase_tables_multiple_entries * Added test_lookup_table_is_serialisable * Update src/dodal/devices/util/lookup_tables_apple2.py Co-authored-by: Raymond Fan <[email protected]> * Fixed formatting * Improved code coverage --------- Co-authored-by: Relm-Arrowny <[email protected]>
1 parent b68dfe8 commit ac5c734

11 files changed

+1029
-22
lines changed

src/dodal/devices/util/lookup_tables_apple2.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
Field,
4242
RootModel,
4343
field_serializer,
44+
field_validator,
4445
)
4546

4647
from dodal.devices.apple2_undulator import Pol
@@ -109,6 +110,14 @@ class EnergyCoverageEntry(BaseModel):
109110
high: float
110111
poly: np.poly1d
111112

113+
@field_validator("poly", mode="before")
114+
@classmethod
115+
def validate_and_convert_poly(cls, value):
116+
"""If reading from serialized data, it will be using a list. Convert to np.poly1d"""
117+
if isinstance(value, list):
118+
return np.poly1d(value)
119+
return value
120+
112121
@field_serializer("poly", mode="plain")
113122
def serialize_poly(self, value: np.poly1d) -> list:
114123
"""Allow np.poly1d to work when serializing."""

tests/devices/i10/test_data/__init__.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,24 @@
99
ID_ENERGY_2_PHASE_CALIBRATIONS_CSV = join(
1010
LOOKUP_TABLE_PATH, "IDEnergy2PhaseCalibrations.csv"
1111
)
12-
EXPECTED_ID_ENERGY_2_GAP_CALIBRATIONS_IDD_PKL = join(
13-
LOOKUP_TABLE_PATH, "expectedIDEnergy2GapCalibrationsIdd.pkl"
12+
EXPECTED_ID_ENERGY_2_GAP_CALIBRATIONS_IDD_JSON = join(
13+
LOOKUP_TABLE_PATH, "expectedIDEnergy2GapCalibrationsIdd.json"
1414
)
15-
EXPECTED_ID_ENERGY_2_GAP_CALIBRATIONS_IDU_PKL = join(
16-
LOOKUP_TABLE_PATH, "expectedIDEnergy2GapCalibrationsIdu.pkl"
15+
EXPECTED_ID_ENERGY_2_GAP_CALIBRATIONS_IDU_JSON = join(
16+
LOOKUP_TABLE_PATH, "expectedIDEnergy2GapCalibrationsIdu.json"
1717
)
18-
EXPECTED_ID_ENERGY_2_PHASE_CALIBRATIONS_IDD_PKL = join(
19-
LOOKUP_TABLE_PATH, "expectedIDEnergy2PhaseCalibrationsidd.pkl"
18+
EXPECTED_ID_ENERGY_2_PHASE_CALIBRATIONS_IDD_JSON = join(
19+
LOOKUP_TABLE_PATH, "expectedIDEnergy2PhaseCalibrationsidd.json"
2020
)
21-
EXPECTED_ID_ENERGY_2_PHASE_CALIBRATIONS_IDU_PKL = join(
22-
LOOKUP_TABLE_PATH, "expectedIDEnergy2PhaseCalibrationsidu.pkl"
21+
EXPECTED_ID_ENERGY_2_PHASE_CALIBRATIONS_IDU_JSON = join(
22+
LOOKUP_TABLE_PATH, "expectedIDEnergy2PhaseCalibrationsidu.json"
2323
)
2424
__all__ = [
2525
"LOOKUP_TABLE_PATH",
2626
"ID_ENERGY_2_GAP_CALIBRATIONS_CSV",
2727
"ID_ENERGY_2_PHASE_CALIBRATIONS_CSV",
28-
"EXPECTED_ID_ENERGY_2_GAP_CALIBRATIONS_IDD_PKL",
29-
"EXPECTED_ID_ENERGY_2_GAP_CALIBRATIONS_IDU_PKL",
30-
"EXPECTED_ID_ENERGY_2_PHASE_CALIBRATIONS_IDD_PKL",
31-
"EXPECTED_ID_ENERGY_2_PHASE_CALIBRATIONS_IDU_PKL",
28+
"EXPECTED_ID_ENERGY_2_GAP_CALIBRATIONS_IDD_JSON",
29+
"EXPECTED_ID_ENERGY_2_GAP_CALIBRATIONS_IDU_JSON",
30+
"EXPECTED_ID_ENERGY_2_PHASE_CALIBRATIONS_IDD_JSON",
31+
"EXPECTED_ID_ENERGY_2_PHASE_CALIBRATIONS_IDU_JSON",
3232
]
Lines changed: 314 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,314 @@
1+
{
2+
"lh": {
3+
"energies": {
4+
"249.772": {
5+
"low": 249.772,
6+
"high": 487.644,
7+
"poly": [
8+
5.23532e-08,
9+
-8.56005e-05,
10+
0.0680339,
11+
4.12064
12+
]
13+
},
14+
"487.644": {
15+
"low": 487.644,
16+
"high": 731.037,
17+
"poly": [
18+
1.89432e-08,
19+
-4.20426e-05,
20+
0.0492164,
21+
6.81039
22+
]
23+
},
24+
"731.037": {
25+
"low": 731.037,
26+
"high": 980.599,
27+
"poly": [
28+
3.77061e-09,
29+
-1.05292e-05,
30+
0.027081,
31+
12.0757
32+
]
33+
},
34+
"980.599": {
35+
"low": 980.599,
36+
"high": 1236.31,
37+
"poly": [
38+
1.16963e-08,
39+
-3.24713e-05,
40+
0.0473828,
41+
5.79522
42+
]
43+
},
44+
"1236.31": {
45+
"low": 1236.31,
46+
"high": 1700.0,
47+
"poly": [
48+
4.4545e-08,
49+
-0.000157637,
50+
0.206534,
51+
-61.7239
52+
]
53+
}
54+
},
55+
"limit": {
56+
"minimum": 249.772,
57+
"maximum": 1700.0
58+
}
59+
},
60+
"lv": {
61+
"energies": {
62+
"496.652": {
63+
"low": 496.652,
64+
"high": 689.325,
65+
"poly": [
66+
1.90295e-08,
67+
-3.86443e-05,
68+
0.0400226,
69+
3.53496
70+
]
71+
},
72+
"689.325": {
73+
"low": 689.325,
74+
"high": 886.548,
75+
"poly": [
76+
5.35915e-09,
77+
-1.35913e-05,
78+
0.0247265,
79+
6.65066
80+
]
81+
},
82+
"886.548": {
83+
"low": 886.548,
84+
"high": 1088.57,
85+
"poly": [
86+
1.1181e-08,
87+
-3.06327e-05,
88+
0.0412981,
89+
1.29591
90+
]
91+
},
92+
"1088.57": {
93+
"low": 1088.57,
94+
"high": 1294.24,
95+
"poly": [
96+
1.63633e-08,
97+
-5.01767e-05,
98+
0.0655113,
99+
-8.58906
100+
]
101+
},
102+
"1294.24": {
103+
"low": 1294.24,
104+
"high": 1700.0,
105+
"poly": [
106+
5.10085e-08,
107+
-0.00018901,
108+
0.250993,
109+
-91.2008
110+
]
111+
}
112+
},
113+
"limit": {
114+
"minimum": 496.652,
115+
"maximum": 1700.0
116+
}
117+
},
118+
"pc": {
119+
"energies": {
120+
"385.505": {
121+
"low": 385.505,
122+
"high": 596.042,
123+
"poly": [
124+
2.21358e-08,
125+
-4.29176e-05,
126+
0.0433433,
127+
4.67408
128+
]
129+
},
130+
"596.042": {
131+
"low": 596.042,
132+
"high": 810.876,
133+
"poly": [
134+
7.83367e-09,
135+
-1.97097e-05,
136+
0.0307363,
137+
6.97271
138+
]
139+
},
140+
"810.876": {
141+
"low": 810.876,
142+
"high": 1030.87,
143+
"poly": [
144+
4.5975e-09,
145+
-1.19019e-05,
146+
0.0244055,
147+
8.69789
148+
]
149+
},
150+
"1030.87": {
151+
"low": 1030.87,
152+
"high": 1255.31,
153+
"poly": [
154+
8.21876e-09,
155+
-2.13844e-05,
156+
0.0324129,
157+
6.55313
158+
]
159+
},
160+
"1255.31": {
161+
"low": 1255.31,
162+
"high": 1700.0,
163+
"poly": [
164+
3.57615e-08,
165+
-0.000125734,
166+
0.164373,
167+
-49.1463
168+
]
169+
}
170+
},
171+
"limit": {
172+
"minimum": 385.505,
173+
"maximum": 1700.0
174+
}
175+
},
176+
"nc": {
177+
"energies": {
178+
"394.958": {
179+
"low": 394.958,
180+
"high": 605.487,
181+
"poly": [
182+
2.01446e-08,
183+
-4.02467e-05,
184+
0.0422041,
185+
4.82301
186+
]
187+
},
188+
"605.487": {
189+
"low": 605.487,
190+
"high": 820.328,
191+
"poly": [
192+
7.4329e-09,
193+
-1.87797e-05,
194+
0.0300373,
195+
7.1421
196+
]
197+
},
198+
"820.328": {
199+
"low": 820.328,
200+
"high": 1040.05,
201+
"poly": [
202+
5.55491e-09,
203+
-1.44209e-05,
204+
0.0266286,
205+
8.04047
206+
]
207+
},
208+
"1040.05": {
209+
"low": 1040.05,
210+
"high": 1264.12,
211+
"poly": [
212+
1.46731e-08,
213+
-4.32987e-05,
214+
0.0572147,
215+
-2.79321
216+
]
217+
},
218+
"1264.12": {
219+
"low": 1264.12,
220+
"high": 1700.0,
221+
"poly": [
222+
4.68429e-08,
223+
-0.00017034,
224+
0.22423,
225+
-75.8958
226+
]
227+
}
228+
},
229+
"limit": {
230+
"minimum": 394.958,
231+
"maximum": 1700.0
232+
}
233+
},
234+
"lh3": {
235+
"energies": {
236+
"710.953": {
237+
"low": 710.953,
238+
"high": 951.552,
239+
"poly": [
240+
4.92026e-09,
241+
-1.78548e-05,
242+
0.0304018,
243+
1.71019
244+
]
245+
},
246+
"951.552": {
247+
"low": 951.552,
248+
"high": 1193.71,
249+
"poly": [
250+
2.15916e-09,
251+
-1.00382e-05,
252+
0.0230031,
253+
4.05097
254+
]
255+
},
256+
"1193.71": {
257+
"low": 1193.71,
258+
"high": 1438.26,
259+
"poly": [
260+
1.72396e-10,
261+
-2.70169e-06,
262+
0.013952,
263+
7.78066
264+
]
265+
},
266+
"1438.26": {
267+
"low": 1438.26,
268+
"high": 1684.34,
269+
"poly": [
270+
6.65626e-10,
271+
-4.51536e-06,
272+
0.0161913,
273+
6.84516
274+
]
275+
},
276+
"1684.34": {
277+
"low": 1684.34,
278+
"high": 2100.0,
279+
"poly": [
280+
-7.61825e-09,
281+
3.85587e-05,
282+
-0.0582239,
283+
49.5656
284+
]
285+
}
286+
},
287+
"limit": {
288+
"minimum": 710.953,
289+
"maximum": 2100.0
290+
}
291+
},
292+
"la": {
293+
"energies": {
294+
"610.0": {
295+
"low": 610.0,
296+
"high": 1001.28640795282,
297+
"poly": [
298+
-5.66653297e-18,
299+
3.08703041e-14,
300+
-7.14462774e-11,
301+
9.10074539e-08,
302+
-6.88548924e-05,
303+
0.0309135438,
304+
-7.60298294,
305+
800.865724
306+
]
307+
}
308+
},
309+
"limit": {
310+
"minimum": 610.0,
311+
"maximum": 1001.28640795282
312+
}
313+
}
314+
}
Binary file not shown.

0 commit comments

Comments
 (0)