Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,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_1509_use_config_server_for_detector_lut",
]


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from pathlib import Path

import bluesky.plan_stubs as bps
from daq_config_server.client import ConfigServer
from daq_config_server.models import DetectorXYLookupTable
from dodal.devices.beamlines.i24.aperture import Aperture, AperturePositions
from dodal.devices.beamlines.i24.beam_center import DetectorBeamCenter
from dodal.devices.beamlines.i24.beamstop import Beamstop, BeamstopPositions
Expand All @@ -10,7 +12,6 @@
from dodal.devices.motors import YZStage
from dodal.devices.util.lookup_tables import (
linear_interpolation_lut,
parse_lookup_table,
)

from mx_bluesky.beamlines.i24.serial.log import SSX_LOGGER
Expand All @@ -26,17 +27,20 @@ def compute_beam_center_position_from_lut(
"""Calculate the beam center position for the detector distance \
using the values in the lookup table for the conversion.
"""
lut_values = parse_lookup_table(lut_path.as_posix())
config_server = ConfigServer(url="https://daq-config.diamond.ac.uk")
lut_columns = config_server.get_file_contents(
lut_path, DetectorXYLookupTable
).columns

calc_x = linear_interpolation_lut(lut_values[0], lut_values[1])
calc_x = linear_interpolation_lut(lut_columns[0], lut_columns[1])
beam_x_mm = calc_x(detector_distance_mm)
beam_x = (
beam_x_mm
* det_size_constants.det_size_pixels.width
/ det_size_constants.det_dimension.width
)

calc_y = linear_interpolation_lut(lut_values[0], lut_values[2])
calc_y = linear_interpolation_lut(lut_columns[0], lut_columns[2])
beam_y_mm = calc_y(detector_distance_mm)
beam_y = (
beam_y_mm
Expand Down
33 changes: 32 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import pytest
from bluesky.simulators import RunEngineSimulator
from bluesky.utils import Msg, MsgGenerator
from daq_config_server.models import ConfigModel
from dodal.beamlines import aithre, i03
from dodal.common.beamlines import beamline_utils
from dodal.common.beamlines.beamline_parameters import (
Expand Down Expand Up @@ -1728,7 +1729,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:
Expand All @@ -1741,6 +1742,36 @@ def mock_config_server():
yield


def _fake_config_server_get_file_contents(
filepath: str | Path,
desired_return_type: type[str] | type[dict] | ConfigModel = str,
reset_cached_result: bool = True,
):
filepath = Path(filepath)
# Minimal logic required for unit tests
with filepath.open("r") as f:
contents = f.read()
print(contents)
if desired_return_type is str:
return contents
elif desired_return_type is dict:
print("return type is dict")
return json.loads(contents)
elif issubclass(desired_return_type, ConfigModel): # 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


@pytest.fixture(autouse=True)
def mock_alert_service():
with patch(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#Table giving position of beam X and Y as a function of detector distance
#Units mm mm mm
# Eiger values
# distance beamY beamX (values from mosflm)
Units mm mm mm
200 119.78 127.0
1500 119.4 126.9
{
"column_names": ["detector_distances_mm", "beam_centre_x_mm", "beam_centre_y_mm"],
"rows": [
[200.0, 119.78, 127.0],
[1500.0, 119.4, 126.9]
]
}
14 changes: 7 additions & 7 deletions tests/test_data/test_det_dist_converter.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#Table giving position of beam X and Y as a function of detector distance
#Units mm mm mm
# Eiger values
# distance beamY beamX (values from mosflm)
Units mm mm mm
200 153.61 162.45
500 153.57 159.96
{
"column_names": ["detector_distances_mm", "beam_centre_x_mm", "beam_centre_y_mm"],
"rows": [
[200.0, 153.61, 162.45],
[500.0, 153.57, 159.96]
]
}
11 changes: 6 additions & 5 deletions tests/test_data/test_lookup_table.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Beam converter lookup table for testing

Units det_dist beam_x beam_y
100.0 150.0 160.0
200.0 151.0 165.0
{
"rows": [
[100.0, 150.0, 160.0],
[200.0, 151.0, 165.0]
]
}
8 changes: 4 additions & 4 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.