Skip to content

Commit

Permalink
Merge pull request #227 from DiamondLightSource/895_hyperion_fgs_dwel…
Browse files Browse the repository at this point in the history
…l_time

Validate the dwell_time parameter's datatype
  • Loading branch information
olliesilvester authored Nov 8, 2023
2 parents 2943074 + ded9d4a commit 8498a43
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/dodal/devices/fast_grid_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class GridScanParams(BaseModel, AbstractExperimentParameterBase):
x_step_size: float = 0.1
y_step_size: float = 0.1
z_step_size: float = 0.1
dwell_time_ms: float = 0.1
dwell_time_ms: float = 10
x_start: float = 0.1
y1_start: float = 0.1
y2_start: float = 0.1
Expand Down Expand Up @@ -91,6 +91,18 @@ def _get_y_axis(cls, y_axis: GridAxis, values: dict[str, Any]) -> GridAxis:
def _get_z_axis(cls, z_axis: GridAxis, values: dict[str, Any]) -> GridAxis:
return GridAxis(values["z2_start"], values["z_step_size"], values["z_steps"])

@validator("dwell_time_ms", always=True, check_fields=True)
def non_integer_dwell_time(cls, dwell_time_ms: float) -> float:
dwell_time_floor_rounded = np.floor(dwell_time_ms)
dwell_time_is_close = np.isclose(
dwell_time_ms, dwell_time_floor_rounded, rtol=1e-3
)
if not dwell_time_is_close:
raise ValueError(
f"Dwell time of {dwell_time_ms}ms is not an integer value. Fast Grid Scan only accepts integer values"
)
return dwell_time_ms

def is_valid(self, limits: XYZLimitBundle) -> bool:
"""
Validates scan parameters
Expand Down
30 changes: 30 additions & 0 deletions tests/devices/unit_tests/test_gridscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,3 +337,33 @@ def test_given_x_y_z_steps_when_full_number_calculated_then_answer_is_as_expecte
grid_scan_params: GridScanParams,
):
assert grid_scan_params.get_num_images() == 350


@pytest.mark.parametrize(
"test_dwell_times, expected_dwell_time_is_integer",
[
(9000, True),
(1000, True),
(100.1, True),
(100.09, True),
(150.7, False),
(10, True),
(99, True),
(59, True),
(0.4, False),
(0.9, False),
(0.44, False),
(0.99, False),
(0.01, False),
(0.09, False),
(0.001, False),
(0.009, False),
],
)
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)
assert params.dwell_time_ms == test_dwell_times
else:
with pytest.raises(ValueError):
GridScanParams(dwell_time_ms=test_dwell_times)

0 comments on commit 8498a43

Please sign in to comment.