Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Commit

Permalink
Merge pull request #753 from DiamondLightSource/716_full_grid_scan_se…
Browse files Browse the repository at this point in the history
…ts_transmission_first

Full grid scan sets transmission, transmission sent to ispbyb
  • Loading branch information
DominicOram authored Jul 17, 2023
2 parents 8bd7078 + c31703c commit 6c618d7
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/artemis/experiment_plans/fast_grid_scan_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from dodal.beamlines import i03
from dodal.beamlines.i03 import (
ApertureScatterguard,
Attenuator,
Backlight,
EigerDetector,
FastGridScan,
Expand Down Expand Up @@ -61,6 +62,7 @@ class FGSComposite:
synchrotron: Synchrotron
undulator: Undulator
zebra: Zebra
attenuator: Attenuator

def __init__(
self,
Expand All @@ -82,6 +84,7 @@ def __init__(
self.undulator = i03.undulator(fake_with_ophyd_sim=fake)
self.synchrotron = i03.synchrotron(fake_with_ophyd_sim=fake)
self.zebra = i03.zebra(fake_with_ophyd_sim=fake)
self.attenuator = i03.attenuator(fake_with_ophyd_sim=fake)


fast_grid_scan_composite: FGSComposite | None = None
Expand Down Expand Up @@ -131,6 +134,7 @@ def read_hardware_for_ispyb(
undulator: Undulator,
synchrotron: Synchrotron,
s4_slit_gaps: S4SlitGaps,
attenuator: Attenuator,
flux: Flux,
):
artemis.log.LOGGER.info(
Expand All @@ -143,6 +147,7 @@ def read_hardware_for_ispyb(
yield from bps.read(synchrotron.machine_status.synchrotron_mode)
yield from bps.read(s4_slit_gaps.xgap)
yield from bps.read(s4_slit_gaps.ygap)
yield from bps.read(attenuator.actual_transmission)
yield from bps.read(flux.flux_reading)
yield from bps.save()

Expand Down Expand Up @@ -213,6 +218,7 @@ def run_gridscan(
fgs_composite.undulator,
fgs_composite.synchrotron,
fgs_composite.s4_slit_gaps,
fgs_composite.attenuator,
fgs_composite.flux,
)

Expand All @@ -233,6 +239,8 @@ def do_fgs():
yield from bps.kickoff(fgs_motors)
yield from bps.complete(fgs_motors, wait=True)

# Wait for arming to finish
yield from bps.wait("ready_for_data_collection")
yield from bps.stage(fgs_composite.eiger)

with TRACER.start_span("do_fgs"):
Expand Down
11 changes: 10 additions & 1 deletion src/artemis/experiment_plans/full_grid_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from bluesky import preprocessors as bpp
from dodal.beamlines import i03
from dodal.devices.aperturescatterguard import AperturePositions, ApertureScatterguard
from dodal.devices.attenuator import Attenuator
from dodal.devices.backlight import Backlight
from dodal.devices.detector_motion import DetectorMotion
from dodal.devices.eiger import EigerDetector
Expand Down Expand Up @@ -80,14 +81,20 @@ def create_parameters_for_fast_grid_scan(

def start_arming_then_do_grid(
parameters: GridScanWithEdgeDetectInternalParameters,
attenuator: Attenuator,
backlight: Backlight,
eiger: EigerDetector,
aperture_scatterguard: ApertureScatterguard,
detector_motion: DetectorMotion,
oav_params: OAVParameters,
):
# Start stage with asynchronous arming here
yield from bps.abs_set(eiger.do_arm, 1, group="arming")
yield from bps.abs_set(eiger.do_arm, 1, group="ready_for_data_collection")
yield from bps.abs_set(
attenuator,
parameters.artemis_params.ispyb_params.transmission,
group="ready_for_data_collection",
)

yield from bpp.contingency_wrapper(
detect_grid_and_do_gridscan(
Expand Down Expand Up @@ -181,13 +188,15 @@ def get_plan(
eiger: EigerDetector = i03.eiger()
aperture_scatterguard: ApertureScatterguard = i03.aperture_scatterguard()
detector_motion: DetectorMotion = i03.detector_motion()
attenuator: Attenuator = i03.attenuator()

eiger.set_detector_parameters(parameters.artemis_params.detector_params)

oav_params = OAVParameters("xrayCentring", **oav_param_files)

return start_arming_then_do_grid(
parameters,
attenuator,
backlight,
eiger,
aperture_scatterguard,
Expand Down
10 changes: 8 additions & 2 deletions src/artemis/experiment_plans/tests/test_fast_grid_scan_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ def test_read_hardware_for_ispyb_updates_from_ophyd_devices(
synchrotron_test_value
)

transmission_test_value = 0.5
fake_fgs_composite.attenuator.actual_transmission.sim_put(transmission_test_value)

xgap_test_value = 0.1234
ygap_test_value = 0.2345
fake_fgs_composite.s4_slit_gaps.xgap.user_readback.sim_put(xgap_test_value)
Expand All @@ -91,16 +94,17 @@ def test_read_hardware_for_ispyb_updates_from_ophyd_devices(
test_ispyb_callback.ispyb = MagicMock()
RE.subscribe(test_ispyb_callback)

def standalone_read_hardware_for_ispyb(und, syn, slits, fl):
def standalone_read_hardware_for_ispyb(und, syn, slits, attn, fl):
yield from bps.open_run()
yield from read_hardware_for_ispyb(und, syn, slits, fl)
yield from read_hardware_for_ispyb(und, syn, slits, attn, fl)
yield from bps.close_run()

RE(
standalone_read_hardware_for_ispyb(
fake_fgs_composite.undulator,
fake_fgs_composite.synchrotron,
fake_fgs_composite.s4_slit_gaps,
fake_fgs_composite.attenuator,
fake_fgs_composite.flux,
)
)
Expand All @@ -110,6 +114,8 @@ def standalone_read_hardware_for_ispyb(und, syn, slits, fl):
assert params.artemis_params.ispyb_params.synchrotron_mode == synchrotron_test_value
assert params.artemis_params.ispyb_params.slit_gap_size_x == xgap_test_value
assert params.artemis_params.ispyb_params.slit_gap_size_y == ygap_test_value
assert params.artemis_params.ispyb_params.transmission == transmission_test_value
assert params.artemis_params.ispyb_params.flux == flux_test_value


@patch(
Expand Down
27 changes: 27 additions & 0 deletions src/artemis/experiment_plans/tests/test_full_grid_scan_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ class DetectException(Exception):
RE(
start_arming_then_do_grid(
parameters=test_full_grid_scan_params,
attenuator=MagicMock(),
backlight=MagicMock(),
eiger=eiger,
aperture_scatterguard=MagicMock(),
Expand All @@ -254,3 +255,29 @@ class DetectException(Exception):
eiger.async_stage.assert_called_once()

eiger.disarm_detector.assert_called_once()


@patch("artemis.experiment_plans.full_grid_scan.detect_grid_and_do_gridscan")
def test_when_start_arming_then_transmission_set(
mock_grid_detection_plan: MagicMock,
RE: RunEngine,
test_full_grid_scan_params: GridScanWithEdgeDetectInternalParameters,
test_config_files: Dict,
):
attenuator = MagicMock()
RE(
start_arming_then_do_grid(
parameters=test_full_grid_scan_params,
attenuator=attenuator,
backlight=MagicMock(),
eiger=MagicMock(),
aperture_scatterguard=MagicMock(),
detector_motion=MagicMock(),
oav_params=OAVParameters("xrayCentring", **test_config_files),
)
)

# Check transmission set
attenuator.set.assert_called_once_with(
test_full_grid_scan_params.artemis_params.ispyb_params.transmission
)
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ def event(self, doc: dict):
self.params.artemis_params.ispyb_params.slit_gap_size_y = doc["data"][
"s4_slit_gaps_ygap"
]
self.params.artemis_params.ispyb_params.transmission = doc["data"][
"attenuator_actual_transmission"
]

LOGGER.info("Creating ispyb entry.")
self.ispyb_ids = self.ispyb.begin_deposition()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class TestData:
"s4_slit_gaps_ygap": 0.2345,
"synchrotron_machine_status_synchrotron_mode": "test",
"undulator_gap": 1.234,
"attenuator_actual_transmission": 1,
},
"timestamps": {"det1": 1666604299.8220396, "det2": 1666604299.8235943},
"seq_num": 1,
Expand Down
3 changes: 3 additions & 0 deletions src/artemis/system_tests/test_main_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ def test_cli_args_parse():
assert test_args == ("DEBUG", True, True, True)


@patch("dodal.beamlines.i03.Attenuator")
@patch("dodal.beamlines.i03.Flux")
@patch("dodal.beamlines.i03.DetectorMotion")
@patch("dodal.beamlines.i03.OAV")
Expand Down Expand Up @@ -328,6 +329,7 @@ def test_when_blueskyrunner_initiated_then_plans_are_setup_and_devices_connected
aperture_scatterguard,
oav,
detector_motion,
attenuator,
flux,
):
type_comparison.return_value = True
Expand All @@ -343,6 +345,7 @@ def test_when_blueskyrunner_initiated_then_plans_are_setup_and_devices_connected
aperture_scatterguard.return_value.wait_for_connection.assert_called()
oav.return_value.wait_for_connection.assert_called()
detector_motion.return_value.wait_for_connection.assert_called()
attenuator.return_value.wait_for_connection.assert_called()
flux.return_value.wait_for_connection.assert_called()


Expand Down

0 comments on commit 6c618d7

Please sign in to comment.