diff --git a/pyproject.toml b/pyproject.toml index f22c5df38b..a831d3882f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,12 +43,12 @@ dependencies = [ # These dependencies may be issued as pre-release versions and should have a pin constraint # as by default pip-install will not upgrade to a pre-release. # - "daq-config-server>=v1.0.0-rc.2", + "daq-config-server >= v1.1.2", "blueapi >= 1.8.0", "ophyd >= 1.10.5", "ophyd-async >= 0.14.0", "bluesky >= 1.14.6", - "dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@main", + "dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@mx_bluesky_1494_use_config_server_for_undulator", ] diff --git a/src/mx_bluesky/hyperion/device_setup_plans/dcm_pitch_roll_mirror_adjuster.py b/src/mx_bluesky/hyperion/device_setup_plans/dcm_pitch_roll_mirror_adjuster.py index b2e1c04387..ad2eaf983f 100644 --- a/src/mx_bluesky/hyperion/device_setup_plans/dcm_pitch_roll_mirror_adjuster.py +++ b/src/mx_bluesky/hyperion/device_setup_plans/dcm_pitch_roll_mirror_adjuster.py @@ -1,4 +1,6 @@ import bluesky.plan_stubs as bps +from daq_config_server.client import ConfigServer +from daq_config_server.models import BeamlinePitchLookupTable, BeamlineRollLookupTable from dodal.devices.focusing_mirror import ( FocusingMirrorWithStripes, MirrorStripe, @@ -8,7 +10,6 @@ from dodal.devices.util.adjuster_plans import lookup_table_adjuster from dodal.devices.util.lookup_tables import ( linear_interpolation_lut, - parse_lookup_table, ) from mx_bluesky.common.utils.log import LOGGER @@ -116,12 +117,15 @@ def adjust_dcm_pitch_roll_vfm_from_lut( d_spacing_a: float = yield from bps.rd( undulator_dcm.dcm_ref().crystal_metadata_d_spacing_a ) + config_server = ConfigServer(url="https://daq-config.diamond.ac.uk") + pitch_energy_table = config_server.get_file_contents( + undulator_dcm.pitch_energy_table_path, BeamlinePitchLookupTable + ) + bragg_deg = energy_to_bragg_angle(energy_kev, d_spacing_a) LOGGER.info(f"Target Bragg angle = {bragg_deg} degrees") dcm_pitch_adjuster = lookup_table_adjuster( - linear_interpolation_lut( - *parse_lookup_table(undulator_dcm.pitch_energy_table_path) - ), + linear_interpolation_lut(*pitch_energy_table.columns), dcm.xtal_1.pitch_in_mrad, bragg_deg, ) @@ -130,10 +134,11 @@ def adjust_dcm_pitch_roll_vfm_from_lut( LOGGER.info("Waiting for DCM pitch adjust to complete...") # DCM Roll + roll_energy_table = config_server.get_file_contents( + undulator_dcm.roll_energy_table_path, BeamlineRollLookupTable + ) dcm_roll_adjuster = lookup_table_adjuster( - linear_interpolation_lut( - *parse_lookup_table(undulator_dcm.roll_energy_table_path) - ), + linear_interpolation_lut(*roll_energy_table.columns), dcm.xtal_1.roll_in_mrad, bragg_deg, ) diff --git a/tests/conftest.py b/tests/conftest.py index 3b3c82b0f5..38bf54ec46 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -77,6 +77,7 @@ from ophyd_async.epics.motor import Motor from ophyd_async.fastcs.panda import DatasetTable, PandaHdf5DatasetType from PIL import Image +from pydantic import BaseModel from pydantic.dataclasses import dataclass from scanspec.core import Path as ScanPath from scanspec.specs import Line @@ -1722,7 +1723,7 @@ def _fake_config_server_read( @pytest.fixture(autouse=True) -def mock_config_server(): +def mock_mx_config_server(): # Don't actually talk to central service during unit tests, and reset caches between test for client in IMPLEMENTED_CONFIG_CLIENTS: @@ -1735,6 +1736,34 @@ def mock_config_server(): yield +def _fake_config_server_get_file_contents( + filepath: str | Path, + desired_return_type: type[str] | type[dict] | BaseModel = str, + reset_cached_result=False, +): + filepath = Path(filepath) + # Minimal logic required for unit tests + with filepath.open("r") as f: + contents = f.read() + if desired_return_type is str: + return contents + elif desired_return_type is dict: + return json.loads(contents) + elif issubclass(desired_return_type, BaseModel): # type: ignore + return desired_return_type.model_validate(json.loads(contents)) + + +@pytest.fixture(autouse=True) +def mock_config_server(): + # Don't actually talk to central service during unit tests, and reset caches between test + + with patch( + "daq_config_server.client.ConfigServer.get_file_contents", + side_effect=_fake_config_server_get_file_contents, + ): + yield + + def mock_beamline_module_filepaths(bl_name, bl_module): if mock_attributes := mock_attributes_table.get(bl_name): [bl_module.__setattr__(attr[0], attr[1]) for attr in mock_attributes] diff --git a/tests/test_data/test_daq_configuration/lookup/BeamLineEnergy_DCM_Pitch_converter.txt b/tests/test_data/test_daq_configuration/lookup/BeamLineEnergy_DCM_Pitch_converter.txt index 449e920f73..54d32ddbe2 100644 --- a/tests/test_data/test_daq_configuration/lookup/BeamLineEnergy_DCM_Pitch_converter.txt +++ b/tests/test_data/test_daq_configuration/lookup/BeamLineEnergy_DCM_Pitch_converter.txt @@ -1,25 +1,23 @@ -# Bragg pitch -# Degree values for pitch are interpreted as mrad -# The values cannot change direction. -# last update 2023/06/26 NP -Units Deg mrad -Units Deg Deg -19.24347 -0.79775 -16.40949 -0.78679 -14.31123 -0.77838 -12.69287 -0.77276 -11.40555 -0.77276 -10.35662 -0.77031 -9.48522 -0.76693 -8.95826 -0.76387 -8.74953 -0.76387 -8.12020 -0.76387 -7.57556 -0.76354 -7.09950 -0.76166 -6.67997 -0.76044 -6.30732 -0.75953 -5.97411 -0.75845 -5.67434 -0.75796 -5.40329 -0.75789 -5.15700 -0.75551 -4.93218 -0.75513 +{ + "rows": [ + [19.24347, -0.79775], + [16.40949, -0.78679], + [14.31123, -0.77838], + [12.69287, -0.77276], + [11.40555, -0.77276], + [10.35662, -0.77031], + [9.48522, -0.76693], + [8.95826, -0.76387], + [8.74953, -0.76387], + [8.1202, -0.76387], + [7.57556, -0.76354], + [7.0995, -0.76166], + [6.67997, -0.76044], + [6.30732, -0.75953], + [5.97411, -0.75845], + [5.67434, -0.75796], + [5.40329, -0.75789], + [5.157, -0.75551], + [4.93218, -0.75513] + ] +} diff --git a/tests/test_data/test_daq_configuration/lookup/BeamLineEnergy_DCM_Roll_converter.txt b/tests/test_data/test_daq_configuration/lookup/BeamLineEnergy_DCM_Roll_converter.txt index 9b5b52dcb7..7f2a6fc2f9 100644 --- a/tests/test_data/test_daq_configuration/lookup/BeamLineEnergy_DCM_Roll_converter.txt +++ b/tests/test_data/test_daq_configuration/lookup/BeamLineEnergy_DCM_Roll_converter.txt @@ -1,6 +1,6 @@ -#Bragg angle against roll( absolute number) -#reloadLookupTables() -# last update 2023/01/19 NP -Units Deg mrad -26.4095 -0.2799 -6.3075 -0.2799 +{ + "rows": [ + [26.4095, -0.2799], + [6.3075, -0.2799] + ] +} diff --git a/tests/test_data/test_daq_configuration/lookup/BeamLine_Undulator_toGap.txt b/tests/test_data/test_daq_configuration/lookup/BeamLine_Undulator_toGap.txt index 4dfe25c74e..bb101e0696 100755 --- a/tests/test_data/test_daq_configuration/lookup/BeamLine_Undulator_toGap.txt +++ b/tests/test_data/test_daq_configuration/lookup/BeamLine_Undulator_toGap.txt @@ -1,60 +1,54 @@ -####################### -# # -# 5.5mm CPMU 20/11/22 # -# # -####################### -# Used to convert from energy to gap. Constructed from tables for 3rd, 5th and 7th harmonic. -# It is important that at the point of change from one harmonic to another that there is -# point for the same energy from both harmomics to prevent invalid interpolation. -# run reloadLookupTables() when done -Units eV mm -5700 5.4606 -5760 5.5 -6000 5.681 -6500 6.045 -7000 6.404 -7500 6.765 -8000 7.124 -8500 7.491 -9000 7.872 -9500 8.258 -9700 8.424 -9700 5.542 -10000 5.675 -10500 5.895 -11000 6.113 -11500 6.328 -12000 6.545 -12500 6.758 -12700 6.83 -13000 6.98 -13443 7.168 -13443 5.5 -13500 5.517 -14000 5.674 -14500 5.831 -15000 5.987 -15500 6.139 -16000 6.294 -16500 6.447 -17000 6.603 -17320 6.697 -17320 5.5 -17500 5.552 -18000 5.674 -18500 5.794 -19000 5.912 -19500 6.037 -20000 6.157 -20500 6.277 -20939 6.378 -20939 5.5 -21000 5.517 -21500 5.577 -22000 5.674 -22500 5.773 -23000 5.871 -23500 5.97 -24000 6.072 -24500 6.167 -25000 6.264 +{ + "rows": [ + [5700, 5.4606], + [5760, 5.5], + [6000, 5.681], + [6500, 6.045], + [7000, 6.404], + [7500, 6.765], + [8000, 7.124], + [8500, 7.491], + [9000, 7.872], + [9500, 8.258], + [9700, 8.424], + [9700, 5.542], + [10000, 5.675], + [10500, 5.895], + [11000, 6.113], + [11500, 6.328], + [12000, 6.545], + [12500, 6.758], + [12700, 6.83], + [13000, 6.98], + [13443, 7.168], + [13443, 5.5], + [13500, 5.517], + [14000, 5.674], + [14500, 5.831], + [15000, 5.987], + [15500, 6.139], + [16000, 6.294], + [16500, 6.447], + [17000, 6.603], + [17320, 6.697], + [17320, 5.5], + [17500, 5.552], + [18000, 5.674], + [18500, 5.794], + [19000, 5.912], + [19500, 6.037], + [20000, 6.157], + [20500, 6.277], + [20939, 6.378], + [20939, 5.5], + [21000, 5.517], + [21500, 5.577], + [22000, 5.674], + [22500, 5.773], + [23000, 5.871], + [23500, 5.97], + [24000, 6.072], + [24500, 6.167], + [25000, 6.264] + ] +}