Skip to content

Commit

Permalink
(DiamondLightSource/hyperion#895) Corrected dwell_time validator for …
Browse files Browse the repository at this point in the history
…milliseconds and changed subsequent tests for good coverage
  • Loading branch information
subinsaji committed Nov 7, 2023
1 parent 9692d1a commit ded9d4a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
13 changes: 6 additions & 7 deletions 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 @@ -93,14 +93,13 @@ def _get_z_axis(cls, z_axis: GridAxis, values: dict[str, Any]) -> GridAxis:

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

Expand Down
31 changes: 16 additions & 15 deletions tests/devices/unit_tests/test_gridscan.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,21 +342,22 @@ def test_given_x_y_z_steps_when_full_number_calculated_then_answer_is_as_expecte
@pytest.mark.parametrize(
"test_dwell_times, expected_dwell_time_is_integer",
[
(0.001, True),
(0.009, True),
(0.005, True),
(0.0011, True),
(0.0051, True),
(0.0099, True),
(0.0059, False),
(0.0004, False),
(0.0009, False),
(0.00044, False),
(0.00099, False),
(0.00001, False),
(0.00009, False),
(0.000001, False),
(0.000009, False),
(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):
Expand Down

0 comments on commit ded9d4a

Please sign in to comment.