Skip to content

Commit c4fe49f

Browse files
committed
move from pixel coordinates
1 parent 1460984 commit c4fe49f

2 files changed

Lines changed: 36 additions & 33 deletions

File tree

autoarray/mask/mask_2d_util.py

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -119,44 +119,15 @@ def mask_2d_circular_annular_from(
119119
"""
120120
centres_scaled = mask_2d_centres_from(shape_native, pixel_scales, centre)
121121

122-
y, x = np.ogrid[:shape_native[0], :shape_native[1]]
122+
y, x = np.ogrid[: shape_native[0], : shape_native[1]]
123123
y_scaled = (y - centres_scaled[0]) * pixel_scales[0]
124124
x_scaled = (x - centres_scaled[1]) * pixel_scales[1]
125125

126126
distances_squared = x_scaled**2 + y_scaled**2
127127

128-
return ~((distances_squared >= inner_radius**2) & (distances_squared <= outer_radius**2))
129-
130-
131-
def mask_2d_via_pixel_coordinates_from(
132-
shape_native: Tuple[int, int], pixel_coordinates: [list], buffer: int = 0
133-
) -> np.ndarray:
134-
"""
135-
Returns a mask where all unmasked `False` entries are defined from an input list of list of pixel coordinates.
136-
137-
These may be buffed via an input ``buffer``, whereby all entries in all 8 neighboring directions by this
138-
amount.
139-
140-
Parameters
141-
----------
142-
shape_native (int, int)
143-
The (y,x) shape of the mask in units of pixels.
144-
pixel_coordinates : [[int, int]]
145-
The input lists of 2D pixel coordinates where `False` entries are created.
146-
buffer
147-
All input ``pixel_coordinates`` are buffed with `False` entries in all 8 neighboring directions by this
148-
amount.
149-
"""
150-
151-
mask_2d = np.full(shape=shape_native, fill_value=True)
152-
153-
for y, x in pixel_coordinates:
154-
mask_2d[y, x] = False
155-
156-
if buffer == 0:
157-
return mask_2d
158-
else:
159-
return buffed_mask_2d_from(mask_2d=mask_2d, buffer=buffer)
128+
return ~(
129+
(distances_squared >= inner_radius**2) & (distances_squared <= outer_radius**2)
130+
)
160131

161132

162133
@numba_util.jit()
@@ -342,6 +313,37 @@ def mask_2d_elliptical_annular_from(
342313
return mask_2d
343314

344315

316+
def mask_2d_via_pixel_coordinates_from(
317+
shape_native: Tuple[int, int], pixel_coordinates: [list], buffer: int = 0
318+
) -> np.ndarray:
319+
"""
320+
Returns a mask where all unmasked `False` entries are defined from an input list of list of pixel coordinates.
321+
322+
These may be buffed via an input ``buffer``, whereby all entries in all 8 neighboring directions by this
323+
amount.
324+
325+
Parameters
326+
----------
327+
shape_native (int, int)
328+
The (y,x) shape of the mask in units of pixels.
329+
pixel_coordinates : [[int, int]]
330+
The input lists of 2D pixel coordinates where `False` entries are created.
331+
buffer
332+
All input ``pixel_coordinates`` are buffed with `False` entries in all 8 neighboring directions by this
333+
amount.
334+
"""
335+
336+
mask_2d = np.full(shape=shape_native, fill_value=True)
337+
338+
for y, x in pixel_coordinates:
339+
mask_2d[y, x] = False
340+
341+
if buffer == 0:
342+
return mask_2d
343+
else:
344+
return buffed_mask_2d_from(mask_2d=mask_2d, buffer=buffer)
345+
346+
345347
@numba_util.jit()
346348
def blurring_mask_2d_from(
347349
mask_2d: np.ndarray, kernel_shape_native: Tuple[int, int]

test_autoarray/mask/test_mask_2d.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ def test__circular_annular():
141141
assert mask.origin == (0.0, 0.0)
142142
assert mask.mask_centre == (0.0, 0.0)
143143

144+
144145
def test__elliptical():
145146
mask_via_util = aa.util.mask_2d.mask_2d_elliptical_from(
146147
shape_native=(8, 5),

0 commit comments

Comments
 (0)