Skip to content

Commit 1da50f4

Browse files
authored
Merge pull request #163 from Jammy2211/feature/mask_2d_util_to_numpy
feature/mask 2d util to numpy
2 parents 61bc511 + bbed38d commit 1da50f4

File tree

15 files changed

+578
-1121
lines changed

15 files changed

+578
-1121
lines changed

autoarray/geometry/geometry_util.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def convert_pixel_scales_2d(pixel_scales: ty.PixelScales) -> Tuple[float, float]
182182

183183
@numba_util.jit()
184184
def central_pixel_coordinates_2d_from(
185-
shape_native: Tuple[int, int]
185+
shape_native: Tuple[int, int],
186186
) -> Tuple[float, float]:
187187
"""
188188
Returns the central pixel coordinates of a 2D geometry (and therefore a 2D data structure like an ``Array2D``)
@@ -477,7 +477,6 @@ def grid_pixels_2d_slim_from(
477477
pixel_scales=(0.5, 0.5), origin=(0.0, 0.0))
478478
"""
479479

480-
481480
centres_scaled = central_scaled_coordinate_2d_from(
482481
shape_native=shape_native, pixel_scales=pixel_scales, origin=origin
483482
)
@@ -544,7 +543,6 @@ def grid_pixel_centres_2d_slim_from(
544543
pixel_scales=(0.5, 0.5), origin=(0.0, 0.0))
545544
"""
546545

547-
548546
centres_scaled = central_scaled_coordinate_2d_from(
549547
shape_native=shape_native, pixel_scales=pixel_scales, origin=origin
550548
)
@@ -629,8 +627,10 @@ def grid_pixel_indexes_2d_slim_from(
629627

630628
if use_jax:
631629
grid_pixel_indexes_2d_slim = (
632-
grid_pixels_2d_slim * np.array([shape_native[1], 1])
633-
).sum(axis=1).astype(int)
630+
(grid_pixels_2d_slim * np.array([shape_native[1], 1]))
631+
.sum(axis=1)
632+
.astype(int)
633+
)
634634
else:
635635
grid_pixel_indexes_2d_slim = np.zeros(grid_pixels_2d_slim.shape[0])
636636

@@ -690,7 +690,9 @@ def grid_scaled_2d_slim_from(
690690
centres_scaled = np.array(centres_scaled)
691691
pixel_scales = np.array(pixel_scales)
692692
sign = np.array([-1, 1])
693-
grid_scaled_2d_slim = (grid_pixels_2d_slim - centres_scaled - 0.5) * pixel_scales * sign
693+
grid_scaled_2d_slim = (
694+
(grid_pixels_2d_slim - centres_scaled - 0.5) * pixel_scales * sign
695+
)
694696
else:
695697
grid_scaled_2d_slim = np.zeros((grid_pixels_2d_slim.shape[0], 2))
696698

@@ -755,7 +757,7 @@ def grid_pixel_centres_2d_from(
755757
centres_scaled = np.array(centres_scaled)
756758
pixel_scales = np.array(pixel_scales)
757759
sign = np.array([-1.0, 1.0])
758-
grid_pixels_2d = (
760+
grid_pixels_2d = (
759761
(sign * grid_scaled_2d / pixel_scales) + centres_scaled + 0.5
760762
).astype(int)
761763
else:
@@ -764,17 +766,21 @@ def grid_pixel_centres_2d_from(
764766
for y in range(grid_scaled_2d.shape[0]):
765767
for x in range(grid_scaled_2d.shape[1]):
766768
grid_pixels_2d[y, x, 0] = int(
767-
(-grid_scaled_2d[y, x, 0] / pixel_scales[0]) + centres_scaled[0] + 0.5
769+
(-grid_scaled_2d[y, x, 0] / pixel_scales[0])
770+
+ centres_scaled[0]
771+
+ 0.5
768772
)
769773
grid_pixels_2d[y, x, 1] = int(
770-
(grid_scaled_2d[y, x, 1] / pixel_scales[1]) + centres_scaled[1] + 0.5
774+
(grid_scaled_2d[y, x, 1] / pixel_scales[1])
775+
+ centres_scaled[1]
776+
+ 0.5
771777
)
772778

773779
return grid_pixels_2d
774780

775781

776782
def extent_symmetric_from(
777-
extent: Tuple[float, float, float, float]
783+
extent: Tuple[float, float, float, float],
778784
) -> Tuple[float, float, float, float]:
779785
"""
780786
Given an input extent of the form (x_min, x_max, y_min, y_max), this function returns an extent which is

autoarray/inversion/pixelization/border_relocator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def sub_slim_indexes_for_slim_index_via_mask_2d_from(
4848
sub_mask_1d_indexes_for_mask_1d_index = sub_mask_1d_indexes_for_mask_1d_index_from(mask=mask, sub_size=2)
4949
"""
5050

51-
total_pixels = mask_2d_util.total_pixels_2d_from(mask_2d=mask_2d)
51+
total_pixels = np.sum(~mask_2d)
5252

5353
sub_slim_indexes_for_slim_index = [[] for _ in range(total_pixels)]
5454

autoarray/inversion/pixelization/mesh/mesh_util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
@numba_util.jit()
99
def rectangular_neighbors_from(
10-
shape_native: Tuple[int, int]
10+
shape_native: Tuple[int, int],
1111
) -> Tuple[np.ndarray, np.ndarray]:
1212
"""
1313
Returns the 4 (or less) adjacent neighbors of every pixel on a rectangular pixelization as an ndarray of shape

autoarray/mask/abstract_mask.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import logging
55

66
from autoarray.numpy_wrapper import np, use_jax
7+
78
if use_jax:
89
import jax
910
from pathlib import Path

autoarray/mask/mask_2d.py

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -379,65 +379,6 @@ def circular_annular(
379379
invert=invert,
380380
)
381381

382-
@classmethod
383-
def circular_anti_annular(
384-
cls,
385-
shape_native: Tuple[int, int],
386-
inner_radius: float,
387-
outer_radius: float,
388-
outer_radius_2: float,
389-
pixel_scales: ty.PixelScales,
390-
origin: Tuple[float, float] = (0.0, 0.0),
391-
centre: Tuple[float, float] = (0.0, 0.0),
392-
invert: bool = False,
393-
) -> "Mask2D":
394-
"""
395-
Returns a Mask2D (see *Mask2D.__new__*) where all `False` entries are within an inner circle and second
396-
outer circle, forming an inverse annulus.
397-
398-
The `inner_radius`, `outer_radius`, `outer_radius_2` and `centre` are all input in scaled units.
399-
400-
Parameters
401-
----------
402-
shape_native
403-
The (y,x) shape of the mask in units of pixels.
404-
inner_radius
405-
The inner radius in scaled units of the annulus within which pixels are `False` and unmasked.
406-
outer_radius
407-
The first outer radius in scaled units of the annulus within which pixels are `True` and masked.
408-
outer_radius_2
409-
The second outer radius in scaled units of the annulus within which pixels are `False` and unmasked and
410-
outside of which all entries are `True` and masked.
411-
pixel_scales
412-
The (y,x) scaled units to pixel units conversion factors of every pixel. If this is input as a `float`,
413-
it is converted to a (float, float) structure.
414-
origin
415-
The (y,x) scaled units origin of the mask's coordinate system.
416-
centre
417-
The (y,x) scaled units centre of the anti-annulus used to mask pixels.
418-
invert
419-
If `True`, the `bool`'s of the input `mask` are inverted, for example `False`'s become `True`
420-
and visa versa.
421-
"""
422-
423-
pixel_scales = geometry_util.convert_pixel_scales_2d(pixel_scales=pixel_scales)
424-
425-
mask = mask_2d_util.mask_2d_circular_anti_annular_from(
426-
shape_native=shape_native,
427-
pixel_scales=pixel_scales,
428-
inner_radius=inner_radius,
429-
outer_radius=outer_radius,
430-
outer_radius_2_scaled=outer_radius_2,
431-
centre=centre,
432-
)
433-
434-
return cls(
435-
mask=mask,
436-
pixel_scales=pixel_scales,
437-
origin=origin,
438-
invert=invert,
439-
)
440-
441382
@classmethod
442383
def elliptical(
443384
cls,

0 commit comments

Comments
 (0)