Skip to content

refactor: clamp brightest_coordinate_in_region_from to array bounds#263

Merged
Jammy2211 merged 1 commit intomainfrom
feature/brightest-coordinates-region-refactor
Apr 10, 2026
Merged

refactor: clamp brightest_coordinate_in_region_from to array bounds#263
Jammy2211 merged 1 commit intomainfrom
feature/brightest-coordinates-region-refactor

Conversation

@Jammy2211
Copy link
Copy Markdown
Collaborator

Summary

  • Refactors AbstractArray2D.brightest_coordinate_in_region_from in autoarray/structures/arrays/uniform_2d.py to compute each pixel bound (py_min, py_max, px_min, px_max) via four separate pixel_coordinates_2d_from calls instead of two paired calls — each call now passes a single scaled coordinate on the axis it maps to, which is less fragile than packing two coords of different meaning into one call.
  • Clamps the computed bounds against self.shape_native so regions that extend past the array edge no longer slice off-array.
  • Updates the slice to [py_min : py_max + 1, px_min : px_max + 1] (inclusive end) and adjusts the brightest-pixel index recovery to match the new clamped bounds.

Test plan

  • pytest test_autoarray/structures/arrays/test_uniform_2d.py -k "brightest_coordinate_in_region_from or brightest_sub_pixel_coordinate_in_region_from" — all 11 tests pass (6 pre-existing + 5 new).

New tests added in test_autoarray/structures/arrays/test_uniform_2d.py:

  • test__brightest_coordinate_in_region_from__region_offset_from_origin__correct_peak_coordinate
  • test__brightest_coordinate_in_region_from__region_fully_offset_negative_quadrant__correct_peak_coordinate
  • test__brightest_coordinate_in_region_from__region_offset_positive_quadrant__correct_peak_coordinate
  • test__brightest_coordinate_in_region_from__region_clipped_to_array_bounds__correct_peak_coordinate (exercises the new clamp path)
  • test__brightest_sub_pixel_coordinate_in_region_from__region_offset_from_origin__correct_sub_pixel_peak

🤖 Generated with Claude Code

Compute each pixel bound (py_min/py_max/px_min/px_max) via separate
pixel_coordinates_2d_from calls and clamp against shape_native so a
region that extends past the array edge no longer slices off-array.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Jammy2211 Jammy2211 merged commit 03a3b57 into main Apr 10, 2026
2 checks passed
@Jammy2211 Jammy2211 deleted the feature/brightest-coordinates-region-refactor branch April 10, 2026 14:19
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.

1 participant