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

Move transmission to the experiment param base class #394

Merged
merged 3 commits into from
Apr 4, 2024
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
6 changes: 3 additions & 3 deletions src/dodal/devices/fast_grid_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
Signal,
)
from ophyd.status import DeviceStatus, StatusBase
from pydantic import BaseModel, validator
from pydantic import validator
from pydantic.dataclasses import dataclass

from dodal.devices.motors import XYZLimitBundle
from dodal.devices.status import await_value
from dodal.log import LOGGER
from dodal.parameters.experiment_parameter_base import AbstractExperimentParameterBase
from dodal.parameters.experiment_parameter_base import AbstractExperimentWithBeamParams


@dataclass
Expand All @@ -44,7 +44,7 @@ def is_within(self, steps):
return 0 <= steps <= self.full_steps


class GridScanParamsCommon(BaseModel, AbstractExperimentParameterBase):
class GridScanParamsCommon(AbstractExperimentWithBeamParams):
"""
Common holder class for the parameters of a grid scan in a similar
layout to EPICS. The parameters and functions of this class are common
Expand Down
10 changes: 9 additions & 1 deletion src/dodal/parameters/experiment_parameter_base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
from abc import ABC, abstractmethod

from pydantic import BaseModel


class AbstractExperimentParameterBase(BaseModel, ABC):
pass


class AbstractExperimentWithBeamParams(AbstractExperimentParameterBase):
transmission_fraction: float
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't we always need a transmission fraction? Could this just be in the original AbstractExperimentParameterBase?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we might want to expose endpoints which only do things without beam, e.g. optical centring, or load a sample only, and those don't need transmission


class AbstractExperimentParameterBase(ABC):
@abstractmethod
def get_num_images(self) -> int:
pass
10 changes: 8 additions & 2 deletions tests/devices/system_tests/test_gridscan_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ def test_when_program_data_set_and_staged_then_expected_images_correct(
fast_grid_scan: FastGridScan,
):
RE = RunEngine()
RE(set_fast_grid_scan_params(fast_grid_scan, GridScanParams(x_steps=2, y_steps=2)))
RE(
set_fast_grid_scan_params(
fast_grid_scan,
GridScanParams(transmission_fraction=0.01, x_steps=2, y_steps=2),
)
)
assert fast_grid_scan.expected_images.get() == 2 * 2
fast_grid_scan.stage()
assert fast_grid_scan.position_counter.get() == 0
Expand All @@ -44,7 +49,8 @@ def test_given_valid_params_when_kickoff_then_completion_status_increases_and_fi
):
def set_and_wait_plan(fast_grid_scan: FastGridScan):
yield from set_fast_grid_scan_params(
fast_grid_scan, GridScanParams(x_steps=3, y_steps=3)
fast_grid_scan,
GridScanParams(transmission_fraction=0.01, x_steps=3, y_steps=3),
)
yield from wait_for_fgs_valid(fast_grid_scan)

Expand Down
29 changes: 24 additions & 5 deletions tests/devices/unit_tests/test_gridscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,12 @@ def run_test_on_complete_watcher(
RE = RunEngine()
RE(
set_fast_grid_scan_params(
fast_grid_scan, GridScanParams(x_steps=num_pos_1d, y_steps=num_pos_1d)
fast_grid_scan,
GridScanParams(
x_steps=num_pos_1d,
y_steps=num_pos_1d,
transmission_fraction=0.01,
),
)
)

Expand Down Expand Up @@ -146,7 +151,10 @@ def test_running_finished_with_all_images_done_then_complete_status_finishes_not
RE = RunEngine()
RE(
set_fast_grid_scan_params(
fast_grid_scan, GridScanParams(x_steps=num_pos_1d, y_steps=num_pos_1d)
fast_grid_scan,
GridScanParams(
transmission_fraction=0.01, x_steps=num_pos_1d, y_steps=num_pos_1d
),
)
)

Expand Down Expand Up @@ -212,7 +220,9 @@ def test_within_limits_check(position, expected_in_limit):
)
def test_scan_within_limits_1d(start, steps, size, expected_in_limits):
motor_bundle = create_motor_bundle_with_limits(0.0, 10.0)
grid_params = GridScanParams(x_start=start, x_steps=steps, x_step_size=size)
grid_params = GridScanParams(
transmission_fraction=0.01, x_start=start, x_steps=steps, x_step_size=size
)
assert grid_params.is_valid(motor_bundle.get_xyz_limits()) == expected_in_limits


Expand All @@ -229,6 +239,7 @@ def test_scan_within_limits_2d(
):
motor_bundle = create_motor_bundle_with_limits(0.0, 10.0)
grid_params = GridScanParams(
transmission_fraction=0.01,
x_start=x_start,
x_steps=x_steps,
x_step_size=x_size,
Expand Down Expand Up @@ -285,6 +296,7 @@ def test_scan_within_limits_3d(
):
motor_bundle = create_motor_bundle_with_limits(0.0, 10.0)
grid_params = GridScanParams(
transmission_fraction=0.01,
x_start=x_start,
x_steps=x_steps,
x_step_size=x_size,
Expand All @@ -303,6 +315,7 @@ def test_scan_within_limits_3d(
@pytest.fixture
def grid_scan_params():
yield GridScanParams(
transmission_fraction=0.01,
x_steps=10,
y_steps=15,
z_steps=20,
Expand Down Expand Up @@ -404,8 +417,14 @@ def test_given_x_y_z_steps_when_full_number_calculated_then_answer_is_as_expecte
)
def test_non_test_integer_dwell_time(test_dwell_times, expected_dwell_time_is_integer):
if expected_dwell_time_is_integer:
params = GridScanParams(dwell_time_ms=test_dwell_times)
params = GridScanParams(
dwell_time_ms=test_dwell_times,
transmission_fraction=0.01,
)
assert params.dwell_time_ms == test_dwell_times
else:
with pytest.raises(ValueError):
GridScanParams(dwell_time_ms=test_dwell_times)
GridScanParams(
dwell_time_ms=test_dwell_times,
transmission_fraction=0.01,
)
7 changes: 6 additions & 1 deletion tests/devices/unit_tests/test_panda_gridscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ def test_running_finished_with_all_images_done_then_complete_status_finishes_not
RE = RunEngine()
RE(
set_fast_grid_scan_params(
fast_grid_scan, PandAGridScanParams(x_steps=num_pos_1d, y_steps=num_pos_1d)
fast_grid_scan,
PandAGridScanParams(
x_steps=num_pos_1d,
y_steps=num_pos_1d,
transmission_fraction=0.01,
),
)
)

Expand Down
Loading