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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ dependencies = [
"ophyd >= 1.10.5",
"ophyd-async >= 0.14.0",
"bluesky >= 1.14.6",
"dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@62960e0e587bf86943ce1b581848fa131ef884d5",
"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.detector.det_dim_constants import DetectorSizeConstants
from dodal.devices.i24.aperture import Aperture, AperturePositions
from dodal.devices.i24.beam_center import DetectorBeamCenter
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 @@ -17,6 +17,7 @@
import pytest
from bluesky.simulators import RunEngineSimulator
from bluesky.utils import Msg
from daq_config_server.models import ConfigModel
from dodal.beamlines import aithre, i03
from dodal.common.beamlines import beamline_parameters as bp
from dodal.common.beamlines import beamline_utils
Expand Down Expand Up @@ -1725,7 +1726,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 @@ -1738,6 +1739,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


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]
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]
]
}