From 46a05b48e0893f0307f2a7df060acac108b4f57d Mon Sep 17 00:00:00 2001 From: appel_c Date: Fri, 3 Jul 2026 12:34:07 +0200 Subject: [PATCH] fix(cont-grid): add extra point in lines to include endpoint --- csaxs_bec/scans/scans_v4/cont_grid.py | 13 +++++++------ tests/tests_scans/test_cont_grid_scan.py | 22 +++++++++++++++++----- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/csaxs_bec/scans/scans_v4/cont_grid.py b/csaxs_bec/scans/scans_v4/cont_grid.py index 691c823..f9c7f32 100644 --- a/csaxs_bec/scans/scans_v4/cont_grid.py +++ b/csaxs_bec/scans/scans_v4/cont_grid.py @@ -141,12 +141,13 @@ class ContGrid(ScanBase): or setting up the devices. """ self._check_motor_inputs() - frames_per_trigger = int( - np.ceil(np.abs(self.fast_end - self.fast_start) / self.fast_step_size) - ) - self._cont_motor_params["num_lines"] = int( - np.ceil(np.abs(self.stepper_stop - self.stepper_start) / self.stepper_step_size) - ) + frames_per_trigger = ( + int(np.ceil(np.abs(self.fast_end - self.fast_start) / self.fast_step_size)) + 1 + ) # include last point + self._cont_motor_params["num_lines"] = ( + int(np.ceil(np.abs(self.stepper_stop - self.stepper_start) / self.stepper_step_size)) + + 1 + ) # include last point positions = position_generators.nd_grid_positions( [ (self.fast_start, self.fast_end, frames_per_trigger), diff --git a/tests/tests_scans/test_cont_grid_scan.py b/tests/tests_scans/test_cont_grid_scan.py index 90ece7d..efeec8d 100644 --- a/tests/tests_scans/test_cont_grid_scan.py +++ b/tests/tests_scans/test_cont_grid_scan.py @@ -115,11 +115,23 @@ def test_cont_grid_prepare_scan_keeps_generated_positions_stable(v4_scan_assembl scan.prepare_scan() - assert np.array_equal(scan.positions, np.array([[1.0, -2.0], [1.0, 2.0]])) - assert scan.scan_info.frames_per_trigger == 2 - assert scan._cont_motor_params["num_lines"] == 2 - assert scan.scan_info.additional_scan_parameters["num_lines"] == 2 + assert np.array_equal(scan.positions, np.array([[1.0, -2.0], [1.0, 0.0], [1.0, 2.0]])) + assert scan.scan_info.frames_per_trigger == 3 + assert scan._cont_motor_params["num_lines"] == 3 + assert scan.scan_info.additional_scan_parameters["num_lines"] == 3 assert np.array_equal( scan.scan_info.additional_scan_parameters["computed_positions"], - np.array([[-1.0, -2.0], [1.0, -2.0], [-1.0, 2.0], [1.0, 2.0]]), + np.array( + [ + [-1.0, -2.0], + [0.0, -2.0], + [1.0, -2.0], + [-1.0, 0.0], + [0.0, 0.0], + [1.0, 0.0], + [-1.0, 2.0], + [0.0, 2.0], + [1.0, 2.0], + ] + ), )