From 95fa5507eab19b052a3e4209bfd63adb43faa87b Mon Sep 17 00:00:00 2001 From: David Perl Date: Fri, 30 Oct 2026 16:23:24 +0100 Subject: [PATCH] feat: use rotation scan defaut settings from config service --- pyproject.toml | 2 +- .../beamline_dispatch/default/beamline_dispatch.py | 12 +++++++++++- .../beamline_dispatch/x06da/beamline_dispatch.py | 5 ----- .../beamline_dispatch/x10sa/beamline_dispatch.py | 5 ----- tests/unit/utils/test_beamline_dispatch.py | 12 +++++++++++- 5 files changed, 23 insertions(+), 13 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 10356cbe..3e4cc9d4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,7 +33,7 @@ dependencies = [ "aarelcinfer-client==0.1.1a8", "matplotlib>=3.10.3", "httpx>=0.28.1", - "aare-config>=0.1.7", + "aare-config>=0.3.0", ] [project.optional-dependencies] diff --git a/src/aare/beamline_dispatch/default/beamline_dispatch.py b/src/aare/beamline_dispatch/default/beamline_dispatch.py index 45dba3bb..28435b60 100644 --- a/src/aare/beamline_dispatch/default/beamline_dispatch.py +++ b/src/aare/beamline_dispatch/default/beamline_dispatch.py @@ -4,6 +4,7 @@ from abc import ABC from importlib.resources import files from typing import Any +from aare_config import AareConfigClient from aarecommon.config.beamline import MXBeamline from aarecommon.models.beam_centre import BeamCentre @@ -46,6 +47,9 @@ class DefaultDispatch(BeamlineDispatch, ABC): ) -> None: self._auth = DefaultAuthDispatch() self._geo = geo_class(beamline=beamline) + self._config = AareConfigClient( + redis_url=f"redis://mx-{beamline.value.lower()}-queue-01", key_prefix="config" + ) @property def auth(self): @@ -57,7 +61,13 @@ class DefaultDispatch(BeamlineDispatch, ABC): @property def default_rotation_parameters(self) -> dict[str, Any]: - return {"exp_time_s": 0.04, "dtz": 110, "incr_omega_deg": 0.2} + defaults = self._config.rotation_defaults + return { + "exp_time_s": defaults.exp_time_s, + "dtz": defaults.detector_distance_mm, + "incr_omega_deg": defaults.image_width_deg, + "transmission": defaults.transmission_fraction, + } @property def default_auto_raster_parameters(self) -> dict[str, Any]: diff --git a/src/aare/beamline_dispatch/x06da/beamline_dispatch.py b/src/aare/beamline_dispatch/x06da/beamline_dispatch.py index 0c85000c..a6dbdd18 100644 --- a/src/aare/beamline_dispatch/x06da/beamline_dispatch.py +++ b/src/aare/beamline_dispatch/x06da/beamline_dispatch.py @@ -109,11 +109,6 @@ class X06daDispatch(DefaultDispatch): def bec_macros(self) -> BecMacros: return self._bec_macros - @property - def default_rotation_parameters(self) -> dict[str, Any]: - default = super().default_rotation_parameters - return default | {"transmission": 1.0} - @property def default_auto_raster_parameters(self) -> dict[str, Any]: return {"exp_time_s": 0.04, "transmission": 1.0, "dtz": 150} diff --git a/src/aare/beamline_dispatch/x10sa/beamline_dispatch.py b/src/aare/beamline_dispatch/x10sa/beamline_dispatch.py index 356cbe90..86089dad 100644 --- a/src/aare/beamline_dispatch/x10sa/beamline_dispatch.py +++ b/src/aare/beamline_dispatch/x10sa/beamline_dispatch.py @@ -110,11 +110,6 @@ class X10saDispatch(DefaultDispatch): def bec_macros(self) -> BecMacros: return self._bec_macros - @property - def default_rotation_parameters(self) -> dict[str, Any]: - default = super().default_rotation_parameters - return default | {"transmission": 0.1} - @property def default_auto_raster_parameters(self) -> dict[str, Any]: # Full transmission for 20 keV rastering diff --git a/tests/unit/utils/test_beamline_dispatch.py b/tests/unit/utils/test_beamline_dispatch.py index 49357794..5ae6ba92 100644 --- a/tests/unit/utils/test_beamline_dispatch.py +++ b/tests/unit/utils/test_beamline_dispatch.py @@ -1,5 +1,5 @@ import importlib.util -from unittest.mock import patch +from unittest.mock import MagicMock, patch import numpy as np import pytest @@ -10,6 +10,16 @@ from aare.beamline_dispatch.x06da import X06daDispatch from aare.beamline_dispatch.x10sa import X10saDispatch +@pytest.fixture(autouse=True) +def mock_config_client(): + """Every dispatch class goes through DefaultDispatch, which builds an AareConfigClient + pointing at the beamline redis; stub it so no test needs a live connection.""" + with patch( + "aare.beamline_dispatch.default.beamline_dispatch.AareConfigClient", autospec=True + ) as mock_cls: + yield mock_cls.return_value + + def test_dispatch_cannot_be_instantiated_without_env(): with patch.dict("os.environ", {}, clear=True), pytest.raises(ValueError) as e: _ = get_beamline_dispatch()