Skip to content

Commit

Permalink
Merge branch 'main' into 684_serial-detector-params
Browse files Browse the repository at this point in the history
  • Loading branch information
noemifrisina committed Dec 17, 2024
2 parents 4793efc + 0042db5 commit 29db653
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 7 deletions.
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ dependencies = [
"matplotlib",
"nexgen",
"numpy",
"opencv-python", # Needed for I24 ssx moveonclick. To be changed to headless once this is moved to separate ui.
"opencv-python", # Needed for I24 ssx moveonclick. To be changed to headless once this is moved to separate ui.
"opentelemetry-distro",
"opentelemetry-exporter-otlp",
"pydantic",
"pydantic-extra-types",
"pydantic-extra-types >= 2.10.1",
"pyepics",
"pyzmq",
"requests",
Expand All @@ -46,7 +46,7 @@ dependencies = [
"ophyd == 1.9.0",
"ophyd-async >= 0.8a5",
"bluesky >= 1.13.0a4",
"dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@317b15e07b7ff1055207c398d0fcf635ac68915a",
"dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@a0077625f9383e691e1b59cc3041038efd9ae268",
]


Expand Down
11 changes: 11 additions & 0 deletions src/mx_bluesky/common/external_interaction/config_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,19 @@ def get_config_server() -> ConfigServer: ...
def mark_overridden_features(cls, values):
assert isinstance(values, dict)
values["overriden_features"] = values.copy()
cls._validate_overridden_features(values)
return values

@classmethod
def _validate_overridden_features(cls, values: dict):
"""Validates overridden features to ensure they are defined in the model fields."""
defined_fields = cls.model_fields.keys()
invalid_features = [key for key in values.keys() if key not in defined_fields]

if invalid_features:
message = f"Invalid feature toggle(s) supplied: {invalid_features}. "
raise ValueError(message)

def _get_flags(self):
flags = type(self).get_config_server().best_effort_get_all_feature_flags()
return {f: flags[f] for f in flags if f in self.model_fields.keys()}
Expand Down
38 changes: 38 additions & 0 deletions src/mx_bluesky/common/external_interaction/test_config_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from functools import cache

import pytest

from mx_bluesky.common.external_interaction.config_server import FeatureFlags


class MockConfigServer:
def best_effort_get_all_feature_flags(self):
return {
"feature_a": False,
"feature_b": False,
}


class FakeFeatureFlags(FeatureFlags):
@staticmethod
@cache
def get_config_server() -> MockConfigServer: # type: ignore
return MockConfigServer()

feature_a: bool = False
feature_b: bool = False


@pytest.fixture
def fake_feature_flags():
return FakeFeatureFlags(feature_a=False, feature_b=False)


def test_valid_overridden_features(fake_feature_flags: FakeFeatureFlags):
assert fake_feature_flags.feature_a is False
assert fake_feature_flags.feature_b is False


def test_invalid_overridden_features():
with pytest.raises(ValueError, match="Invalid feature toggle"):
FakeFeatureFlags(feature_x=True) # type: ignore
1 change: 1 addition & 0 deletions src/mx_bluesky/common/parameters/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class IspybExperimentType(StrEnum):
STILL = "Still"
SSX_CHIP = "SSX-Chip"
SSX_JET = "SSX-Jet"
METAL_ID = "Metal ID"

# Aliases for historic hyperion experiment type mapping
ROTATION = "SAD"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,11 @@ def adjust_dcm_pitch_roll_vfm_from_lut(
feedback from making unnecessary corrections while beam is being adjusted."""

# Adjust DCM Pitch
dcm = undulator_dcm.dcm
dcm = undulator_dcm.dcm_ref()
LOGGER.info(f"Adjusting DCM and VFM for {energy_kev} keV")
d_spacing_a: float = yield from bps.rd(undulator_dcm.dcm.crystal_metadata_d_spacing)
d_spacing_a: float = yield from bps.rd(
undulator_dcm.dcm_ref().crystal_metadata_d_spacing
)
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(
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ def mirror_voltages():
@pytest.fixture
def undulator_dcm(RE, sim_run_engine, dcm):
undulator_dcm = i03.undulator_dcm(fake_with_ophyd_sim=True)
set_up_dcm(undulator_dcm.dcm, sim_run_engine)
set_up_dcm(undulator_dcm.dcm_ref(), sim_run_engine)
undulator_dcm.roll_energy_table_path = "tests/test_data/test_daq_configuration/lookup/BeamLineEnergy_DCM_Roll_converter.txt"
undulator_dcm.pitch_energy_table_path = "tests/test_data/test_daq_configuration/lookup/BeamLineEnergy_DCM_Pitch_converter.txt"
yield undulator_dcm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def test_execute_load_centre_collect_full(
robot_load_cb.expeye.end_load = MagicMock()
robot_load_cb.expeye.update_barcode_and_snapshots = MagicMock()
set_mock_value(
load_centre_collect_composite.undulator_dcm.undulator.current_gap, 1.11
load_centre_collect_composite.undulator_dcm.undulator_ref().current_gap, 1.11
)
RE.subscribe(ispyb_gridscan_cb)
RE.subscribe(ispyb_rotation_cb)
Expand Down

0 comments on commit 29db653

Please sign in to comment.