Skip to content
This repository was archived by the owner on Sep 2, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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 setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ install_requires =
xarray
doct
databroker
dodal @ git+https://github.com/DiamondLightSource/python-dodal.git@787580a676b769628665f732f97cadd78a69d1da
dodal @ git+https://github.com/DiamondLightSource/python-dodal.git@9f82cf522fddbdb415d36ead204ead380ab0648a

[options.extras_require]
dev =
Expand Down
7 changes: 7 additions & 0 deletions src/artemis/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import sys
from os import environ, getenv


def pytest_runtest_teardown():
if "dodal.i03" in sys.modules:
sys.modules["dodal.i03"].clear_devices()


s03_epics_server_port = getenv("S03_EPICS_CA_SERVER_PORT")
s03_epics_repeater_port = getenv("S03_EPICS_CA_REPEATER_PORT")

Expand Down
104 changes: 67 additions & 37 deletions src/artemis/experiment_plans/fast_grid_scan_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,21 @@
import bluesky.preprocessors as bpp
from bluesky import RunEngine
from bluesky.utils import ProgressBarManager
from dodal.devices.aperturescatterguard import AperturePositions, ApertureScatterguard
from dodal.devices.eiger import EigerDetector
from dodal.devices.fast_grid_scan import FastGridScan, set_fast_grid_scan_params
from dodal.devices.fast_grid_scan_composite import FGSComposite
from dodal.devices.s4_slit_gaps import S4SlitGaps
from dodal.devices.synchrotron import Synchrotron
from dodal.devices.undulator import Undulator
from dodal import i03
from dodal.devices.aperturescatterguard import AperturePositions
from dodal.devices.eiger import DetectorParams
from dodal.devices.fast_grid_scan import set_fast_grid_scan_params
from dodal.i03 import (
ApertureScatterguard,
Backlight,
EigerDetector,
FastGridScan,
S4SlitGaps,
Smargon,
Synchrotron,
Undulator,
Zebra,
)

import artemis.log
from artemis.device_setup_plans.setup_zebra_for_fgs import (
Expand All @@ -34,15 +42,47 @@
from artemis.utils import Point3D

if TYPE_CHECKING:
from dodal.devices.fast_grid_scan_composite import FGSComposite

from artemis.external_interaction.callbacks.fgs.fgs_callback_collection import (
FGSCallbackCollection,
)
from artemis.parameters.internal_parameters import InternalParameters

fast_grid_scan_composite: FGSComposite = None
eiger: EigerDetector = None

class FGSComposite:
"""A device consisting of all the Devices required for a fast gridscan."""

aperture_scatterguard: ApertureScatterguard
backlight: Backlight
eiger: EigerDetector
fast_grid_scan: FastGridScan
s4_slit_gaps: S4SlitGaps
sample_motors: Smargon
synchrotron: Synchrotron
undulator: Undulator
zebra: Zebra

def __init__(
self,
aperture_positions: AperturePositions = None,
detector_params: DetectorParams = None,
fake: bool = False,
):
self.aperture_scatterguard = i03.aperture_scatterguard(
fake_with_ophyd_sim=fake, aperture_positions=aperture_positions
)
self.backlight = i03.backlight(fake_with_ophyd_sim=fake)
self.eiger = i03.eiger(
wait_for_connection=False, fake_with_ophyd_sim=fake, params=detector_params
)
self.fast_grid_scan = i03.fast_grid_scan(fake_with_ophyd_sim=fake)
self.s4_slit_gaps = i03.s4_slit_gaps(fake_with_ophyd_sim=fake)
self.sample_motors = i03.smargon(fake_with_ophyd_sim=fake)
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)


fast_grid_scan_composite: FGSComposite | None = None


def get_beamline_parameters():
Expand All @@ -51,29 +91,16 @@ def get_beamline_parameters():

def create_devices():
"""Creates the devices required for the plan and connect to them"""
global fast_grid_scan_composite, eiger
global fast_grid_scan_composite
prefixes = get_beamline_prefixes()
artemis.log.LOGGER.info(
f"Creating devices for {prefixes.beamline_prefix} and {prefixes.insertion_prefix}"
)
aperture_positions = AperturePositions.from_gda_beamline_params(
get_beamline_parameters()
)
fast_grid_scan_composite = FGSComposite(
insertion_prefix=prefixes.insertion_prefix,
name="fgs",
prefix=prefixes.beamline_prefix,
aperture_positions=aperture_positions,
)

# Note, eiger cannot be currently waited on, see #166
eiger = EigerDetector(
name="eiger",
prefix=f"{prefixes.beamline_prefix}-EA-EIGER-01:",
)

artemis.log.LOGGER.info("Connecting to EPICS devices...")
fast_grid_scan_composite.wait_for_connection()
fast_grid_scan_composite = FGSComposite(aperture_positions=aperture_positions)
artemis.log.LOGGER.info("Connected.")


Expand Down Expand Up @@ -123,6 +150,7 @@ def move_xyz(
):
"""Move 'sample motors' to a specific motor position (e.g. a position obtained
from gridscan processing results)"""
artemis.log.LOGGER.info(f"Moving Smargon x, y, z to: {xray_centre_motor_position}")
yield from bps.mv(
sample_motors.x,
xray_centre_motor_position.x,
Expand Down Expand Up @@ -150,14 +178,14 @@ def wait_for_fgs_valid(fgs_motors: FastGridScan, timeout=0.5):


def tidy_up_plans(fgs_composite: FGSComposite):
artemis.log.LOGGER.info("Tidying up Zebra")
yield from set_zebra_shutter_to_manual(fgs_composite.zebra)


@bpp.set_run_key_decorator("run_gridscan")
@bpp.run_decorator(md={"subplan_name": "run_gridscan"})
def run_gridscan(
fgs_composite: FGSComposite,
eiger: EigerDetector,
parameters: InternalParameters,
md={
"plan_name": "run_gridscan",
Expand Down Expand Up @@ -187,7 +215,7 @@ def run_gridscan(

@bpp.set_run_key_decorator("do_fgs")
@bpp.run_decorator(md={"subplan_name": "do_fgs"})
@bpp.stage_decorator([eiger])
@bpp.stage_decorator([fgs_composite.eiger])
def do_fgs():
yield from bps.wait() # Wait for all moves to complete
yield from bps.kickoff(fgs_motors)
Expand All @@ -204,7 +232,6 @@ def do_fgs():
@bpp.run_decorator(md={"subplan_name": "run_gridscan_and_move"})
def run_gridscan_and_move(
fgs_composite: FGSComposite,
eiger: EigerDetector,
parameters: InternalParameters,
subscriptions: FGSCallbackCollection,
):
Expand All @@ -222,11 +249,11 @@ def run_gridscan_and_move(

# While the gridscan is happening we want to write out nexus files and trigger zocalo
@bpp.subs_decorator([subscriptions.nexus_handler, subscriptions.zocalo_handler])
def gridscan_with_subscriptions(fgs_composite, detector, params):
yield from run_gridscan(fgs_composite, detector, params)
def gridscan_with_subscriptions(fgs_composite, params):
artemis.log.LOGGER.info("Starting grid scan")
yield from run_gridscan(fgs_composite, params)

artemis.log.LOGGER.info("Starting grid scan")
yield from gridscan_with_subscriptions(fgs_composite, eiger, parameters)
yield from gridscan_with_subscriptions(fgs_composite, parameters)

# the data were submitted to zocalo by the zocalo callback during the gridscan,
# but results may not be ready, and need to be collected regardless.
Expand Down Expand Up @@ -263,15 +290,18 @@ def get_plan(
Returns:
Generator: The plan for the gridscan
"""
eiger.set_detector_parameters(parameters.artemis_params.detector_params)
assert fast_grid_scan_composite is not None
fast_grid_scan_composite.eiger.set_detector_parameters(
parameters.artemis_params.detector_params
)

@bpp.finalize_decorator(lambda: tidy_up_plans(fast_grid_scan_composite))
@bpp.subs_decorator(subscriptions.ispyb_handler)
def run_gridscan_and_move_and_tidy(fgs_composite, detector, params, comms):
yield from run_gridscan_and_move(fgs_composite, detector, params, comms)
def run_gridscan_and_move_and_tidy(fgs_composite, params, comms):
yield from run_gridscan_and_move(fgs_composite, params, comms)

return run_gridscan_and_move_and_tidy(
fast_grid_scan_composite, eiger, parameters, subscriptions
fast_grid_scan_composite, parameters, subscriptions
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,16 @@ def event(self, doc: dict):

if event_descriptor.get("name") == ISPYB_PLAN_NAME:
self.params.artemis_params.ispyb_params.undulator_gap = doc["data"][
"fgs_undulator_gap"
"undulator_gap"
]
self.params.artemis_params.ispyb_params.synchrotron_mode = doc["data"][
"fgs_synchrotron_machine_status_synchrotron_mode"
"synchrotron_machine_status_synchrotron_mode"
]
self.params.artemis_params.ispyb_params.slit_gap_size_x = doc["data"][
"fgs_s4_slit_gaps_xgap"
"s4_slit_gaps_xgap"
]
self.params.artemis_params.ispyb_params.slit_gap_size_y = doc["data"][
"fgs_s4_slit_gaps_ygap"
"s4_slit_gaps_ygap"
]

LOGGER.info("Creating ispyb entry.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ class TestData:
"descriptor": "bd45c2e5-2b85-4280-95d7-a9a15800a78b",
"time": 1666604299.828203,
"data": {
"fgs_s4_slit_gaps_xgap": 0.1234,
"fgs_s4_slit_gaps_ygap": 0.2345,
"fgs_synchrotron_machine_status_synchrotron_mode": "test",
"fgs_undulator_gap": 1.234,
"s4_slit_gaps_xgap": 0.1234,
"s4_slit_gaps_ygap": 0.2345,
"synchrotron_machine_status_synchrotron_mode": "test",
"undulator_gap": 1.234,
},
"timestamps": {"det1": 1666604299.8220396, "det2": 1666604299.8235943},
"seq_num": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import pytest
from bluesky.run_engine import RunEngine
from dodal.devices.eiger import DetectorParams, EigerDetector
from dodal.devices.fast_grid_scan_composite import FGSComposite

from artemis.experiment_plans.fast_grid_scan_plan import run_gridscan_and_move
from artemis.experiment_plans.fast_grid_scan_plan import (
FGSComposite,
run_gridscan_and_move,
)
from artemis.external_interaction.callbacks.fgs.fgs_callback_collection import (
FGSCallbackCollection,
)
from artemis.parameters.constants import SIM_BEAMLINE, SIM_INSERTION_PREFIX
from artemis.parameters.constants import SIM_BEAMLINE
from artemis.parameters.internal_parameters import InternalParameters
from artemis.utils import Point3D

Expand Down Expand Up @@ -89,13 +91,10 @@ def test_communicator_in_composite_run(
callbacks.zocalo_handler._run_start = MagicMock()
callbacks.zocalo_handler.xray_centre_motor_position = Point3D(1, 2, 3)

fast_grid_scan_composite = FGSComposite(
insertion_prefix=SIM_INSERTION_PREFIX, name="fgs", prefix=SIM_BEAMLINE
)
fast_grid_scan_composite = FGSComposite()
# this is where it's currently getting stuck:
# fast_grid_scan_composite.fast_grid_scan.is_invalid = lambda: False
# but this is not a solution
fast_grid_scan_composite.wait_for_connection()
# Would be better to use get_plan instead but eiger doesn't work well in S03
RE(run_gridscan_and_move(fast_grid_scan_composite, eiger, params, callbacks))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def wait_for_results(self, fallback_xyz: Point3D) -> Point3D:
self.ispyb.append_to_comment("Found no diffraction.")
xray_centre = fallback_xyz
bbox_size = None
LOGGER.warn(log_msg)
LOGGER.warning(log_msg)

self.processing_time = time.time() - self.processing_start_time
self.ispyb.append_to_comment(
Expand Down
Loading