Skip to content

Commit

Permalink
Move Hyperion constants and read_hardware_for_zocalo plan, and remove…
Browse files Browse the repository at this point in the history
… pre_plans
  • Loading branch information
olliesilvester committed Aug 20, 2024
1 parent 0da52c9 commit 7a76b60
Show file tree
Hide file tree
Showing 3 changed files with 168 additions and 7 deletions.
10 changes: 10 additions & 0 deletions src/mx_bluesky/device_setup_plans/read_hardware_for_setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import bluesky.plan_stubs as bps
from dodal.devices.eiger import EigerDetector

from mx_bluesky.i03.parameters.constants import CONST


def read_hardware_for_zocalo(detector: EigerDetector):
yield from bps.create(name=CONST.DESCRIPTORS.ZOCALO_HW_READ)
yield from bps.read(detector.odin.file_writer.id)
yield from bps.save()
149 changes: 149 additions & 0 deletions src/mx_bluesky/i03/parameters/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
import os
from enum import Enum

from dodal.devices.detector import EIGER2_X_16M_SIZE
from pydantic.dataclasses import dataclass

TEST_MODE = os.environ.get("HYPERION_TEST_MODE")


@dataclass(frozen=True)
class SimConstants:
BEAMLINE = "BL03S"
INSERTION_PREFIX = "SR03S"
ZOCALO_ENV = "dev_artemis"
# this one is for unit tests
ISPYB_CONFIG = "tests/test_data/test_config.cfg"
# this one is for system tests
DEV_ISPYB_DATABASE_CFG = "/dls_sw/dasc/mariadb/credentials/ispyb-hyperion-dev.cfg"


@dataclass(frozen=True)
class PlanNameConstants:
# Robot load subplan
ROBOT_LOAD = "robot_load"
# Gridscan
GRID_DETECT_AND_DO_GRIDSCAN = "grid_detect_and_do_gridscan"
GRID_DETECT_INNER = "grid_detect"
GRIDSCAN_OUTER = "run_gridscan_move_and_tidy"
GRIDSCAN_AND_MOVE = "run_gridscan_and_move"
GRIDSCAN_MAIN = "run_gridscan"
DO_FGS = "do_fgs"
# Rotation scan
ROTATION_MULTI = "multi_rotation_wrapper"
ROTATION_OUTER = "rotation_scan_with_cleanup"
ROTATION_MAIN = "rotation_scan_main"


@dataclass(frozen=True)
class PlanGroupCheckpointConstants:
# For places to synchronise / stop and wait in plans, use as bluesky group names
# Gridscan
GRID_READY_FOR_DC = "ready_for_data_collection"
MOVE_GONIO_TO_START = "move_gonio_to_start"


@dataclass(frozen=True)
class DocDescriptorNames:
# Robot load event descriptor
ROBOT_LOAD = "robot_load"
# For callbacks to use
OAV_ROTATION_SNAPSHOT_TRIGGERED = "rotation_snapshot_triggered"
OAV_GRID_SNAPSHOT_TRIGGERED = "snapshot_to_ispyb"
HARDWARE_READ_PRE = "read_hardware_for_callbacks_pre_collection"
HARDWARE_READ_DURING = "read_hardware_for_callbacks_during_collection"
ZOCALO_HW_READ = "zocalo_read_hardware_plan"


@dataclass(frozen=True)
class HardwareConstants:
OAV_REFRESH_DELAY = 0.3
PANDA_FGS_RUN_UP_DEFAULT = 0.17
CRYOJET_MARGIN_MM = 0.2


@dataclass(frozen=True)
class TriggerConstants:
ZOCALO = "trigger_zocalo_on"


@dataclass(frozen=True)
class GridscanParamConstants:
WIDTH_UM = 600.0
EXPOSURE_TIME_S = 0.02
USE_ROI = True
BOX_WIDTH_UM = 20.0
OMEGA_1 = 0.0
OMEGA_2 = 90.0


@dataclass(frozen=True)
class DetectorParamConstants:
BEAM_XY_LUT_PATH = (
"tests/test_data/test_det_dist_converter.txt"
if TEST_MODE
else "/dls_sw/i03/software/daq_configuration/lookup/DetDistToBeamXYConverter.txt"
)


@dataclass(frozen=True)
class ExperimentParamConstants:
DETECTOR = DetectorParamConstants()
GRIDSCAN = GridscanParamConstants()


_test_oav_file = "tests/test_data/test_OAVCentring.json"
_live_oav_file = "/dls_sw/i03/software/daq_configuration/json/OAVCentring_hyperion.json"


@dataclass(frozen=True)
class I03Constants:
BASE_DATA_DIR = "/tmp/dls/i03/data/" if TEST_MODE else "/dls/i03/data/"
BEAMLINE = "BL03S" if TEST_MODE else "BL03I"
DETECTOR = EIGER2_X_16M_SIZE
INSERTION_PREFIX = "SR03S" if TEST_MODE else "SR03I"
OAV_CENTRING_FILE = _test_oav_file if TEST_MODE else _live_oav_file
SHUTTER_TIME_S = 0.06
USE_PANDA_FOR_GRIDSCAN = False
USE_GPU_FOR_GRIDSCAN_ANALYSIS = False
THAWING_TIME = 20


@dataclass(frozen=True)
class HyperionConstants:
HARDWARE = HardwareConstants()
I03 = I03Constants()
PARAM = ExperimentParamConstants()
PLAN = PlanNameConstants()
WAIT = PlanGroupCheckpointConstants()
SIM = SimConstants()
TRIGGER = TriggerConstants()
CALLBACK_0MQ_PROXY_PORTS = (5577, 5578)
DESCRIPTORS = DocDescriptorNames()
CONFIG_SERVER_URL = (
"http://fake-url-not-real"
if TEST_MODE
else "https://daq-config.diamond.ac.uk/api"
)
GRAYLOG_PORT = 12232
PARAMETER_SCHEMA_DIRECTORY = "src/hyperion/parameters/schemas/"
ZOCALO_ENV = "dev_artemis" if TEST_MODE else "artemis"


CONST = HyperionConstants()


class Actions(Enum):
START = "start"
STOP = "stop"
SHUTDOWN = "shutdown"
STATUS = "status"


class Status(Enum):
WARN = "Warn"
FAILED = "Failed"
SUCCESS = "Success"
BUSY = "Busy"
ABORTING = "Aborting"
IDLE = "Idle"
16 changes: 9 additions & 7 deletions src/mx_bluesky/plan_stubs/do_fgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@
from dodal.log import LOGGER
from dodal.plans.check_topup import check_topup_and_wait_if_necessary

from mx_bluesky.device_setup_plans.read_hardware_for_setup import (
read_hardware_for_zocalo,
)


def do_fgs(
grid_scan_device: FastGridScanCommon,
detector: EigerDetector, # Once Eiger inherits from StandardDetector, use that type instead
synchrotron: Synchrotron,
pre_plans: Optional[Callable] = None,
post_plans: Optional[Callable] = None,
during_collection_plans: Optional[Callable] = None,
):
"""Triggers a grid scan motion program and waits for completion, accounting for synchrotron topup.
Optionally run other plans kickoff and between kickoff and completion. A bluesky run MUST be open before this plan is
Expand All @@ -25,7 +28,7 @@ def do_fgs(
detector (EigerDetector)
synchrotron (Synchrotron): Synchrotron device
pre_plans (Optional, Callable): Generic plan called just before kickoff, eg zocalo setup. Parameters specified in higher-level plans.
post_plans (Optional, Callable): Generic plan called just before complete, eg waiting on zocalo.
during_collection_plans (Optional, Callable): Generic plan called in between kickoff but and completion, eg waiting on zocalo.
"""

expected_images = yield from bps.rd(grid_scan_device.expected_images)
Expand All @@ -36,15 +39,14 @@ def do_fgs(
expected_images * exposure_sec_per_image,
30.0,
)
if pre_plans:
yield from pre_plans()
read_hardware_for_zocalo(detector)
LOGGER.info("Wait for all moves with no assigned group")
yield from bps.wait()
LOGGER.info("kicking off FGS")
yield from bps.kickoff(grid_scan_device, wait=True)
gridscan_start_time = time()
if post_plans:
yield from post_plans()
if during_collection_plans:
yield from during_collection_plans()
LOGGER.info("completing FGS")
yield from bps.complete(grid_scan_device, wait=True)
# Remove this logging statement once metrics have been added
Expand Down

0 comments on commit 7a76b60

Please sign in to comment.