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

1217 Use event from grid detect to do ispyb deposition #1279

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions src/hyperion/device_setup_plans/read_hardware_for_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def read_hardware_for_ispyb_pre_collection(
):
LOGGER.info("Reading status of beamline for ispyb deposition, pre collection.")
yield from bps.create(
name=CONST.PLAN.ISPYB_HARDWARE_READ
name=CONST.DESCRIPTORS.ISPYB_HARDWARE_READ
) # gives name to event *descriptor* document
yield from bps.read(undulator.current_gap)
yield from bps.read(synchrotron.synchrotron_mode)
Expand All @@ -39,20 +39,20 @@ def read_hardware_for_ispyb_during_collection(
attenuator: Attenuator, flux: Flux, dcm: DCM
):
LOGGER.info("Reading status of beamline for ispyb deposition, during collection.")
yield from bps.create(name=CONST.PLAN.ISPYB_TRANSMISSION_FLUX_READ)
yield from bps.create(name=CONST.DESCRIPTORS.ISPYB_TRANSMISSION_FLUX_READ)
yield from bps.read(attenuator.actual_transmission)
yield from bps.read(flux.flux_reading)
yield from bps.read(dcm.energy_in_kev)
yield from bps.save()


def read_hardware_for_nexus_writer(detector: EigerDetector):
yield from bps.create(name=CONST.PLAN.NEXUS_READ)
yield from bps.create(name=CONST.DESCRIPTORS.NEXUS_READ)
yield from bps.read(detector.bit_depth)
yield from bps.save()


def read_hardware_for_zocalo(detector: EigerDetector):
yield from bps.create(name=CONST.PLAN.ZOCALO_HW_READ)
yield from bps.create(name=CONST.DESCRIPTORS.ZOCALO_HW_READ)
yield from bps.read(detector.odin.file_writer.id)
yield from bps.save()
1 change: 0 additions & 1 deletion src/hyperion/experiment_plans/flyscan_xray_centre_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,6 @@ def flyscan_xray_centre(
CONST.TRIGGER.ZOCALO: CONST.PLAN.DO_FGS,
"hyperion_internal_parameters": old_parameters.json(),
"activate_callbacks": [
"GridscanISPyBCallback",
"GridscanNexusFileCallback",
],
}
Expand Down
32 changes: 13 additions & 19 deletions src/hyperion/experiment_plans/grid_detect_then_xray_centre_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import json
from typing import Any, Union

import numpy as np
from blueapi.core import BlueskyContext, MsgGenerator
from bluesky import plan_stubs as bps
from bluesky import preprocessors as bpp
Expand Down Expand Up @@ -49,8 +48,8 @@
from hyperion.external_interaction.callbacks.grid_detection_callback import (
GridDetectionCallback,
)
from hyperion.external_interaction.callbacks.oav_snapshot_callback import (
OavSnapshotCallback,
from hyperion.external_interaction.callbacks.xray_centre.ispyb_callback import (
ispyb_activation_wrapper,
)
from hyperion.log import LOGGER
from hyperion.parameters.gridscan import GridScanWithEdgeDetect
Expand Down Expand Up @@ -134,6 +133,16 @@ def detect_grid_and_do_gridscan(
composite: GridDetectThenXRayCentreComposite,
parameters: GridScanWithEdgeDetectInternalParameters,
oav_params: OAVParameters,
):
yield from ispyb_activation_wrapper(
_detect_grid_and_do_gridscan(composite, parameters, oav_params), parameters
)


def _detect_grid_and_do_gridscan(
composite: GridDetectThenXRayCentreComposite,
parameters: GridScanWithEdgeDetectInternalParameters,
oav_params: OAVParameters,
):
assert composite.aperture_scatterguard.aperture_positions is not None
experiment_params: GridScanWithEdgeDetectParams = parameters.experiment_params
Expand All @@ -143,15 +152,14 @@ def detect_grid_and_do_gridscan(
f"{detector_params.prefix}_{detector_params.run_number}_{{angle}}"
)

oav_callback = OavSnapshotCallback()
grid_params_callback = GridDetectionCallback(
composite.oav.parameters,
experiment_params.exposure_time,
experiment_params.set_stub_offsets,
experiment_params.run_up_distance_mm,
)

@bpp.subs_decorator([oav_callback, grid_params_callback])
@bpp.subs_decorator([grid_params_callback])
def run_grid_detection_plan(
oav_params,
snapshot_template,
Expand All @@ -178,20 +186,6 @@ def run_grid_detection_plan(
experiment_params.snapshot_dir,
)

# Hack because GDA only passes 3 values to ispyb
out_upper_left = np.array(
oav_callback.out_upper_left[0] + [oav_callback.out_upper_left[1][1]]
)

# Hack because the callback returns the list in inverted order
parameters.hyperion_params.ispyb_params.xtal_snapshots_omega_start = (
oav_callback.snapshot_filenames[0][::-1]
)
parameters.hyperion_params.ispyb_params.xtal_snapshots_omega_end = (
oav_callback.snapshot_filenames[1][::-1]
)
parameters.hyperion_params.ispyb_params.upper_left = out_upper_left

yield from bps.abs_set(composite.backlight, Backlight.OUT)

LOGGER.info(
Expand Down
4 changes: 1 addition & 3 deletions src/hyperion/experiment_plans/oav_grid_detection_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from typing import TYPE_CHECKING, Tuple

import bluesky.plan_stubs as bps
import bluesky.preprocessors as bpp
import numpy as np
from blueapi.core import BlueskyContext
from dodal.devices.backlight import Backlight
Expand Down Expand Up @@ -57,7 +56,6 @@ def get_min_and_max_y_of_pin(
return min_y, max_y


@bpp.run_decorator()
def grid_detection_plan(
composite: OavGridDetectionComposite,
parameters: OAVParameters,
Expand Down Expand Up @@ -159,7 +157,7 @@ def grid_detection_plan(
yield from bps.abs_set(oav.snapshot.directory, snapshot_dir)
yield from bps.trigger(oav.snapshot, wait=True)

yield from bps.create("snapshot_to_ispyb")
yield from bps.create(CONST.DESCRIPTORS.OAV_SNAPSHOT_TRIGGERED)

yield from bps.read(oav.snapshot)
yield from bps.read(smargon)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ def panda_flyscan_xray_centre(
CONST.TRIGGER.ZOCALO: CONST.PLAN.DO_FGS,
"hyperion_internal_parameters": parameters.json(),
"activate_callbacks": [
"GridscanISPyBCallback",
"GridscanNexusFileCallback",
],
}
Expand Down
4 changes: 3 additions & 1 deletion src/hyperion/experiment_plans/robot_load_then_centre_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,16 @@ def robot_load():

yield from bps.wait("robot_load")

yield from bps.create(name=CONST.PLAN.ROBOT_LOAD)
yield from bps.create(name=CONST.DESCRIPTORS.ROBOT_LOAD)
yield from bps.read(composite.robot.barcode)
yield from bps.save()

yield from wait_for_smargon_not_disabled(composite.smargon)

yield from robot_load()

# XXX 1278 this effectively casts between unrelated types which doesn't have all
# attributes needed for downstream e.g. grid_width_microns
params_json = json.loads(parameters.json())
pin_centre_params = PinCentreThenXrayCentreInternalParameters(**params_json)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from __future__ import annotations

import re
from dataclasses import dataclass
from typing import Optional, Union
from typing import Optional

from dodal.devices.detector import DetectorParams
from numpy import ndarray

from hyperion.external_interaction.ispyb.data_model import (
DataCollectionGroupInfo,
Expand Down Expand Up @@ -50,7 +48,7 @@ def populate_data_collection_position_info(ispyb_params):


def populate_remaining_data_collection_info(
comment_constructor,
comment,
data_collection_group_id,
data_collection_info: DataCollectionInfo,
detector_params,
Expand All @@ -65,7 +63,7 @@ def populate_remaining_data_collection_info(
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_constructor()
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
Expand Down Expand Up @@ -123,10 +121,3 @@ def get_xtal_snapshots(ispyb_params):
ISPYB_LOGGER.warning("No xtal snapshot paths sent to ISPyB!")
xtal_snapshots = []
return xtal_snapshots + [None] * (3 - len(xtal_snapshots))


@dataclass
class GridScanInfo:
upper_left: Union[list[int], ndarray]
y_steps: int
y_step_size: float
Loading
Loading