Skip to content

Commit

Permalink
Merge branch 'main' into 533_fix_unit_test_banned_paths
Browse files Browse the repository at this point in the history
  • Loading branch information
rtuck99 authored Jan 28, 2025
2 parents c7e5328 + b8fd466 commit f349d53
Show file tree
Hide file tree
Showing 23 changed files with 240 additions and 135 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ dependencies = [
"ophyd == 1.9.0",
"ophyd-async >= 0.8a5",
"bluesky >= 1.13",
"dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@main",
"dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@cb12746cb3f658a6d4571a0cd870133a17980bb7",
]


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

from mx_bluesky.common.parameters.constants import (
DocDescriptorNames,
TriggerConstants,
)
from mx_bluesky.common.utils.exceptions import ISPyBDepositionNotMade
from mx_bluesky.common.utils.log import ISPYB_ZOCALO_CALLBACK_LOGGER
Expand All @@ -30,34 +29,25 @@ class ZocaloCallback(CallbackBase):

def _reset_state(self):
self.run_uid: str | None = None
self.triggering_plan: str | None = None
self.zocalo_interactor: ZocaloTrigger | None = None
self.zocalo_info: list[ZocaloStartInfo] = []
self.descriptors: dict[str, EventDescriptor] = {}

def __init__(
self,
):
def __init__(self, triggering_plan: str, zocalo_environment: str):
super().__init__()
self.triggering_plan = triggering_plan
self.zocalo_interactor = ZocaloTrigger(zocalo_environment)
self._reset_state()

def start(self, doc: RunStart):
ISPYB_ZOCALO_CALLBACK_LOGGER.info("Zocalo handler received start document.")
if triggering_plan := doc.get(TriggerConstants.ZOCALO):
self.triggering_plan = triggering_plan
assert isinstance(zocalo_environment := doc.get("zocalo_environment"), str)
ISPYB_ZOCALO_CALLBACK_LOGGER.info(
f"Zocalo environment set to {zocalo_environment}."
)
self.zocalo_interactor = ZocaloTrigger(zocalo_environment)

if self.triggering_plan and doc.get("subplan_name") == self.triggering_plan:
self.run_uid = doc.get("uid")
assert isinstance(scan_points := doc.get("scan_points"), list)
if (
isinstance(ispyb_ids := doc.get("ispyb_dcids"), tuple)
and len(ispyb_ids) > 0
):
ISPYB_ZOCALO_CALLBACK_LOGGER.info(f"Zocalo triggering for {ispyb_ids}")
ids_and_shape = list(zip(ispyb_ids, scan_points, strict=False))
start_frame = 0
self.zocalo_info = []
Expand All @@ -82,7 +72,6 @@ def event(self, doc: Event) -> Event:
filename = doc["data"]["eiger_odin_file_writer_id"]
for start_info in self.zocalo_info:
start_info.filename = filename
assert self.zocalo_interactor is not None
self.zocalo_interactor.run_start(start_info)
return doc

Expand Down
7 changes: 6 additions & 1 deletion src/mx_bluesky/common/parameters/gridscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,13 @@ class GridCommon(
DiffractionExperimentWithSample,
OptionalGonioAngleStarts,
):
"""Parameters used in every MX diffraction experiment using grids. This model should be used by plans which have no knowledge of the grid specifications - i.e before automatic grid detection has completed"""
"""
Parameters used in every MX diffraction experiment using grids. This model should
be used by plans which have no knowledge of the grid specifications - i.e before
automatic grid detection has completed
"""

box_size_um: float = Field(default=GridscanParamConstants.BOX_WIDTH_UM)
grid_width_um: float = Field(default=GridscanParamConstants.WIDTH_UM)
exposure_time_s: float = Field(default=GridscanParamConstants.EXPOSURE_TIME_S)

Expand Down
6 changes: 0 additions & 6 deletions src/mx_bluesky/common/plans/do_fgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
read_hardware_for_zocalo,
)
from mx_bluesky.common.parameters.constants import (
EnvironmentConstants,
PlanNameConstants,
TriggerConstants,
)
from mx_bluesky.common.utils.tracing import TRACER

Expand Down Expand Up @@ -70,7 +68,6 @@ def kickoff_and_complete_gridscan(
scan_points: list[AxesPoints[Axis]],
scan_start_indices: list[int],
plan_during_collection: Callable[[], MsgGenerator] | None = None,
zocalo_environment: str = EnvironmentConstants.ZOCALO_ENV,
):
"""Triggers a grid scan motion program and waits for completion, accounting for synchrotron topup.
If the RunEngine is subscribed to ZocaloCallback, this plan will also trigger Zocalo.
Expand All @@ -86,7 +83,6 @@ def kickoff_and_complete_gridscan(
scan_start_indices (list[int]): Contains the first index of each grid scan
plan_during_collection (Optional, MsgGenerator): Generic plan called in between kickoff and completion,
eg waiting on zocalo.
zocalo_environment (Optional, str) Used for zocalo connection
"""

assert len(scan_points) == len(scan_start_indices), (
Expand All @@ -100,10 +96,8 @@ def kickoff_and_complete_gridscan(
@bpp.run_decorator(
md={
"subplan_name": plan_name,
TriggerConstants.ZOCALO: plan_name,
"scan_points": scan_points,
"scan_start_indices": scan_start_indices,
"zocalo_environment": zocalo_environment,
}
)
@bpp.contingency_decorator(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,6 @@ def rotation_scan(
@bpp.run_decorator( # attach experiment metadata to the start document
md={
"subplan_name": CONST.PLAN.ROTATION_OUTER,
CONST.TRIGGER.ZOCALO: CONST.PLAN.ROTATION_MAIN,
"zocalo_environment": CONST.ZOCALO_ENV,
"mx_bluesky_parameters": parameters.model_dump_json(),
"activate_callbacks": [
"RotationISPyBCallback",
Expand Down Expand Up @@ -443,7 +441,6 @@ def _multi_rotation_scan():
@bpp.run_decorator( # attach experiment metadata to the start document
md={
"subplan_name": CONST.PLAN.ROTATION_OUTER,
CONST.TRIGGER.ZOCALO: CONST.PLAN.ROTATION_MAIN,
"mx_bluesky_parameters": single_scan.model_dump_json(),
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,16 @@


def setup_callbacks():
zocalo = ZocaloCallback()
return [
GridscanNexusFileCallback(param_type=HyperionSpecifiedThreeDGridScan),
GridscanISPyBCallback(
param_type=GridCommonWithHyperionDetectorParams, emit=zocalo
param_type=GridCommonWithHyperionDetectorParams,
emit=ZocaloCallback(CONST.PLAN.DO_FGS, CONST.ZOCALO_ENV),
),
RotationNexusFileCallback(),
RotationISPyBCallback(emit=zocalo),
RotationISPyBCallback(
emit=ZocaloCallback(CONST.PLAN.ROTATION_MAIN, CONST.ZOCALO_ENV)
),
LogUidTaggingCallback(),
RobotLoadISPyBCallback(),
SampleHandlingCallback(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from mx_bluesky.hyperion.external_interaction.callbacks.sample_handling.sample_handling_callback import (
SampleHandlingCallback,
)
from mx_bluesky.hyperion.parameters.constants import CONST
from mx_bluesky.hyperion.parameters.gridscan import (
GridCommonWithHyperionDetectorParams,
HyperionSpecifiedThreeDGridScan,
Expand All @@ -34,10 +35,12 @@
def create_robot_load_and_centre_callbacks() -> tuple[
GridscanNexusFileCallback, GridscanISPyBCallback, RobotLoadISPyBCallback
]:
"""Note: This is not actually used in production, see https://github.com/DiamondLightSource/mx-bluesky/issues/516"""
return (
GridscanNexusFileCallback(param_type=HyperionSpecifiedThreeDGridScan),
GridscanISPyBCallback(
param_type=GridCommonWithHyperionDetectorParams, emit=ZocaloCallback()
param_type=GridCommonWithHyperionDetectorParams,
emit=ZocaloCallback(CONST.PLAN.DO_FGS, CONST.ZOCALO_ENV),
),
RobotLoadISPyBCallback(),
)
Expand All @@ -46,18 +49,26 @@ def create_robot_load_and_centre_callbacks() -> tuple[
def create_gridscan_callbacks() -> tuple[
GridscanNexusFileCallback, GridscanISPyBCallback
]:
"""Note: This is not actually used in production, see https://github.com/DiamondLightSource/mx-bluesky/issues/516"""
return (
GridscanNexusFileCallback(param_type=HyperionSpecifiedThreeDGridScan),
GridscanISPyBCallback(
param_type=GridCommonWithHyperionDetectorParams, emit=ZocaloCallback()
param_type=GridCommonWithHyperionDetectorParams,
emit=ZocaloCallback(CONST.PLAN.DO_FGS, CONST.ZOCALO_ENV),
),
)


def create_rotation_callbacks() -> tuple[
RotationNexusFileCallback, RotationISPyBCallback
]:
return (RotationNexusFileCallback(), RotationISPyBCallback(emit=ZocaloCallback()))
"""Note: This is not actually used in production, see https://github.com/DiamondLightSource/mx-bluesky/issues/516"""
return (
RotationNexusFileCallback(),
RotationISPyBCallback(
emit=ZocaloCallback(CONST.PLAN.ROTATION_MAIN, CONST.ZOCALO_ENV)
),
)


def create_load_centre_collect_callbacks() -> tuple[
Expand All @@ -68,13 +79,17 @@ def create_load_centre_collect_callbacks() -> tuple[
RotationISPyBCallback,
SampleHandlingCallback,
]:
"""Note: This is not actually used in production, see https://github.com/DiamondLightSource/mx-bluesky/issues/516"""
return (
GridscanNexusFileCallback(param_type=HyperionSpecifiedThreeDGridScan),
GridscanISPyBCallback(
param_type=GridCommonWithHyperionDetectorParams, emit=ZocaloCallback()
param_type=GridCommonWithHyperionDetectorParams,
emit=ZocaloCallback(CONST.PLAN.DO_FGS, CONST.ZOCALO_ENV),
),
RobotLoadISPyBCallback(),
RotationNexusFileCallback(),
RotationISPyBCallback(emit=ZocaloCallback()),
RotationISPyBCallback(
emit=ZocaloCallback(CONST.PLAN.ROTATION_MAIN, CONST.ZOCALO_ENV)
),
SampleHandlingCallback(),
)
4 changes: 1 addition & 3 deletions src/mx_bluesky/hyperion/parameters/gridscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
PandAGridScanParams,
ZebraGridScanParams,
)
from pydantic import Field

from mx_bluesky.common.parameters.constants import GridscanParamConstants
from mx_bluesky.common.parameters.gridscan import (
GridCommon,
SpecifiedThreeDGridScan,
Expand Down Expand Up @@ -146,4 +144,4 @@ class PinTipCentreThenXrayCentre(
class GridScanWithEdgeDetect(
GridCommonWithHyperionDetectorParams, WithHyperionUDCFeatures
):
box_size_um: float = Field(default=GridscanParamConstants.BOX_WIDTH_UM)
pass
7 changes: 4 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,10 +527,11 @@ def mirror_voltages():

@pytest.fixture
def undulator_dcm(RE, sim_run_engine, dcm):
undulator_dcm = i03.undulator_dcm(fake_with_ophyd_sim=True)
undulator_dcm = i03.undulator_dcm(
fake_with_ophyd_sim=True,
daq_configuration_path="tests/test_data/test_daq_configuration",
)
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
beamline_utils.clear_devices()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
"omega_start_deg": 0.0,
"grid_width_um": 290.6,
"transmission_frac": 1.0,
"visit": "cm31105-4"
"visit": "cm31105-4",
"box_size_um": 20
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"demand_energy_ev": 11100,
"run_number": 0,
"features": {"use_panda_for_gridscan": false, "compare_cpu_and_gpu_zocalo": true},
"panda_runup_distance_mm": 0.17
"panda_runup_distance_mm": 0.17,
"box_size_um": 20
},
"multi_rotation_scan": {
"comment": "Rotation",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
"tip_offset_um": 108.9,
"grid_width_um": 290.6,
"transmission_frac": 1.0,
"visit": "cm31105-4"
"visit": "cm31105-4",
"box_size_um": 20
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
"sample_id": 12345,
"sample_puck": 40,
"sample_pin": 3,
"comment": "Descriptive comment."
"comment": "Descriptive comment.",
"box_size_um": 20
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#######################
# #
# 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
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,9 @@ def start_dict(plan_name: str = "test_plan_name", env: str = "test_env"):

class TestZocaloHandler:
def _setup_handler(self):
zocalo_handler = ZocaloCallback()
assert zocalo_handler.triggering_plan is None
zocalo_handler.start(start_dict()) # type: ignore
assert zocalo_handler.triggering_plan == "test_plan_name"
assert zocalo_handler.zocalo_interactor is not None
zocalo_handler = ZocaloCallback("test_plan_name", "test_env")
return zocalo_handler

def test_handler_gets_plan_name_from_start_doc(self):
self._setup_handler()

def test_handler_doesnt_trigger_on_wrong_plan(self):
zocalo_handler = self._setup_handler()
zocalo_handler.start(start_dict("_not_test_plan_name")) # type: ignore
Expand Down
Loading

0 comments on commit f349d53

Please sign in to comment.