Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Zocalo results multiple sources #445

Merged
merged 16 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ dependencies = [
"ophyd == 1.9.0",
"ophyd-async >= 0.3a5",
"bluesky >= 1.13.0a4",
"dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git",
"dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@99b8f494718162a078138a536d0a2f60d020729b"
]


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ def flyscan_xray_centre(
parameters.features.update_self_from_server()
composite.eiger.set_detector_parameters(parameters.detector_params)
composite.zocalo.zocalo_environment = parameters.zocalo_environment
composite.zocalo.use_cpu_and_gpu_zocalo = parameters.use_cpu_and_gpu_zocalo

feature_controlled = _get_feature_controlled(composite, parameters)

Expand Down
1 change: 1 addition & 0 deletions src/mx_bluesky/hyperion/parameters/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class I03Constants:
USE_PANDA_FOR_GRIDSCAN = False
USE_GPU_FOR_GRIDSCAN_ANALYSIS = False
THAWING_TIME = 20
USE_CPU_AND_GPU_ZOCALO = False


@dataclass(frozen=True)
Expand Down
1 change: 1 addition & 0 deletions src/mx_bluesky/hyperion/parameters/gridscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class GridCommon(
)
use_panda: bool = Field(default=CONST.I03.USE_PANDA_FOR_GRIDSCAN)
use_gpu: bool = Field(default=CONST.I03.USE_GPU_FOR_GRIDSCAN_ANALYSIS)
use_cpu_and_gpu_zocalo: bool = Field(default=CONST.I03.USE_CPU_AND_GPU_ZOCALO)
ispyb_experiment_type: IspybExperimentType = Field(
default=IspybExperimentType.GRIDSCAN_3D
)
Expand Down
24 changes: 20 additions & 4 deletions src/mx_bluesky/hyperion/parameters/rotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@
import os
from collections.abc import Iterator
from itertools import accumulate
from typing import Annotated
from typing import Annotated, Any

from annotated_types import Len
from dodal.devices.aperturescatterguard import AperturePositionGDANames
from dodal.devices.detector import DetectorParams
from dodal.devices.detector.det_dist_to_beam_converter import (
DetectorDistanceToBeamXYConverter,
)
from dodal.devices.zebra import (
RotationDirection,
)
from pydantic import Field, root_validator
from dodal.log import LOGGER
from pydantic import Field, root_validator, validator
from scanspec.core import AxesPoints
from scanspec.core import Path as ScanPath
from scanspec.specs import Line
Expand All @@ -33,6 +35,8 @@
)
from mx_bluesky.hyperion.parameters.constants import CONST, I03Constants

DEFAULT_APERTURE_POSITION = AperturePositionGDANames.LARGE_APERTURE


class RotationScanPerSweep(OptionalGonioAngleStarts, OptionalXyzStarts):
omega_start_deg: float = Field(default=0) # type: ignore
Expand All @@ -51,7 +55,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 Down Expand Up @@ -79,6 +83,18 @@ def _detector_params(self, omega_start_deg: float):
**optional_args,
)

@validator("selected_aperture")
def _set_default_aperture_position(
cls, aperture_position: AperturePositionGDANames | None
):
if not aperture_position:
LOGGER.warning(
f"No aperture position selected. Defaulting to {DEFAULT_APERTURE_POSITION}"
)
return DEFAULT_APERTURE_POSITION
else:
return aperture_position


class RotationScan(WithScan, RotationScanPerSweep, RotationExperiment):
@property
Expand Down Expand Up @@ -131,7 +147,7 @@ def _single_rotation_scan(self, scan: RotationScanPerSweep) -> RotationScan:
return RotationScan(**params)

@root_validator(pre=False) # type: ignore
def validate_snapshot_directory(cls, values):
def validate_snapshot_directory(cls, values: dict[str, Any]) -> dict[str, Any]:
start_img = 0
for scan in values["rotation_scans"]:
scan.nexus_vds_start_img = start_img
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 (
AperturePosition,
Expand All @@ -12,17 +13,25 @@
)


@pytest.mark.parametrize(
"gda_position, set_position",
[
(AperturePositionGDANames.SMALL_APERTURE, AperturePosition.SMALL),
(AperturePositionGDANames.MEDIUM_APERTURE, AperturePosition.MEDIUM),
(AperturePositionGDANames.ROBOT_LOAD, AperturePosition.ROBOT_LOAD),
(AperturePositionGDANames.LARGE_APERTURE, AperturePosition.LARGE),
],
)
async def test_move_aperture_goes_to_correct_position(
aperture_scatterguard: ApertureScatterguard, RE: RunEngine
aperture_scatterguard: ApertureScatterguard,
RE: RunEngine,
gda_position,
set_position,
):
with patch.object(aperture_scatterguard, "set") as mock_set:
RE(
move_aperture_if_required(
aperture_scatterguard, AperturePositionGDANames.LARGE_APERTURE
)
)
RE(move_aperture_if_required(aperture_scatterguard, gda_position))
mock_set.assert_called_once_with(
AperturePosition.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 AperturePositionGDANames
from pydantic import ValidationError

from mx_bluesky.hyperion.parameters.gridscan import (
Expand Down Expand Up @@ -110,3 +111,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 == AperturePositionGDANames.LARGE_APERTURE
Loading