Skip to content

Commit

Permalink
Rotation plan sets aperture to large by default (#429)
Browse files Browse the repository at this point in the history
* Rotation plan sets aperture to large by default

* Use warning instead of warn to get green ticks

* Move default aperture position to constants

* Use updated ApertureScatterguard

* consistent usage of constants

* readd accidentally removed line
  • Loading branch information
olliesilvester committed Sep 12, 2024
1 parent 027a4e7 commit e6f40a3
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 6 deletions.
7 changes: 7 additions & 0 deletions src/mx_bluesky/hyperion/parameters/constants.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
from enum import Enum

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

Expand Down Expand Up @@ -77,6 +78,11 @@ class GridscanParamConstants:
OMEGA_2 = 90.0


@dataclass(frozen=True)
class RotationParamConstants:
DEFAULT_APERTURE_POSITION = ApertureValue.LARGE


@dataclass(frozen=True)
class DetectorParamConstants:
BEAM_XY_LUT_PATH = (
Expand All @@ -90,6 +96,7 @@ class DetectorParamConstants:
class ExperimentParamConstants:
DETECTOR = DetectorParamConstants()
GRIDSCAN = GridscanParamConstants()
ROTATION = RotationParamConstants()


_test_oav_file = "tests/test_data/test_OAVCentring.json"
Expand Down
23 changes: 20 additions & 3 deletions src/mx_bluesky/hyperion/parameters/rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
from typing import Annotated, Any

from annotated_types import Len
from dodal.devices.aperturescatterguard import ApertureValue
from dodal.devices.detector import DetectorParams
from dodal.devices.zebra import (
RotationDirection,
)
from pydantic import Field, model_validator
from dodal.log import LOGGER
from pydantic import Field, field_validator, model_validator
from scanspec.core import AxesPoints
from scanspec.core import Path as ScanPath
from scanspec.specs import Line
Expand All @@ -25,7 +27,10 @@
TemporaryIspybExtras,
WithScan,
)
from mx_bluesky.hyperion.parameters.constants import CONST, I03Constants
from mx_bluesky.hyperion.parameters.constants import (
CONST,
I03Constants,
)


class RotationScanPerSweep(OptionalGonioAngleStarts, OptionalXyzStarts):
Expand All @@ -45,7 +50,7 @@ class RotationExperiment(DiffractionExperimentWithSample):
)

def _detector_params(self, omega_start_deg: float):
self.det_dist_to_beam_converter_path: str = (
self.det_dist_to_beam_converter_path = (
self.det_dist_to_beam_converter_path
or CONST.PARAM.DETECTOR.BEAM_XY_LUT_PATH
)
Expand All @@ -70,6 +75,18 @@ def _detector_params(self, omega_start_deg: float):
**optional_args,
)

@field_validator("selected_aperture")
@classmethod
def _set_default_aperture_position(cls, aperture_position: ApertureValue | None):
if not aperture_position:
default_aperture = CONST.PARAM.ROTATION.DEFAULT_APERTURE_POSITION
LOGGER.warning(
f"No aperture position selected. Defaulting to {default_aperture}"
)
return default_aperture
else:
return aperture_position


class RotationScan(WithScan, RotationScanPerSweep, RotationExperiment):
@property
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from unittest.mock import patch

import pytest
from bluesky.run_engine import RunEngine
from dodal.devices.aperturescatterguard import ApertureScatterguard, ApertureValue

Expand All @@ -8,13 +9,24 @@
)


@pytest.mark.parametrize(
"set_position",
[
(ApertureValue.SMALL),
(ApertureValue.MEDIUM),
(ApertureValue.ROBOT_LOAD),
(ApertureValue.LARGE),
],
)
async def test_move_aperture_goes_to_correct_position(
aperture_scatterguard: ApertureScatterguard, RE: RunEngine
aperture_scatterguard: ApertureScatterguard,
RE: RunEngine,
set_position,
):
with patch.object(aperture_scatterguard, "set") as mock_set:
RE(move_aperture_if_required(aperture_scatterguard, ApertureValue.LARGE))
RE(move_aperture_if_required(aperture_scatterguard, set_position))
mock_set.assert_called_once_with(
ApertureValue.LARGE,
set_position,
)


Expand Down
10 changes: 10 additions & 0 deletions tests/unit_tests/hyperion/parameters/test_parameter_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from pathlib import Path

import pytest
from dodal.devices.aperturescatterguard import ApertureValue
from pydantic import ValidationError

from mx_bluesky.hyperion.parameters.constants import GridscanParamConstants
Expand Down Expand Up @@ -111,3 +112,12 @@ def test_osc_is_used():
params = RotationScan(**raw_params)
assert params.rotation_increment_deg == osc
assert params.num_images == int(params.scan_width_deg / osc)


def test_selected_aperture_uses_default():
raw_params = raw_params_from_file(
"tests/test_data/parameter_json_files/good_test_rotation_scan_parameters.json"
)
raw_params["selected_aperture"] = None
params = RotationScan(**raw_params)
assert params.selected_aperture == ApertureValue.LARGE

0 comments on commit e6f40a3

Please sign in to comment.