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 1033_clarify_desired_transmission
Browse files Browse the repository at this point in the history
  • Loading branch information
dperl-dls committed Apr 3, 2024
2 parents 9602e39 + cfc7796 commit 5458fd5
Show file tree
Hide file tree
Showing 29 changed files with 88 additions and 200 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ markers = [
addopts = "--cov=src/hyperion --cov-report term --cov-report xml:cov.xml"
testpaths = "tests"


[tool.ruff]
src = ["src", "tests"]
line-length = 88
Expand Down
55 changes: 4 additions & 51 deletions src/hyperion/device_setup_plans/setup_oav.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,61 +4,24 @@
import bluesky.plan_stubs as bps
import numpy as np
from bluesky.utils import Msg
from dodal.devices.areadetector.plugins.MXSC import MXSC, PinTipDetect
from dodal.devices.oav.oav_calculations import camera_coordinates_to_xyz
from dodal.devices.oav.oav_detector import OAV, OAVConfigParams
from dodal.devices.oav.oav_errors import OAVError_ZoomLevelNotFound
from dodal.devices.oav.oav_parameters import OAVParameters
from dodal.devices.oav.pin_image_recognition import PinTipDetection
from dodal.devices.oav.utils import ColorMode, EdgeOutputArrayImageType
from dodal.devices.oav.utils import ColorMode
from dodal.devices.smargon import Smargon

from hyperion.exceptions import WarningException
from hyperion.log import LOGGER

Pixel = Tuple[int, int]
oav_group = "oav_setup"
# Helper function to make sure we set the waiting groups correctly
set_using_group = partial(bps.abs_set, group=oav_group)


def start_mxsc(oav: OAV, min_callback_time, filename):
"""
Sets PVs relevant to edge detection plugin.
Args:
min_callback_time: the value to set the minimum callback time to
filename: filename of the python script to detect edge waveforms from camera stream.
Returns: None
"""
# Turns the area detector plugin on
yield from set_using_group(oav.mxsc.enable_callbacks, 1)

# Set the minimum time between updates of the plugin
yield from set_using_group(oav.mxsc.min_callback_time, min_callback_time)

# Stop the plugin from blocking the IOC and hogging all the CPU
yield from set_using_group(oav.mxsc.blocking_callbacks, 0)

# Set the python file to use for calculating the edge waveforms
current_filename = yield from bps.rd(oav.mxsc.filename)
if current_filename != filename:
LOGGER.info(
f"Current OAV MXSC plugin python file is {current_filename}, setting to {filename}"
)
yield from set_using_group(oav.mxsc.filename, filename)
yield from set_using_group(oav.mxsc.read_file, 1)

# Image annotations
yield from set_using_group(oav.mxsc.draw_tip, True)
yield from set_using_group(oav.mxsc.draw_edges, True)

# Use the original image type for the edge output array
yield from set_using_group(oav.mxsc.output_array, EdgeOutputArrayImageType.ORIGINAL)


def setup_pin_tip_detection_params(
pin_tip_detect_device: MXSC | PinTipDetection, parameters: OAVParameters
pin_tip_detect_device: PinTipDetection, parameters: OAVParameters
):
# select which blur to apply to image
yield from set_using_group(
Expand Down Expand Up @@ -102,7 +65,7 @@ def setup_pin_tip_detection_params(
def pre_centring_setup_oav(
oav: OAV,
parameters: OAVParameters,
pin_tip_detection_device: PinTipDetection | MXSC,
pin_tip_detection_device: PinTipDetection,
):
"""
Setup OAV PVs with required values.
Expand All @@ -114,12 +77,6 @@ def pre_centring_setup_oav(

yield from setup_pin_tip_detection_params(pin_tip_detection_device, parameters)

yield from start_mxsc(
oav,
parameters.min_callback_time,
parameters.detection_script_filename,
)

zoom_level_str = f"{float(parameters.zoom)}x"
if zoom_level_str not in oav.zoom_controller.allowed_zoom_levels:
raise OAVError_ZoomLevelNotFound(
Expand All @@ -132,10 +89,6 @@ def pre_centring_setup_oav(
wait=True,
)

# Connect MXSC output to MJPG input for debugging
if isinstance(pin_tip_detection_device, MXSC):
yield from set_using_group(oav.snapshot.input_plugin, "OAV.MXSC")

yield from bps.wait(oav_group)

"""
Expand Down Expand Up @@ -178,7 +131,7 @@ def get_move_required_so_that_beam_is_at_pixel(


def wait_for_tip_to_be_found(
ophyd_pin_tip_detection: PinTipDetection | PinTipDetect,
ophyd_pin_tip_detection: PinTipDetection,
) -> Generator[Msg, None, Pixel]:
yield from bps.trigger(ophyd_pin_tip_detection, wait=True)
found_tip = yield from bps.rd(ophyd_pin_tip_detection.triggered_tip)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ def pin_centre_then_xray_centre_plan(
pin_tip_centring_composite,
parameters.experiment_params.tip_offset_microns,
oav_config_file,
parameters.experiment_params.use_ophyd_pin_tip_detect,
)

grid_detect_params = create_parameters_for_grid_detection(parameters)
Expand Down
20 changes: 5 additions & 15 deletions src/hyperion/experiment_plans/pin_tip_centring_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import numpy as np
from blueapi.core import BlueskyContext
from bluesky.utils import Msg
from dodal.devices.areadetector.plugins.MXSC import PinTipDetect
from dodal.devices.backlight import Backlight
from dodal.devices.oav.oav_detector import OAV
from dodal.devices.oav.oav_parameters import OAV_CONFIG_JSON, OAVParameters
Expand Down Expand Up @@ -41,7 +40,7 @@ def create_devices(context: BlueskyContext) -> PinTipCentringComposite:


def trigger_and_return_pin_tip(
pin_tip: PinTipDetect | PinTipDetection,
pin_tip: PinTipDetection,
) -> Generator[Msg, None, Pixel]:
yield from bps.trigger(pin_tip, wait=True)
tip_x_y_px = yield from bps.rd(pin_tip.triggered_tip)
Expand All @@ -50,7 +49,7 @@ def trigger_and_return_pin_tip(


def move_pin_into_view(
pin_tip_device: PinTipDetect | PinTipDetection,
pin_tip_device: PinTipDetection,
smargon: Smargon,
step_size_mm: float = DEFAULT_STEP_SIZE,
max_steps: int = 2,
Expand All @@ -60,7 +59,7 @@ def move_pin_into_view(
would take it past its limit, it moves to the limit instead.
Args:
pin_tip_device (PinTipDetect | PinTipDetection): The device being used to detect the pin
pin_tip_device (PinTipDetection): The device being used to detect the pin
smargon (Smargon): The gonio to move the tip
step_size (float, optional): Distance to move the gonio (in mm) for each
step of the search. Defaults to 0.5.
Expand Down Expand Up @@ -134,7 +133,6 @@ def pin_tip_centre_plan(
composite: PinTipCentringComposite,
tip_offset_microns: float,
oav_config_file: str = OAV_CONFIG_JSON,
use_ophyd_pin_tip_detect: bool = False,
):
"""Finds the tip of the pin and moves to roughly the centre based on this tip. Does
this at both the current omega angle and +90 deg from this angle so as to get a
Expand All @@ -143,19 +141,13 @@ def pin_tip_centre_plan(
Args:
tip_offset_microns (float): The x offset from the tip where the centre is assumed
to be.
use_ophyd_pin_tip_detect (bool): If true use the ophyd device to find the tip,
rather than the AD plugin.
"""
oav: OAV = composite.oav
smargon: Smargon = composite.smargon
oav_params = OAVParameters("pinTipCentring", oav_config_file)

if use_ophyd_pin_tip_detect:
pin_tip_setup = composite.pin_tip_detection
pin_tip_detect = composite.pin_tip_detection
else:
pin_tip_setup = oav.mxsc
pin_tip_detect = oav.mxsc.pin_tip
pin_tip_setup = composite.pin_tip_detection
pin_tip_detect = composite.pin_tip_detection

assert oav.parameters.micronsPerXPixel is not None
tip_offset_px = int(tip_offset_microns / oav.parameters.micronsPerXPixel)
Expand All @@ -174,8 +166,6 @@ def offset_and_move(tip: Pixel):
# See #673 for improvements
yield from bps.sleep(0.3)

# Set up the old pin tip centring as we will need it for grid detection. Remove once #1068 is done
yield from pre_centring_setup_oav(oav, oav_params, oav.mxsc)
yield from pre_centring_setup_oav(oav, oav_params, pin_tip_setup)

tip = yield from move_pin_into_view(pin_tip_detect, smargon)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ class PinCentreThenXrayCentreParams(AbstractExperimentWithBeamParams):
# Whether to set the stub offsets after centering
set_stub_offsets: bool = False

# Whether to use the ophyd device for tip centring rather than the area detector
# plugin
use_ophyd_pin_tip_detect: bool = False

# Distance for the smargon to accelerate into the grid and decelerate out of the grid when using the panda
run_up_distance_mm: float = 0.15

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ class RobotLoadThenCentreParams(AbstractExperimentWithBeamParams):
# Use constant motion panda scans instead of fast grid scans
use_panda: bool = False

# Whether to use the ophyd device for tip centring rather than the area detector
# plugin
use_ophyd_pin_tip_detect: bool = False

def get_num_images(self):
return 0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
"omega_start": {
"type": "number"
},
"use_ophyd_pin_tip_detect": {
"type": "boolean"
},
"requested_energy_kev": {
"type": [
"number",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"type": "object",
"properties": {
"params_version": {
"const": "5.0.0"
"const": "4.0.5"
},
"hyperion_params": {
"type": "object",
Expand Down
5 changes: 5 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,11 @@ def flux():
return i03.flux(fake_with_ophyd_sim=True)


@pytest.fixture
def pin_tip():
return i03.pin_tip_detection(fake_with_ophyd_sim=True)


@pytest.fixture
def ophyd_pin_tip_detection():
RunEngine() # A RE is needed to start the bluesky loop
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"params_version": "5.0.0",
"params_version": "4.0.5",
"hyperion_params": {
"beamline": "BL03S",
"insertion_prefix": "SR03S",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"params_version": "5.0.0",
"params_version": "4.0.5",
"hyperion_params": {
"beamline": "BL03S",
"insertion_prefix": "SR03S",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"params_version": "5.0.0",
"params_version": "4.0.5",
"hyperion_params": {
"beamline": "BL03S",
"insertion_prefix": "SR03S",
Expand Down Expand Up @@ -43,7 +43,6 @@
"tip_offset_microns": 108.9,
"grid_width_microns": 290.6,
"oav_centring_file": "tests/test_data/test_OAVCentring.json",
"use_ophyd_pin_tip_detect": true,
"transmission_fraction": 1.0
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"params_version": "5.0.0",
"params_version": "4.0.5",
"hyperion_params": {
"zocalo_environment": "artemis",
"beamline": "BL03I",
Expand Down Expand Up @@ -37,7 +37,6 @@
"exposure_time": 0.004,
"detector_distance": 255,
"snapshot_dir": "/tmp",
"use_ophyd_pin_tip_detect": true,
"requested_energy_kev": 11.1,
"sample_puck": 40,
"sample_pin": 3
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"params_version": "5.0.0",
"params_version": "4.0.5",
"hyperion_params": {
"zocalo_environment": "artemis",
"beamline": "BL03I",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"params_version": "5.0.0",
"params_version": "4.0.5",
"hyperion_params": {
"beamline": "BL03S",
"insertion_prefix": "SR03S",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"params_version": "5.0.0",
"params_version": "4.0.5",
"hyperion_params": {
"beamline": "BL03S",
"insertion_prefix": "SR03S",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"params_version": "5.0.0",
"params_version": "4.0.5",
"hyperion_params": {
"beamline": "BL03S",
"insertion_prefix": "SR03S",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"params_version": "5.0.0",
"params_version": "4.0.5",
"hyperion_params": {
"beamline": "BL03I",
"insertion_prefix": "SR03I",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"params_version": "5.0.0",
"params_version": "4.0.5",
"hyperion_params": {
"beamline": "BL03I",
"insertion_prefix": "SR03I",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"params_version": "5.0.0",
"params_version": "4.0.5",
"hyperion_params": {
"beamline": "BL03I",
"insertion_prefix": "SR03I",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"params_version": "5.0.0",
"params_version": "4.0.5",
"hyperion_params": {
"zocalo_environment": "dev_artemis",
"beamline": "BL03S",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"params_version": "5.0.0",
"params_version": "4.0.5",
"hyperion_params": {
"zocalo_environment": "dev_artemis",
"beamline": "BL03S",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"params_version": "5.0.0",
"params_version": "4.0.5",
"hyperion_params": {
"zocalo_environment": "dev_artemis",
"beamline": "BL03S",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"params_version": "5.0.0",
"params_version": "4.0.5",
"hyperion_params": {
"zocalo_environment": "dev_artemis",
"beamline": "BL03S",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_data/parameter_json_files/test_parameters.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"params_version": "5.0.0",
"params_version": "4.0.5",
"hyperion_params": {
"beamline": "BL03S",
"insertion_prefix": "SR03S",
Expand Down
1 change: 0 additions & 1 deletion tests/unit_tests/device_setup_plans/test_setup_oav.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ def test_when_set_up_oav_with_different_zoom_levels_then_flat_field_applied_corr

RE = RunEngine()
RE(pre_centring_setup_oav(oav, mock_parameters, ophyd_pin_tip_detection))
assert oav.mxsc.input_plugin.get() == expected_plugin
assert oav.snapshot.input_plugin.get() == expected_plugin


Expand Down
Loading

0 comments on commit 5458fd5

Please sign in to comment.