Skip to content

Commit d7a1f49

Browse files
author
eir17846
committed
add_i09_hu_lut_converter
1 parent c186dc6 commit d7a1f49

File tree

7 files changed

+54
-3
lines changed

7 files changed

+54
-3
lines changed

src/daq_config_server/models/converters/_file_converter_map.py

Lines changed: 2 additions & 1 deletion
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,5 +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
43-
"IIDCalibrationTable.txt": undulator_energy_gap_lut, # noga
44+
"IIDCalibrationTable.txt": i09_hu_undulator_energy_gap_lut, # noga
4445
}

src/daq_config_server/models/converters/convert.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ def get_converted_file_contents(file_path: Path) -> dict[str, Any]:
1414
if converter := file_converter_map.FILE_TO_CONVERTER_MAP.get(str(file_path)):
1515
try:
1616
contents = converter(raw_contents)
17-
raise TypeError(contents)
1817
if isinstance(contents, ConfigModel):
1918
return contents.model_dump()
2019
return contents

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") or line.startswith("ScannableUnits"):
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/constants.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ class TestDataPaths:
3434

3535
TEST_BAD_LUT_PATH = TEST_DATA_DIR_PATH.joinpath("test_bad_lut.txt")
3636

37+
TEST_I09_HU_LUT_PATH = TEST_DATA_DIR_PATH.joinpath("test_i09_hu_lut.txt")
38+
3739
TEST_GOOD_DISPLAY_CONFIG_PATH = TEST_DATA_DIR_PATH.joinpath(
3840
"test_display.configuration"
3941
)
@@ -53,6 +55,7 @@ class ServerFilePaths:
5355
BAD_JSON_FILE = Path("/tests/test_data/test_bad_json")
5456
FILE_IN_GOOD_DIR = Path("/tests/test_data/test_bad_json")
5557
GOOD_LUT = Path("/tests/test_data/test_good_lut.txt")
58+
I09_HU_LUT = Path("/tests/test_data/test_i09_hu_lut.txt")
5659

5760

5861
TEST_CONFIG_PATH = TEST_DATA_DIR_PATH.joinpath("test_config.yaml")
@@ -63,6 +66,7 @@ class ServerFilePaths:
6366
- {TestDataPaths.TEST_BAD_JSON_PATH}
6467
- {TestDataPaths.TEST_BEAMLINE_PARAMETERS_PATH}
6568
- {TestDataPaths.TEST_INVALID_FILE_PATH}
69+
- {TestDataPaths.TEST_I09_HU_LUT_PATH}
6670
6771
whitelist_dirs:
6872
- {TEST_DATA_DIR_PATH.joinpath("good_dir")}

tests/unit_tests/converters/test_lookup_tables_converters.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
beamline_pitch_lut,
77
beamline_roll_lut,
88
detector_xy_lut,
9+
i09_hu_undulator_energy_gap_lut,
910
undulator_energy_gap_lut,
1011
)
1112
from daq_config_server.models.converters.lookup_tables._converters import parse_lut
@@ -113,3 +114,31 @@ def test_undulator_gap_lut_gives_expected_result():
113114
)
114115
result = undulator_energy_gap_lut(input)
115116
assert result == expected
117+
118+
119+
def test_i09_hu_undulator_gap_lut_gives_expected_result():
120+
input = (
121+
"#I09 Hard X-ray ID calibration parameters, created 18 July 2012\n"
122+
"ScannableNames n Ee Br Epmin Epmax Gmin Gmax Goffset\n"
123+
"ScannableUnits ONE GeV T KeV Kev mm mm\n"
124+
"1 3.00089 0.98928 2.12 3.05 14.2650 23.7200 0.0\n"
125+
"2 3.04129 1.02504 2.50 2.80 5.05165 8.88007 0.0\n"
126+
)
127+
expected = GenericLookupTable(
128+
column_names=[
129+
"order",
130+
"ring_energy_gev",
131+
"magnetic_field_t",
132+
"energy_min_eV",
133+
"energy_max_eV",
134+
"gap_min_mm",
135+
"gap_max_mm",
136+
"gap_offset_mm",
137+
],
138+
rows=[
139+
[1, 3.00089, 0.98928, 2.12, 3.05, 14.2650, 23.7200, 0.0],
140+
[2, 3.04129, 1.02504, 2.50, 2.80, 5.05165, 8.88007, 0.0],
141+
],
142+
)
143+
result = i09_hu_undulator_energy_gap_lut(input)
144+
assert result == expected

0 commit comments

Comments
 (0)