Skip to content

Commit 7b3764d

Browse files
Villtordeir17846
andauthored
Add i09-1 converter (#145)
* first * add_i09_hu_lut_converter * remove unnecessary i09_hu_lut.txt * reply review * units to lowercase --------- Co-authored-by: eir17846 <[email protected]>
1 parent 635235f commit 7b3764d

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

src/daq_config_server/models/converters/_file_converter_map.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
beamline_pitch_lut,
1414
beamline_roll_lut,
1515
detector_xy_lut,
16+
i09_hu_undulator_energy_gap_lut,
1617
undulator_energy_gap_lut,
1718
)
1819

@@ -40,4 +41,5 @@
4041
"/dls_sw/i03/software/daq_configuration/lookup/BeamLineEnergy_DCM_Pitch_converter.txt": beamline_pitch_lut, # noqa
4142
"/dls_sw/i03/software/daq_configuration/lookup/BeamLineEnergy_DCM_Roll_converter.txt": beamline_roll_lut, # noqa
4243
"/dls_sw/i03/software/daq_configuration/lookup/BeamLine_Undulator_toGap.txt": undulator_energy_gap_lut, # noqa
44+
"/dls_sw/i09-1/software/gda/workspace_git/gda-diamond.git/configurations/i09-1-shared/lookupTables/IIDCalibrationTable.txt": i09_hu_undulator_energy_gap_lut, # noqa: E501
4345
}

src/daq_config_server/models/converters/lookup_tables/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
beamline_pitch_lut,
33
beamline_roll_lut,
44
detector_xy_lut,
5+
i09_hu_undulator_energy_gap_lut,
56
undulator_energy_gap_lut,
67
)
78
from ._models import GenericLookupTable
@@ -12,4 +13,5 @@
1213
"beamline_pitch_lut",
1314
"beamline_roll_lut",
1415
"undulator_energy_gap_lut",
16+
"i09_hu_undulator_energy_gap_lut",
1517
]

src/daq_config_server/models/converters/lookup_tables/_converters.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
from ._models import GenericLookupTable
66

7+
IGNORE_LINES_STARTING_WITH = ("Units", "ScannableUnits", "ScannableNames")
8+
79

810
def parse_lut(contents: str, *params: tuple[str, type | None]) -> GenericLookupTable:
911
"""Converts a lookup table to a pydantic model, containing the names of each column
@@ -18,7 +20,7 @@ def parse_lut(contents: str, *params: tuple[str, type | None]) -> GenericLookupT
1820
column_names = [param[0] for param in params]
1921
types = [param[1] for param in params]
2022
for line in remove_comments(contents.splitlines()):
21-
if line.startswith("Units"):
23+
if line.startswith(IGNORE_LINES_STARTING_WITH):
2224
continue
2325
rows.append(
2426
[parse_value(value, types[i]) for i, value in enumerate(line.split())]
@@ -45,3 +47,17 @@ def beamline_roll_lut(contents: str) -> GenericLookupTable:
4547

4648
def undulator_energy_gap_lut(contents: str) -> GenericLookupTable:
4749
return parse_lut(contents, ("energy_eV", int), ("gap_mm", float))
50+
51+
52+
def i09_hu_undulator_energy_gap_lut(contents: str) -> GenericLookupTable:
53+
return parse_lut(
54+
contents,
55+
("order", int),
56+
("ring_energy_gev", float),
57+
("magnetic_field_t", float),
58+
("energy_min_ev", float),
59+
("energy_max_ev", float),
60+
("gap_min_mm", float),
61+
("gap_max_mm", float),
62+
("gap_offset_mm", float),
63+
)

tests/unit_tests/converters/test_lookup_tables_converters.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
beamline_pitch_lut,
99
beamline_roll_lut,
1010
detector_xy_lut,
11+
i09_hu_undulator_energy_gap_lut,
1112
undulator_energy_gap_lut,
1213
)
1314
from daq_config_server.models.converters.lookup_tables._converters import parse_lut
@@ -117,6 +118,34 @@ def test_undulator_gap_lut_gives_expected_result():
117118
assert result == expected
118119

119120

121+
def test_i09_hu_undulator_gap_lut_gives_expected_result():
122+
input = (
123+
"#I09 Hard X-ray ID calibration parameters, created 18 July 2012\n"
124+
"ScannableNames n Ee Br Epmin Epmax Gmin Gmax Goffset\n"
125+
"ScannableUnits ONE GeV T KeV Kev mm mm\n"
126+
"1 3.00089 0.98928 2.12 3.05 14.2650 23.7200 0.0\n"
127+
"2 3.04129 1.02504 2.50 2.80 5.05165 8.88007 0.0\n"
128+
)
129+
expected = GenericLookupTable(
130+
column_names=[
131+
"order",
132+
"ring_energy_gev",
133+
"magnetic_field_t",
134+
"energy_min_ev",
135+
"energy_max_ev",
136+
"gap_min_mm",
137+
"gap_max_mm",
138+
"gap_offset_mm",
139+
],
140+
rows=[
141+
[1, 3.00089, 0.98928, 2.12, 3.05, 14.2650, 23.7200, 0.0],
142+
[2, 3.04129, 1.02504, 2.50, 2.80, 5.05165, 8.88007, 0.0],
143+
],
144+
)
145+
result = i09_hu_undulator_energy_gap_lut(input)
146+
assert result == expected
147+
148+
120149
@pytest.mark.parametrize(
121150
"args, expected_value",
122151
[

0 commit comments

Comments
 (0)