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

Commit

Permalink
Merge branch 'main' into 1372_enable_dev_shm_on_gda_property
Browse files Browse the repository at this point in the history
  • Loading branch information
DominicOram committed May 22, 2024
2 parents bb79dd3 + 54c986a commit 1cd023d
Show file tree
Hide file tree
Showing 90 changed files with 851 additions and 3,710 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ install_requires =
ophyd-async >= 0.3a5
bluesky >= 1.13.0a3
blueapi >= 0.4.3-a1
dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@4123dada042d62a750194d7c715662a3690cf25c
dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@ba2e0da424cf7a82e724f278b668987575cf8a52

[options.entry_points]
console_scripts =
Expand Down
4 changes: 1 addition & 3 deletions src/hyperion/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,7 @@ def compose_start_args(context: BlueskyContext, plan_name: str, action: Actions)
if experiment_registry_entry is None:
raise PlanNotFound(f"Experiment plan '{plan_name}' not found in registry.")

experiment_internal_param_type = experiment_registry_entry.get(
"internal_param_type"
)
experiment_internal_param_type = experiment_registry_entry.get("param_type")
callback_type = experiment_registry_entry.get("callback_collection_type")
plan = context.plan_functions.get(plan_name)
if experiment_internal_param_type is None:
Expand Down
43 changes: 8 additions & 35 deletions src/hyperion/experiment_plans/experiment_registry.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
from __future__ import annotations

from typing import Callable, TypedDict, Union

from dodal.devices.fast_grid_scan import GridScanParams
from dodal.devices.panda_fast_grid_scan import PandAGridScanParams
from dodal.parameters.experiment_parameter_base import AbstractExperimentWithBeamParams
from typing import Callable, TypedDict

import hyperion.experiment_plans.flyscan_xray_centre_plan as flyscan_xray_centre_plan
import hyperion.experiment_plans.panda_flyscan_xray_centre_plan as panda_flyscan_xray_centre_plan
Expand All @@ -26,18 +22,6 @@
RobotLoadThenCentre,
ThreeDGridScan,
)
from hyperion.parameters.plan_specific.grid_scan_with_edge_detect_params import (
GridScanWithEdgeDetectParams,
)
from hyperion.parameters.plan_specific.pin_centre_then_xray_centre_params import (
PinCentreThenXrayCentreParams,
)
from hyperion.parameters.plan_specific.robot_load_then_center_params import (
RobotLoadThenCentreParams,
)
from hyperion.parameters.plan_specific.rotation_scan_internal_params import (
RotationScanParams,
)
from hyperion.parameters.rotation import RotationScan


Expand All @@ -51,59 +35,48 @@ def do_nothing():

class ExperimentRegistryEntry(TypedDict):
setup: Callable
internal_param_type: type[
param_type: type[
ThreeDGridScan
| GridScanWithEdgeDetect
| RotationScan
| PinTipCentreThenXrayCentre
| RobotLoadThenCentre
]
experiment_param_type: type[AbstractExperimentWithBeamParams]
callbacks_factory: CallbacksFactory


EXPERIMENT_TYPES = Union[GridScanParams, RotationScanParams]
PLAN_REGISTRY: dict[str, ExperimentRegistryEntry] = {
"panda_flyscan_xray_centre": {
"setup": panda_flyscan_xray_centre_plan.create_devices,
"internal_param_type": ThreeDGridScan,
"experiment_param_type": PandAGridScanParams,
"param_type": ThreeDGridScan,
"callbacks_factory": create_gridscan_callbacks,
},
"flyscan_xray_centre": {
"setup": flyscan_xray_centre_plan.create_devices,
"internal_param_type": ThreeDGridScan,
"experiment_param_type": GridScanParams,
"param_type": ThreeDGridScan,
"callbacks_factory": create_gridscan_callbacks,
},
"grid_detect_then_xray_centre": {
"setup": grid_detect_then_xray_centre_plan.create_devices,
"internal_param_type": GridScanWithEdgeDetect,
"experiment_param_type": GridScanWithEdgeDetectParams,
"param_type": GridScanWithEdgeDetect,
"callbacks_factory": create_gridscan_callbacks,
},
"rotation_scan": {
"setup": rotation_scan_plan.create_devices,
"internal_param_type": RotationScan,
"experiment_param_type": RotationScanParams,
"param_type": RotationScan,
"callbacks_factory": create_rotation_callbacks,
},
"pin_tip_centre_then_xray_centre": {
"setup": pin_centre_then_xray_centre_plan.create_devices,
"internal_param_type": PinTipCentreThenXrayCentre,
"experiment_param_type": PinCentreThenXrayCentreParams,
"param_type": PinTipCentreThenXrayCentre,
"callbacks_factory": create_gridscan_callbacks,
},
"robot_load_then_centre": {
"setup": robot_load_then_centre_plan.create_devices,
"internal_param_type": RobotLoadThenCentre,
"experiment_param_type": RobotLoadThenCentreParams,
"param_type": RobotLoadThenCentre,
"callbacks_factory": create_robot_load_and_centre_callbacks,
},
}
EXPERIMENT_NAMES = list(PLAN_REGISTRY.keys())
EXPERIMENT_TYPE_LIST = [p["experiment_param_type"] for p in PLAN_REGISTRY.values()]
EXPERIMENT_TYPE_DICT = dict(zip(EXPERIMENT_NAMES, EXPERIMENT_TYPE_LIST))


class PlanNotFound(Exception):
Expand Down
12 changes: 6 additions & 6 deletions src/hyperion/experiment_plans/flyscan_xray_centre_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ def kickoff_and_complete_gridscan(
synchrotron: Synchrotron,
zocalo_environment: str,
scan_points: list[AxesPoints[Axis]],
scan_start_indices: list[int],
):
@TRACER.start_as_current_span(CONST.PLAN.DO_FGS)
@bpp.set_run_key_decorator(CONST.PLAN.DO_FGS)
Expand All @@ -173,6 +174,7 @@ def kickoff_and_complete_gridscan(
"subplan_name": CONST.PLAN.DO_FGS,
"zocalo_environment": zocalo_environment,
"scan_points": scan_points,
"scan_start_indices": scan_start_indices,
}
)
@bpp.contingency_decorator(
Expand Down Expand Up @@ -261,10 +263,8 @@ def run_gridscan(
fgs_composite.eiger,
fgs_composite.synchrotron,
parameters.zocalo_environment,
[
parameters.old_parameters().get_scan_points(1),
parameters.old_parameters().get_scan_points(2),
],
[parameters.scan_points_first_grid, parameters.scan_points_second_grid],
parameters.scan_indices,
)
yield from bps.abs_set(fgs_motors.z_steps, 0, wait=False)

Expand Down Expand Up @@ -349,7 +349,7 @@ def flyscan_xray_centre(
at any point in it.
Args:
parameters (FGSInternalParameters): The parameters to run the scan.
parameters (ThreeDGridScan): The parameters to run the scan.
Returns:
Generator: The plan for the gridscan
Expand All @@ -363,7 +363,7 @@ def flyscan_xray_centre(
md={
"subplan_name": CONST.PLAN.GRIDSCAN_OUTER,
CONST.TRIGGER.ZOCALO: CONST.PLAN.DO_FGS,
"hyperion_internal_parameters": parameters.old_parameters().json(),
"hyperion_parameters": parameters.json(),
"activate_callbacks": [
"GridscanNexusFileCallback",
],
Expand Down
10 changes: 4 additions & 6 deletions src/hyperion/experiment_plans/panda_flyscan_xray_centre_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,8 @@ def run_gridscan(
fgs_composite.eiger,
fgs_composite.synchrotron,
parameters.zocalo_environment,
[
parameters.old_parameters().get_scan_points(1),
parameters.old_parameters().get_scan_points(2),
],
[parameters.scan_points_first_grid, parameters.scan_points_second_grid],
parameters.scan_indices,
)

yield from bps.abs_set(fgs_motors.z_steps, 0, wait=False)
Expand Down Expand Up @@ -266,7 +264,7 @@ def panda_flyscan_xray_centre(
at any point in it.
Args:
parameters (FGSInternalParameters): The parameters to run the scan.
parameters (ThreeDGridScan): The parameters to run the scan.
Returns:
Generator: The plan for the gridscan
Expand All @@ -281,7 +279,7 @@ def panda_flyscan_xray_centre(
md={
"subplan_name": CONST.PLAN.GRIDSCAN_OUTER,
CONST.TRIGGER.ZOCALO: CONST.PLAN.DO_FGS,
"hyperion_internal_parameters": parameters.old_parameters().json(),
"hyperion_parameters": parameters.json(),
"activate_callbacks": [
"GridscanNexusFileCallback",
],
Expand Down
2 changes: 1 addition & 1 deletion src/hyperion/experiment_plans/rotation_scan_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def rotation_scan(
md={
"subplan_name": CONST.PLAN.ROTATION_OUTER,
CONST.TRIGGER.ZOCALO: CONST.PLAN.ROTATION_MAIN,
"hyperion_internal_parameters": parameters.old_parameters().json(),
"hyperion_parameters": parameters.json(),
"activate_callbacks": [
"RotationISPyBCallback",
"RotationNexusFileCallback",
Expand Down
36 changes: 15 additions & 21 deletions src/hyperion/external_interaction/callbacks/common/ispyb_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@
get_current_time_string,
)
from hyperion.log import ISPYB_LOGGER
from hyperion.parameters.components import DiffractionExperimentWithSample


def populate_data_collection_group(
experiment_type: str, detector_params: DetectorParams, ispyb_params: IspybParams
):
def populate_data_collection_group(params: DiffractionExperimentWithSample):
dcg_info = DataCollectionGroupInfo(
visit_string=get_visit_string(ispyb_params, detector_params),
experiment_type=experiment_type,
sample_id=ispyb_params.sample_id,
visit_string=params.visit,
experiment_type=params.ispyb_experiment_type.value,
sample_id=params.sample_id,
)
return dcg_info

Expand All @@ -47,38 +46,33 @@ def populate_remaining_data_collection_info(
comment,
data_collection_group_id,
data_collection_info: DataCollectionInfo,
detector_params,
ispyb_params,
params: DiffractionExperimentWithSample,
):
data_collection_info.visit_string = get_visit_string(ispyb_params, detector_params)
data_collection_info.visit_string = params.visit
data_collection_info.parent_id = data_collection_group_id
data_collection_info.sample_id = ispyb_params.sample_id
data_collection_info.sample_id = params.sample_id
data_collection_info.detector_id = I03_EIGER_DETECTOR
data_collection_info.axis_start = data_collection_info.omega_start
data_collection_info.focal_spot_size_at_samplex = ispyb_params.focal_spot_size_x
data_collection_info.focal_spot_size_at_sampley = ispyb_params.focal_spot_size_y
data_collection_info.beamsize_at_samplex = ispyb_params.beam_size_x
data_collection_info.beamsize_at_sampley = ispyb_params.beam_size_y
data_collection_info.comments = comment
data_collection_info.detector_distance = detector_params.detector_distance
data_collection_info.exp_time = detector_params.exposure_time
data_collection_info.imgdir = detector_params.directory
data_collection_info.imgprefix = detector_params.prefix
data_collection_info.detector_distance = params.detector_params.detector_distance
data_collection_info.exp_time = params.detector_params.exposure_time
data_collection_info.imgdir = params.detector_params.directory
data_collection_info.imgprefix = params.detector_params.prefix
data_collection_info.imgsuffix = EIGER_FILE_SUFFIX
# Both overlap and n_passes included for backwards compatibility,
# planned to be removed later
data_collection_info.n_passes = 1
data_collection_info.overlap = 0
data_collection_info.start_image_number = 1
beam_position = detector_params.get_beam_position_mm(
detector_params.detector_distance
beam_position = params.detector_params.get_beam_position_mm(
params.detector_params.detector_distance
)
data_collection_info.xbeam = beam_position[0]
data_collection_info.ybeam = beam_position[1]
data_collection_info.start_time = get_current_time_string()
# temporary file template until nxs filewriting is integrated and we can use
# that file name
data_collection_info.file_template = f"{detector_params.prefix}_{data_collection_info.data_collection_number}_master.h5"
data_collection_info.file_template = f"{params.detector_params.prefix}_{data_collection_info.data_collection_number}_master.h5"
return data_collection_info


Expand Down
28 changes: 15 additions & 13 deletions src/hyperion/external_interaction/callbacks/ispyb_callback_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from collections.abc import Sequence
from typing import TYPE_CHECKING, Any, Callable, Dict, Optional, TypeVar

from dodal.beamline_specific_utils.i03 import beam_size_from_aperture
from dodal.devices.aperturescatterguard import SingleAperturePosition
from dodal.devices.detector.det_resolution import resolution
from dodal.devices.synchrotron import SynchrotronMode

Expand All @@ -25,14 +27,8 @@
)
from hyperion.external_interaction.ispyb.ispyb_utils import get_ispyb_config
from hyperion.log import ISPYB_LOGGER, set_dcgid_tag
from hyperion.parameters.components import DiffractionExperimentWithSample
from hyperion.parameters.constants import CONST
from hyperion.parameters.internal_parameters import InternalParameters
from hyperion.parameters.plan_specific.gridscan_internal_params import (
GridscanInternalParameters,
)
from hyperion.parameters.plan_specific.rotation_scan_internal_params import (
RotationInternalParameters,
)
from hyperion.utils.utils import convert_eV_to_angstrom

from .logging_callback import format_doc_for_log
Expand All @@ -54,9 +50,7 @@ def __init__(
ISPYB_LOGGER.debug("Initialising ISPyB callback")
super().__init__(log=ISPYB_LOGGER, emit=emit)
self._oav_snapshot_event_idx: int = 0
self.params: GridscanInternalParameters | RotationInternalParameters | None = (
None
)
self.params: DiffractionExperimentWithSample | None = None
self.ispyb: StoreInIspyb
self.descriptors: Dict[str, EventDescriptor] = {}
self.ispyb_config = get_ispyb_config()
Expand Down Expand Up @@ -115,7 +109,15 @@ def _handle_ispyb_hardware_read(self, doc) -> Sequence[ScanDataInfo]:
synchrotron_mode := doc["data"]["synchrotron-synchrotron_mode"],
SynchrotronMode,
)
aperture_size = SingleAperturePosition(
**doc["data"]["aperture_scatterguard-selected_aperture"]
)
beamsize = beam_size_from_aperture(aperture_size)
hwscan_data_collection_info = DataCollectionInfo(
beamsize_at_samplex=beamsize.x_um,
beamsize_at_sampley=beamsize.y_um,
focal_spot_size_at_samplex=beamsize.x_um,
focal_spot_size_at_sampley=beamsize.y_um,
undulator_gap1=doc["data"]["undulator-current_gap"],
synchrotron_mode=synchrotron_mode.value,
slitgap_horizontal=doc["data"]["s4_slit_gaps_xgap"],
Expand Down Expand Up @@ -186,9 +188,9 @@ def _handle_ispyb_transmission_flux_read(self, doc) -> Sequence[ScanDataInfo]:
wavelength_angstroms = convert_eV_to_angstrom(energy_ev)
hwscan_data_collection_info.wavelength = wavelength_angstroms
hwscan_data_collection_info.resolution = resolution(
self.params.hyperion_params.detector_params,
self.params.detector_params,
wavelength_angstroms,
self.params.hyperion_params.detector_params.detector_distance,
self.params.detector_params.detector_distance,
)
scan_data_infos = self.populate_info_for_update(
hwscan_data_collection_info, self.params
Expand All @@ -200,7 +202,7 @@ def _handle_ispyb_transmission_flux_read(self, doc) -> Sequence[ScanDataInfo]:
def populate_info_for_update(
self,
event_sourced_data_collection_info: DataCollectionInfo,
params: InternalParameters,
params: DiffractionExperimentWithSample,
) -> Sequence[ScanDataInfo]:
pass

Expand Down
Loading

0 comments on commit 1cd023d

Please sign in to comment.