From 0ddb8ba78ccc52fe0399ac6cd6195ab9f089034a Mon Sep 17 00:00:00 2001 From: ovelle Date: Mon, 1 Jun 2026 17:36:11 -0400 Subject: [PATCH] fix: populate region_shapes for flexible/single/template regions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Only add_region (well-plate) and set_manual_coordinates were populating self.region_shapes. The other add methods — add_flexible_region, add_flexible_region_with_step_size, add_single_fov_region, and add_template_region — wrote region_centers and region_fov_coordinates but skipped region_shapes. validate_region only checks region_centers and region_fov_coordinates, so it returned True for these regions, and the subsequent self.region_shapes[region_id] lookup in get_region_shape raised KeyError. Enabling "Use Focus Map" in flexible multipoint mode goes through region_contains_coordinate -> get_region_shape and crashed. Set region_shapes[region_id] = "Square" in the four missing add methods. region_contains_coordinate only special-cases "Circle" (radius check); rectangular grids correctly fall through to the bounding-box test. --- software/control/core/scan_coordinates.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/software/control/core/scan_coordinates.py b/software/control/core/scan_coordinates.py index 8bfb16765..6718b5ef1 100644 --- a/software/control/core/scan_coordinates.py +++ b/software/control/core/scan_coordinates.py @@ -317,6 +317,7 @@ def add_flexible_region(self, region_id, center_x, center_y, center_z, Nx, Ny, o if scan_coordinates: # Only add region if there are valid coordinates self._log.info(f"Added Flexible Region: {region_id}") self.region_centers[region_id] = [center_x, center_y, center_z] + self.region_shapes[region_id] = "Square" self.region_fov_coordinates[region_id] = scan_coordinates self._update_callback( AddScanCoordinateRegion(fov_centers=FovCenter.from_scan_coordinates(scan_coordinates)) @@ -329,6 +330,7 @@ def add_single_fov_region(self, region_id, center_x, center_y, center_z): raise ValueError(f"FOV with center (x,y)={center_x},{center_y} is not valid, cannot add region.") self.region_centers[region_id] = [center_x, center_y, center_z] + self.region_shapes[region_id] = "Square" self.region_fov_coordinates[region_id] = [(center_x, center_y)] self._update_callback(AddScanCoordinateRegion(fov_centers=[FovCenter(x_mm=center_x, y_mm=center_y)])) @@ -353,6 +355,7 @@ def add_flexible_region_with_step_size(self, region_id, center_x, center_y, cent if scan_coordinates: # Only add region if there are valid coordinates self._log.info(f"Added Flexible Region: {region_id}") self.region_centers[region_id] = [center_x, center_y, center_z] + self.region_shapes[region_id] = "Square" self.region_fov_coordinates[region_id] = scan_coordinates self._update_callback( AddScanCoordinateRegion(fov_centers=FovCenter.from_scan_coordinates(scan_coordinates)) @@ -459,6 +462,7 @@ def add_template_region( if self.validate_coordinates(x, y): scan_coordinates.append((x, y)) self.region_centers[region_id] = [x_mm, y_mm, z_mm] + self.region_shapes[region_id] = "Square" self.region_fov_coordinates[region_id] = scan_coordinates self._update_callback(AddScanCoordinateRegion(fov_centers=FovCenter.from_scan_coordinates(scan_coordinates)))