Skip to content

fix: populate region_shapes for flexible/single/template regions#554

Open
mpiersonsmela wants to merge 1 commit into
Cephla-Lab:masterfrom
mpiersonsmela:fix/focus-map-region-shapes-keyerror
Open

fix: populate region_shapes for flexible/single/template regions#554
mpiersonsmela wants to merge 1 commit into
Cephla-Lab:masterfrom
mpiersonsmela:fix/focus-map-region-shapes-keyerror

Conversation

@mpiersonsmela
Copy link
Copy Markdown

Summary

Fixes a KeyError that crashes the GUI when enabling Use Focus Map in flexible-multipoint acquisition after loading a region list.

Bug

File "control/core/scan_coordinates.py", line 614, in get_region_shape
    return self.region_shapes[region_id]
KeyError: 'R0'

Repro: switch to flexible multipoint, load a list of regions (e.g. R0..R3), check Use Focus Map → crash.

Root cause

ScanCoordinates keeps three parallel dicts keyed by region_id: region_centers, region_fov_coordinates, and region_shapes. Only add_region (well-plate) and set_manual_coordinates populate region_shapes. The other four add methods write the first two dicts but skip region_shapes:

  • add_flexible_region
  • add_flexible_region_with_step_size
  • add_single_fov_region
  • add_template_region

validate_region only checks region_centers and region_fov_coordinates, so it returns True for these regions and the subsequent self.region_shapes[region_id] lookup in get_region_shape raises KeyError. The focus-map grid generator hits this path through region_contains_coordinateget_region_shape.

Fix

Set self.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, so "Square" is the right value for these grid-based regions.

Test plan

  • Reproduce the crash on master: load region list in flexible mode, enable Use Focus Map → KeyError
  • Apply fix → enabling Use Focus Map works without exception
  • Regression: well-plate mode and manual ROI still produce correct shape behavior (Circle/Square/Manual)

🤖 Generated with Claude Code

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants