diff --git a/src/dodal/beamlines/aithre.py b/src/dodal/beamlines/aithre.py index d3ce9ec5c6e..8770a0cfaf3 100644 --- a/src/dodal/beamlines/aithre.py +++ b/src/dodal/beamlines/aithre.py @@ -1,3 +1,7 @@ +from functools import cache + +from daq_config_server import ConfigClient + from dodal.device_manager import DeviceManager from dodal.devices.aithre_lasershaping.goniometer import Goniometer from dodal.devices.aithre_lasershaping.laser_robot import LaserRobot @@ -14,6 +18,12 @@ devices = DeviceManager() +@devices.fixture +@cache +def config_client() -> ConfigClient: + return ConfigClient() + + @devices.factory() def goniometer() -> Goniometer: return Goniometer( @@ -31,12 +41,16 @@ def robot() -> LaserRobot: @devices.factory() -def oav(params: OAVConfigBeamCentre | None = None) -> OAVBeamCentreFile: +def oav( + config_client: ConfigClient, params: OAVConfigBeamCentre | None = None +) -> OAVBeamCentreFile: config = ( params if params is not None else OAVConfigBeamCentre( - zoom_params_file=ZOOM_PARAMS_FILE, display_config_file=DISPLAY_CONFIG + zoom_params_file=ZOOM_PARAMS_FILE, + display_config_file=DISPLAY_CONFIG, + config_client=config_client, ) ) return OAVBeamCentreFile( diff --git a/src/dodal/beamlines/i03.py b/src/dodal/beamlines/i03.py index 79631b15b2e..41a6b678de0 100644 --- a/src/dodal/beamlines/i03.py +++ b/src/dodal/beamlines/i03.py @@ -205,11 +205,13 @@ def panda_fast_grid_scan() -> PandAFastGridScan: @devices.factory() def oav( + config_client: ConfigClient, params: OAVConfigBeamCentre | None = None, ) -> OAVBeamCentreFile: return OAVBeamCentreFile( prefix=f"{PREFIX.beamline_prefix}-DI-OAV-01:", - config=params or OAVConfigBeamCentre(ZOOM_PARAMS_FILE, DISPLAY_CONFIG), + config=params + or OAVConfigBeamCentre(ZOOM_PARAMS_FILE, DISPLAY_CONFIG, config_client), ) diff --git a/src/dodal/beamlines/i04.py b/src/dodal/beamlines/i04.py index abf8384c9b0..b2f57c086a1 100644 --- a/src/dodal/beamlines/i04.py +++ b/src/dodal/beamlines/i04.py @@ -216,18 +216,22 @@ def zebra() -> Zebra: @devices.factory() -def oav(params: OAVConfig | None = None) -> OAVBeamCentrePV: +def oav( + config_client: ConfigClient, params: OAVConfig | None = None +) -> OAVBeamCentrePV: return OAVBeamCentrePV( prefix=f"{PREFIX.beamline_prefix}-DI-OAV-01:", - config=params or OAVConfig(ZOOM_PARAMS_FILE), + config=params or OAVConfig(ZOOM_PARAMS_FILE, config_client), ) @devices.factory() -def oav_full_screen(params: OAVConfig | None = None) -> OAVBeamCentrePV: +def oav_full_screen( + config_client: ConfigClient, params: OAVConfig | None = None +) -> OAVBeamCentrePV: return OAVBeamCentrePV( prefix=f"{PREFIX.beamline_prefix}-DI-OAV-01:", - config=params or OAVConfig(ZOOM_PARAMS_FILE), + config=params or OAVConfig(ZOOM_PARAMS_FILE, config_client), overlay_channel=3, mjpeg_prefix="XTAL", ) diff --git a/src/dodal/beamlines/i19_1.py b/src/dodal/beamlines/i19_1.py index 3e8ef966622..883bc6cacf5 100644 --- a/src/dodal/beamlines/i19_1.py +++ b/src/dodal/beamlines/i19_1.py @@ -1,3 +1,7 @@ +from functools import cache + +from daq_config_server import ConfigClient + from dodal.common.beamlines.beamline_utils import ( set_beamline as set_utils_beamline, ) @@ -48,6 +52,12 @@ devices = DeviceManager() +@devices.fixture +@cache +def config_client() -> ConfigClient: + return ConfigClient() + + @devices.factory() def attenuator_motor_squad() -> AttenuatorMotorSquad: return AttenuatorMotorSquad( @@ -62,7 +72,7 @@ def beamstop() -> BeamStop: @devices.fixture def oav_config() -> OAVConfigBeamCentre: - return OAVConfigBeamCentre(ZOOM_PARAMS_FILE, DISPLAY_CONFIG) + return OAVConfigBeamCentre(ZOOM_PARAMS_FILE, DISPLAY_CONFIG, config_client()) @devices.factory() diff --git a/src/dodal/beamlines/i24.py b/src/dodal/beamlines/i24.py index fdfb219727a..92d7bb2dd1b 100644 --- a/src/dodal/beamlines/i24.py +++ b/src/dodal/beamlines/i24.py @@ -68,6 +68,12 @@ def path_provider() -> PathProvider: ) +@devices.fixture +@cache +def config_client() -> ConfigClient: + return ConfigClient() + + @devices.factory() def attenuator() -> EnumFilterAttenuator: return EnumFilterAttenuator( @@ -110,10 +116,10 @@ def pmac() -> PMAC: @devices.factory() -def oav() -> OAVBeamCentreFile: +def oav(config_client) -> OAVBeamCentreFile: return OAVBeamCentreFile( prefix=f"{PREFIX.beamline_prefix}-DI-OAV-01:", - config=OAVConfigBeamCentre(ZOOM_PARAMS_FILE, DISPLAY_CONFIG), + config=OAVConfigBeamCentre(ZOOM_PARAMS_FILE, DISPLAY_CONFIG, config_client), ) diff --git a/src/dodal/devices/oav/oav_parameters.py b/src/dodal/devices/oav/oav_parameters.py index 7b2925398a9..403d23cf599 100644 --- a/src/dodal/devices/oav/oav_parameters.py +++ b/src/dodal/devices/oav/oav_parameters.py @@ -1,11 +1,12 @@ -import json from abc import abstractmethod from collections import ChainMap from dataclasses import dataclass from typing import Any, Generic, TypeVar -from xml.etree import ElementTree from xml.etree.ElementTree import Element +from daq_config_server import ConfigClient +from daq_config_server.models import DisplayConfig + # GDA currently assumes this aspect ratio for the OAV window size. # For some beamline this doesn't affect anything as the actual OAV aspect ratio # matches. Others need to take it into account to rescale the values stored in @@ -34,20 +35,24 @@ def __init__( ): self.oav_config_json: str = oav_config_json self.context = context + config_server = ConfigClient(url="https://daq-config.diamond.ac.uk") - self.global_params, self.context_dicts = self.load_json(self.oav_config_json) + self.global_params, self.context_dicts = self.load_json( + config_server, self.oav_config_json + ) self.active_params: ChainMap = ChainMap( self.context_dicts[self.context], self.global_params ) self.update_self_from_current_context() @staticmethod - def load_json(filename: str) -> tuple[dict[str, Any], dict[str, dict]]: - """Loads the json from the specified file, and returns a dict with all the + def load_json( + config_server: ConfigClient, filename: str + ) -> tuple[dict[str, Any], dict[str, dict]]: + """Loads the specified file from the config server, and returns a dict with all the individual top-level k-v pairs, and one with all the subdicts. """ - with open(filename) as f: - raw_params: dict[str, Any] = json.load(f) + raw_params: dict[str, Any] = config_server.get_file_contents(filename, dict) global_params = { k: raw_params.pop(k) for k, v in list(raw_params.items()) @@ -116,21 +121,20 @@ class ZoomParamsCrosshair(ZoomParams): class OAVConfigBase(Generic[ParamType]): - def __init__(self, zoom_params_file: str): - self.zoom_params = self._get_zoom_params(zoom_params_file) - - def _get_zoom_params(self, zoom_params_file: str): - tree = ElementTree.parse(zoom_params_file) - root = tree.getroot() - return root.findall(".//zoomLevel") + def __init__(self, zoom_params_file: str, config_client: ConfigClient): + self.zoom_params = config_client.get_file_contents(zoom_params_file, dict)[ + "JCameraManSettings" + ] def _read_zoom_params(self) -> dict: um_per_pix = {} - for node in self.zoom_params: - zoom = str(_get_element_as_float(node, "level")) - um_pix_x = _get_element_as_float(node, "micronsPerXPixel") - um_pix_y = _get_element_as_float(node, "micronsPerYPixel") - um_per_pix[zoom] = (um_pix_x, um_pix_y) + zoom_levels: list[dict] = self.zoom_params["levels"]["zoomLevel"] + for level in zoom_levels: + zoom = level["level"] + um_per_pix[zoom] = ( + float(level["micronsPerXPixel"]), + float(level["micronsPerYPixel"]), + ) return um_per_pix @abstractmethod @@ -157,23 +161,17 @@ def __init__( self, zoom_params_file: str, display_config_file: str, + config_client: ConfigClient, ): - self.display_config = self._get_display_config(display_config_file) - super().__init__(zoom_params_file) - - def _get_display_config(self, display_config_file: str): - with open(display_config_file) as f: - file_lines = f.readlines() - return file_lines + self.display_config = config_client.get_file_contents( + display_config_file, DisplayConfig + ) + super().__init__(zoom_params_file, config_client) def _read_display_config(self) -> dict: crosshairs = {} - for i in range(len(self.display_config)): - if self.display_config[i].startswith("zoomLevel"): - zoom = self.display_config[i].split(" = ")[1].strip() - x = int(self.display_config[i + 1].split(" = ")[1]) - y = int(self.display_config[i + 2].split(" = ")[1]) - crosshairs[zoom] = (x, y) + for zoom, values in self.display_config.zoom_levels.items(): + crosshairs[str(zoom)] = (values.crosshair_x, values.crosshair_y) return crosshairs def get_parameters(self) -> dict[str, ZoomParamsCrosshair]: diff --git a/system_tests/conftest.py b/system_tests/conftest.py index d3df62cbd5d..06fee26e905 100644 --- a/system_tests/conftest.py +++ b/system_tests/conftest.py @@ -1,2 +1,5 @@ # Add run_engine to be used in tests -pytest_plugins = ["dodal.testing.fixtures.run_engine"] +pytest_plugins = [ + "dodal.testing.fixtures.run_engine", + "dodal.testing.fixtures.config_server", +] diff --git a/system_tests/test_oav_system.py b/system_tests/test_oav_system.py index bfecb9622b3..30f04a2fc0a 100644 --- a/system_tests/test_oav_system.py +++ b/system_tests/test_oav_system.py @@ -1,11 +1,9 @@ import bluesky.plan_stubs as bps import pytest from bluesky.run_engine import RunEngine +from daq_config_server import ConfigClient from ophyd_async.core import init_devices -from tests.test_data import ( - TEST_DISPLAY_CONFIG, - TEST_OAV_ZOOM_LEVELS_XML, -) +from tests.devices.oav.test_data import TEST_OAV_ZOOM_LEVELS from dodal.devices.oav.oav_detector import OAV, OAVConfig @@ -18,7 +16,7 @@ @pytest.fixture async def oav() -> OAV: - oav_config = OAVConfig(TEST_OAV_ZOOM_LEVELS_XML, TEST_DISPLAY_CONFIG) + oav_config = OAVConfig(TEST_OAV_ZOOM_LEVELS, ConfigClient("")) async with init_devices(connect=True): oav = OAV("", config=oav_config, name="oav") return oav @@ -39,7 +37,7 @@ def take_snapshot_with_grid(oav: OAV, snapshot_filename, snapshot_directory): @pytest.mark.skip(reason="Don't want to actually take snapshots during testing.") def test_grid_overlay(run_engine: RunEngine): beamline = "BL03I" - oav_params = OAVConfig(TEST_OAV_ZOOM_LEVELS_XML, TEST_DISPLAY_CONFIG) + oav_params = OAVConfig(TEST_OAV_ZOOM_LEVELS, ConfigClient("")) oav = OAV(name="oav", prefix=f"{beamline}", config=oav_params) snapshot_filename = "snapshot" snapshot_directory = "." diff --git a/tests/conftest.py b/tests/conftest.py index f9b8a0116ab..90f1e44bcf6 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -30,17 +30,16 @@ make_all_devices, ) from tests.devices.beamlines.i10.test_data import LOOKUP_TABLE_PATH +from tests.devices.oav.test_data import TEST_DISPLAY_CONFIG, TEST_OAV_ZOOM_LEVELS from tests.devices.test_daq_configuration import MOCK_DAQ_CONFIG_PATH from tests.devices.test_data import TEST_LUT_TXT from tests.test_data import ( I04_BEAMLINE_PARAMETERS, - TEST_DISPLAY_CONFIG, - TEST_OAV_ZOOM_LEVELS_XML, ) MOCK_PATHS = [ ("DAQ_CONFIGURATION_PATH", MOCK_DAQ_CONFIG_PATH), - ("ZOOM_PARAMS_FILE", TEST_OAV_ZOOM_LEVELS_XML), + ("ZOOM_PARAMS_FILE", TEST_OAV_ZOOM_LEVELS), ("DISPLAY_CONFIG", TEST_DISPLAY_CONFIG), ("LOOK_UPTABLE_DIR", LOOKUP_TABLE_PATH), ] diff --git a/tests/devices/beamlines/i03/conftest.py b/tests/devices/beamlines/i03/conftest.py index e69de29bb2d..c116593b798 100644 --- a/tests/devices/beamlines/i03/conftest.py +++ b/tests/devices/beamlines/i03/conftest.py @@ -0,0 +1,6 @@ +import pytest + + +@pytest.fixture(autouse=True) +def use_beamline_i03(monkeypatch): + monkeypatch.setenv("BEAMLINE", "i03") diff --git a/tests/devices/oav/conftest.py b/tests/devices/oav/conftest.py index 579d6578ff5..8da3a5512f5 100644 --- a/tests/devices/oav/conftest.py +++ b/tests/devices/oav/conftest.py @@ -1,16 +1,19 @@ from unittest.mock import AsyncMock import pytest +from daq_config_server import ConfigClient from ophyd_async.core import init_devices, set_mock_value from dodal.devices.oav.oav_detector import OAVBeamCentreFile, OAVBeamCentrePV from dodal.devices.oav.oav_parameters import OAVConfig, OAVConfigBeamCentre -from tests.test_data import TEST_DISPLAY_CONFIG, TEST_OAV_ZOOM_LEVELS_XML +from tests.devices.oav.test_data import TEST_DISPLAY_CONFIG, TEST_OAV_ZOOM_LEVELS @pytest.fixture async def oav() -> OAVBeamCentreFile: - oav_config = OAVConfigBeamCentre(TEST_OAV_ZOOM_LEVELS_XML, TEST_DISPLAY_CONFIG) + oav_config = OAVConfigBeamCentre( + TEST_OAV_ZOOM_LEVELS, TEST_DISPLAY_CONFIG, ConfigClient("") + ) async with init_devices(mock=True, connect=True): oav = OAVBeamCentreFile("", config=oav_config, name="oav") zoom_levels_list = ["1.0x", "3.0x", "5.0x", "7.5x", "10.0x"] @@ -25,7 +28,7 @@ async def oav() -> OAVBeamCentreFile: @pytest.fixture async def oav_beam_centre_pv_roi() -> OAVBeamCentrePV: - oav_config = OAVConfig(TEST_OAV_ZOOM_LEVELS_XML) + oav_config = OAVConfig(TEST_OAV_ZOOM_LEVELS, ConfigClient("")) async with init_devices(mock=True, connect=True): oav = OAVBeamCentrePV("", config=oav_config, name="oav") zoom_levels_list = ["1.0x", "3.0x", "5.0x", "7.5x", "10.0x"] @@ -40,7 +43,7 @@ async def oav_beam_centre_pv_roi() -> OAVBeamCentrePV: @pytest.fixture async def oav_beam_centre_pv_fs() -> OAVBeamCentrePV: - oav_config = OAVConfig(TEST_OAV_ZOOM_LEVELS_XML) + oav_config = OAVConfig(TEST_OAV_ZOOM_LEVELS, ConfigClient("")) async with init_devices(mock=True, connect=True): oav = OAVBeamCentrePV( "", config=oav_config, name="oav", mjpeg_prefix="XTAL", overlay_channel=3 diff --git a/tests/devices/oav/test_data/__init__.py b/tests/devices/oav/test_data/__init__.py index 204c5af0f2e..71b9722652c 100644 --- a/tests/devices/oav/test_data/__init__.py +++ b/tests/devices/oav/test_data/__init__.py @@ -3,11 +3,15 @@ TEST_DATA_PATH = Path(__file__).parent TEST_OAV_CENTRING_JSON = join(TEST_DATA_PATH, "test_OAVCentring.json") +TEST_DISPLAY_CONFIG = join(TEST_DATA_PATH, "test_display.configuration") +TEST_OAV_ZOOM_LEVELS = join(TEST_DATA_PATH, "jCameraManZoomLevels.json") OAV_SNAPSHOT_TEST_PNG = join(TEST_DATA_PATH, "oav_snapshot_test.png") OAV_SNAPSHOT_EXPECTED_PNG = join(TEST_DATA_PATH, "oav_snapshot_expected.png") __all__ = [ + "TEST_OAV_CENTRING_JSON", + "TEST_DISPLAY_CONFIG", + "TEST_OAV_ZOOM_LEVELS", "OAV_SNAPSHOT_EXPECTED_PNG", "OAV_SNAPSHOT_TEST_PNG", - "TEST_OAV_CENTRING_JSON", ] diff --git a/tests/devices/oav/test_data/jCameraManZoomLevels.json b/tests/devices/oav/test_data/jCameraManZoomLevels.json new file mode 100644 index 00000000000..843414a3b86 --- /dev/null +++ b/tests/devices/oav/test_data/jCameraManZoomLevels.json @@ -0,0 +1,45 @@ +{ + "JCameraManSettings": { + "levels": { + "zoomLevel": [ + { + "level": "1.0", + "position": "0", + "micronsPerXPixel": "2.87", + "micronsPerYPixel": "2.87" + }, + { + "level": "2.5", + "position": "10", + "micronsPerXPixel": "2.31", + "micronsPerYPixel": "2.31" + }, + { + "level": "5.0", + "position": "25", + "micronsPerXPixel": "1.58", + "micronsPerYPixel": "1.58" + }, + { + "level": "7.5", + "position": "50", + "micronsPerXPixel": "0.806", + "micronsPerYPixel": "0.806" + }, + { + "level": "10.0", + "position": "75", + "micronsPerXPixel": "0.438", + "micronsPerYPixel": "0.438" + }, + { + "level": "15.0", + "position": "90", + "micronsPerXPixel": "0.302", + "micronsPerYPixel": "0.302" + } + ] + }, + "tolerance": "1.0" + } +} diff --git a/tests/devices/oav/test_data/test_OAVCentring.json b/tests/devices/oav/test_data/test_OAVCentring.json index d4002b0eff1..fa6b5aa7ff4 100644 --- a/tests/devices/oav/test_data/test_OAVCentring.json +++ b/tests/devices/oav/test_data/test_OAVCentring.json @@ -1,70 +1,70 @@ { - "exposure": 0.075, - "acqPeriod": 0.05, - "gain": 1.0, - "minheight": 70, - "oav": "OAV", - "mxsc_input": "CAM", - "min_callback_time": 0.080, - "close_ksize": 11, - "direction": 0, - "pinTipCentring": { - "zoom": 1.0, - "preprocess": 8, - "preProcessKSize": 21, - "CannyEdgeUpperThreshold": 20.0, - "CannyEdgeLowerThreshold": 5.0, - "brightness": 20, - "max_tip_distance": 300, - "mxsc_input": "proc", - "minheight": 10, - "min_callback_time": 0.15, - "filename": "/dls_sw/prod/R3.14.12.7/support/adPython/2-1-11/adPythonApp/scripts/adPythonMxSampleDetect.py" - }, - "loopCentring": { - "zoom": 5.0, - "preprocess": 8, - "preProcessKSize": 21, - "CannyEdgeUpperThreshold": 20.0, - "CannyEdgeLowerThreshold": 5.0, - "brightness": 20, - "filename": "/dls_sw/prod/R3.14.12.7/support/adPython/2-1-11/adPythonApp/scripts/adPythonMxSampleDetect.py", - "max_tip_distance": 300, - "minheight": 10 - }, - "xrayCentring": { - "zoom": 7.5, - "preprocess": 8, - "preProcessKSize": 31, - "CannyEdgeUpperThreshold": 30.0, - "CannyEdgeLowerThreshold": 5.0, - "close_ksize": 3, - "filename": "/dls_sw/prod/R3.14.12.7/support/adPython/2-1-11/adPythonApp/scripts/adPythonMxSampleDetect.py", - "brightness": 80 - }, - "rotationAxisAlign": { - "zoom": 10.0, - "preprocess": 8, - "preProcessKSize": 21, - "CannyEdgeUpperThreshold": 20.0, - "CannyEdgeLowerThreshold": 5.0, - "filename": "/dls_sw/prod/R3.14.12.7/support/adPython/2-1-11/adPythonApp/scripts/adPythonMxSampleDetect.py", - "brightness": 100 - }, - "SmargonOffsets1": { - "zoom": 1.0, - "preprocess": 8, - "preProcessKSize": 21, - "CannyEdgeUpperThreshold": 50.0, - "CannyEdgeLowerThreshold": 5.0, - "brightness": 80 - }, - "SmargonOffsets2": { - "zoom": 5.0, - "preprocess": 8, - "preProcessKSize": 11, - "CannyEdgeUpperThreshold": 50.0, - "CannyEdgeLowerThreshold": 5.0, - "brightness": 90 - } + "exposure": 0.075, + "acqPeriod": 0.05, + "gain": 1.0, + "minheight": 70, + "oav": "OAV", + "mxsc_input": "CAM", + "min_callback_time": 0.080, + "close_ksize": 11, + "direction": 0, + "pinTipCentring": { + "zoom": 1.0, + "preprocess": 8, + "preProcessKSize": 21, + "CannyEdgeUpperThreshold": 20.0, + "CannyEdgeLowerThreshold": 5.0, + "brightness": 20, + "max_tip_distance": 300, + "mxsc_input": "proc", + "minheight": 10, + "min_callback_time": 0.15, + "filename": "/dls_sw/prod/R3.14.12.7/support/adPython/2-1-11/adPythonApp/scripts/adPythonMxSampleDetect.py" + }, + "loopCentring": { + "zoom": 5.0, + "preprocess": 8, + "preProcessKSize": 21, + "CannyEdgeUpperThreshold": 20.0, + "CannyEdgeLowerThreshold": 5.0, + "brightness": 20, + "filename": "/dls_sw/prod/R3.14.12.7/support/adPython/2-1-11/adPythonApp/scripts/adPythonMxSampleDetect.py", + "max_tip_distance": 300, + "minheight": 10 + }, + "xrayCentring": { + "zoom": 7.5, + "preprocess": 8, + "preProcessKSize": 31, + "CannyEdgeUpperThreshold": 30.0, + "CannyEdgeLowerThreshold": 5.0, + "close_ksize": 3, + "filename": "/dls_sw/prod/R3.14.12.7/support/adPython/2-1-11/adPythonApp/scripts/adPythonMxSampleDetect.py", + "brightness": 80 + }, + "rotationAxisAlign": { + "zoom": 10.0, + "preprocess": 8, + "preProcessKSize": 21, + "CannyEdgeUpperThreshold": 20.0, + "CannyEdgeLowerThreshold": 5.0, + "filename": "/dls_sw/prod/R3.14.12.7/support/adPython/2-1-11/adPythonApp/scripts/adPythonMxSampleDetect.py", + "brightness": 100 + }, + "SmargonOffsets1": { + "zoom": 1.0, + "preprocess": 8, + "preProcessKSize": 21, + "CannyEdgeUpperThreshold": 50.0, + "CannyEdgeLowerThreshold": 5.0, + "brightness": 80 + }, + "SmargonOffsets2": { + "zoom": 5.0, + "preprocess": 8, + "preProcessKSize": 11, + "CannyEdgeUpperThreshold": 50.0, + "CannyEdgeLowerThreshold": 5.0, + "brightness": 90 + } } diff --git a/tests/devices/oav/test_data/test_display.configuration b/tests/devices/oav/test_data/test_display.configuration new file mode 100644 index 00000000000..d7d65ae4e65 --- /dev/null +++ b/tests/devices/oav/test_data/test_display.configuration @@ -0,0 +1,52 @@ +{ + "zoom_levels": { + "1.0": { + "crosshair_x": 477, + "crosshair_y": 359, + "top_left_x": 383, + "top_left_y": 253, + "bottom_right_x": 410, + "bottom_right_y": 278 + }, + "2.5": { + "crosshair_x": 493, + "crosshair_y": 355, + "top_left_x": 340, + "top_left_y": 283, + "bottom_right_x": 388, + "bottom_right_y": 322 + }, + "5.0": { + "crosshair_x": 517, + "crosshair_y": 350, + "top_left_x": 268, + "top_left_y": 326, + "bottom_right_x": 354, + "bottom_right_y": 387 + }, + "7.5": { + "crosshair_x": 549, + "crosshair_y": 437, + "top_left_x": 248, + "top_left_y": 394, + "bottom_right_x": 377, + "bottom_right_y": 507 + }, + "10.0": { + "crosshair_x": 613, + "crosshair_y": 344, + "top_left_x": 2, + "top_left_y": 489, + "bottom_right_x": 206, + "bottom_right_y": 630 + }, + "15.0": { + "crosshair_x": 693, + "crosshair_y": 339, + "top_left_x": 1, + "top_left_y": 601, + "bottom_right_x": 65, + "bottom_right_y": 767 + } + } +} diff --git a/tests/devices/oav/test_oav.py b/tests/devices/oav/test_oav.py index 93e340cd645..5c4987e2c63 100644 --- a/tests/devices/oav/test_oav.py +++ b/tests/devices/oav/test_oav.py @@ -1,6 +1,7 @@ from unittest.mock import AsyncMock, patch import pytest +from daq_config_server import ConfigClient from ophyd_async.core import init_devices, set_mock_value from dodal.devices.oav.oav_detector import ( @@ -12,10 +13,7 @@ OAVConfigBeamCentre, ZoomController, ) -from tests.test_data import ( - TEST_DISPLAY_CONFIG, - TEST_OAV_ZOOM_LEVELS_XML, -) +from tests.devices.oav.test_data import TEST_DISPLAY_CONFIG, TEST_OAV_ZOOM_LEVELS @pytest.fixture() @@ -167,7 +165,9 @@ async def test_beam_centre_signals_have_same_names( async def test_oav_with_null_zoom_controller(null_controller: NullZoomController): - oav_config = OAVConfigBeamCentre(TEST_OAV_ZOOM_LEVELS_XML, TEST_DISPLAY_CONFIG) + oav_config = OAVConfigBeamCentre( + TEST_OAV_ZOOM_LEVELS, TEST_DISPLAY_CONFIG, ConfigClient("") + ) oav = OAVBeamCentreFile("", oav_config, "", zoom_controller=null_controller) assert await oav.zoom_controller.level.get_value() == "1.0x" @@ -193,7 +193,9 @@ async def test_oav_with_null_zoom_controller_set_zoom_level_other_than_1( ["MJPG", "XTAL"], ) async def test_setting_mjpeg_prefix_changes_stream_url(mjpeg_prefix): - oav_config = OAVConfigBeamCentre(TEST_OAV_ZOOM_LEVELS_XML, TEST_DISPLAY_CONFIG) + oav_config = OAVConfigBeamCentre( + TEST_OAV_ZOOM_LEVELS, TEST_DISPLAY_CONFIG, ConfigClient("") + ) async with init_devices(mock=True, connect=True): oav = OAVBeamCentreFile( "", config=oav_config, name="oav", mjpeg_prefix=mjpeg_prefix diff --git a/tests/devices/oav/test_oav_parameters.py b/tests/devices/oav/test_oav_parameters.py index ee856c1d784..49bf8159d84 100644 --- a/tests/devices/oav/test_oav_parameters.py +++ b/tests/devices/oav/test_oav_parameters.py @@ -1,6 +1,7 @@ from typing import cast import pytest +from daq_config_server import ConfigClient from dodal.devices.oav.oav_parameters import ( OAVConfig, @@ -9,10 +10,10 @@ ZoomParams, ZoomParamsCrosshair, ) -from tests.devices.oav.test_data import TEST_OAV_CENTRING_JSON -from tests.test_data import ( +from tests.devices.oav.test_data import ( TEST_DISPLAY_CONFIG, - TEST_OAV_ZOOM_LEVELS_XML, + TEST_OAV_CENTRING_JSON, + TEST_OAV_ZOOM_LEVELS, ) @@ -26,13 +27,13 @@ def mock_parameters(): @pytest.fixture def mock_config() -> dict[str, ZoomParams]: - return OAVConfig(TEST_OAV_ZOOM_LEVELS_XML).get_parameters() + return OAVConfig(TEST_OAV_ZOOM_LEVELS, ConfigClient("")).get_parameters() @pytest.fixture def mock_config_with_beam_centre() -> dict[str, ZoomParamsCrosshair]: config = OAVConfigBeamCentre( - TEST_OAV_ZOOM_LEVELS_XML, TEST_DISPLAY_CONFIG + TEST_OAV_ZOOM_LEVELS, TEST_DISPLAY_CONFIG, ConfigClient("") ).get_parameters() config = cast(dict[str, ZoomParamsCrosshair], config) return config diff --git a/tests/test_data/__init__.py b/tests/test_data/__init__.py index 2b2948e8f65..3b6829187c1 100644 --- a/tests/test_data/__init__.py +++ b/tests/test_data/__init__.py @@ -5,13 +5,10 @@ BAD_BEAMLINE_PARAMETERS = join(TEST_DATA_PATH, "bad_beamlineParameters") I04_BEAMLINE_PARAMETERS = join(TEST_DATA_PATH, "i04_beamlineParameters") TEST_BEAMLINE_PARAMETERS_TXT = join(TEST_DATA_PATH, "test_beamline_parameters.txt") -TEST_DISPLAY_CONFIG = join(TEST_DATA_PATH, "test_display.configuration") -TEST_OAV_ZOOM_LEVELS_XML = join(TEST_DATA_PATH, "test_oav_zoom_levels.xml") + __all__ = [ "BAD_BEAMLINE_PARAMETERS", "I04_BEAMLINE_PARAMETERS", "TEST_BEAMLINE_PARAMETERS_TXT", - "TEST_DISPLAY_CONFIG", - "TEST_OAV_ZOOM_LEVELS_XML", ] diff --git a/tests/test_data/test_display.configuration b/tests/test_data/test_display.configuration deleted file mode 100644 index dfb01954ac9..00000000000 --- a/tests/test_data/test_display.configuration +++ /dev/null @@ -1,42 +0,0 @@ -zoomLevel = 1.0 -crosshairX = 477 -crosshairY = 359 -topLeftX = 383 -topLeftY = 253 -bottomRightX = 410 -bottomRightY = 278 -zoomLevel = 2.5 -crosshairX = 493 -crosshairY = 355 -topLeftX = 340 -topLeftY = 283 -bottomRightX = 388 -bottomRightY = 322 -zoomLevel = 5.0 -crosshairX = 517 -crosshairY = 350 -topLeftX = 268 -topLeftY = 326 -bottomRightX = 354 -bottomRightY = 387 -zoomLevel = 7.5 -crosshairX = 549 -crosshairY = 347 -topLeftX = 248 -topLeftY = 394 -bottomRightX = 377 -bottomRightY = 507 -zoomLevel = 10.0 -crosshairX = 613 -crosshairY = 344 -topLeftX = 2 -topLeftY = 489 -bottomRightX = 206 -bottomRightY = 630 -zoomLevel = 15.0 -crosshairX = 693 -crosshairY = 339 -topLeftX = 1 -topLeftY = 601 -bottomRightX = 65 -bottomRightY = 767 diff --git a/tests/test_data/test_oav_zoom_levels.xml b/tests/test_data/test_oav_zoom_levels.xml deleted file mode 100644 index d751fd69747..00000000000 --- a/tests/test_data/test_oav_zoom_levels.xml +++ /dev/null @@ -1,42 +0,0 @@ - - - - - 1.0 - 0 - 2.87 - 2.87 - - - 2.5 - 10 - 2.31 - 2.31 - - - 5.0 - 25 - 1.58 - 1.58 - - - 7.5 - 50 - 0.806 - 0.806 - - - 10.0 - 75 - 0.438 - 0.438 - - - 15.0 - 90 - 0.302 - 0.302 - - -1.0 -