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 @@ -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 @ git+https://github.com/DiamondLightSource/daq-config-server.git@extend_lookup_table_model",
"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",
]


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

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,
Expand All @@ -10,7 +12,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
Expand Down Expand Up @@ -114,12 +115,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,
)
Expand All @@ -128,10 +132,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,
)
Expand Down
31 changes: 30 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1723,7 +1724,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 @@ -1736,6 +1737,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]
Expand Down
Original file line number Diff line number Diff line change
@@ -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]
]
}
Original file line number Diff line number Diff line change
@@ -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]
]
}
Original file line number Diff line number Diff line change
@@ -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]
]
}
Loading