Skip to content

Commit

Permalink
black
Browse files Browse the repository at this point in the history
  • Loading branch information
Jammy2211 committed Dec 12, 2024
1 parent ce815ed commit 100e521
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
18 changes: 13 additions & 5 deletions autoarray/structures/arrays/uniform_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ def brightest_coordinate_in_region_from(
)

def brightest_sub_pixel_coordinate_in_region_from(
self, region: Optional[Tuple[float, float, float, float]], box_size : int = 1
self, region: Optional[Tuple[float, float, float, float]], box_size: int = 1
) -> Tuple[float, float]:
"""
Returns the brightest sub-pixel in the array inside an input region of form (y0, y1, x0, x1) where
Expand All @@ -430,9 +430,15 @@ def brightest_sub_pixel_coordinate_in_region_from(
"""
brightest_pixel = self.brightest_coordinate_in_region_from(region=region)

y, x = self.geometry.pixel_coordinates_2d_from(scaled_coordinates_2d=brightest_pixel)
region_start_y, region_end_y = max(0, y - box_size), min(self.shape_native[0], y + box_size + 1)
region_start_x, region_end_x = max(0, x - box_size), min(self.shape_native[1], x + box_size + 1)
y, x = self.geometry.pixel_coordinates_2d_from(
scaled_coordinates_2d=brightest_pixel
)
region_start_y, region_end_y = max(0, y - box_size), min(
self.shape_native[0], y + box_size + 1
)
region_start_x, region_end_x = max(0, x - box_size), min(
self.shape_native[1], x + box_size + 1
)
region = self.native[region_start_y:region_end_y, region_start_x:region_end_x]

y_indices, x_indices = np.meshgrid(
Expand All @@ -445,7 +451,9 @@ def brightest_sub_pixel_coordinate_in_region_from(
subpixel_y = np.sum(weights * y_indices.flatten()) / np.sum(weights)
subpixel_x = np.sum(weights * x_indices.flatten()) / np.sum(weights)

return self.geometry.scaled_coordinates_2d_from(pixel_coordinates_2d=(subpixel_y, subpixel_x))
return self.geometry.scaled_coordinates_2d_from(
pixel_coordinates_2d=(subpixel_y, subpixel_x)
)

def zoomed_around_mask(self, buffer: int = 1) -> "Array2D":
"""
Expand Down
1 change: 0 additions & 1 deletion test_autoarray/structures/arrays/test_uniform_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,6 @@ def test__brightest_pixel_in_region_from():
assert brightest_coordinate == pytest.approx((-0.1, 0.2), 1.0e-4)



def test__brightest_sub_pixel_in_region_from():
mask = aa.Mask2D.all_false(shape_native=(4, 4), pixel_scales=0.1)
array_2d = aa.Array2D(
Expand Down

0 comments on commit 100e521

Please sign in to comment.