Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 16 additions & 10 deletions autoarray/geometry/geometry_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def convert_pixel_scales_2d(pixel_scales: ty.PixelScales) -> Tuple[float, float]

@numba_util.jit()
def central_pixel_coordinates_2d_from(
shape_native: Tuple[int, int]
shape_native: Tuple[int, int],
) -> Tuple[float, float]:
"""
Returns the central pixel coordinates of a 2D geometry (and therefore a 2D data structure like an ``Array2D``)
Expand Down Expand Up @@ -477,7 +477,6 @@ def grid_pixels_2d_slim_from(
pixel_scales=(0.5, 0.5), origin=(0.0, 0.0))
"""


centres_scaled = central_scaled_coordinate_2d_from(
shape_native=shape_native, pixel_scales=pixel_scales, origin=origin
)
Expand Down Expand Up @@ -544,7 +543,6 @@ def grid_pixel_centres_2d_slim_from(
pixel_scales=(0.5, 0.5), origin=(0.0, 0.0))
"""


centres_scaled = central_scaled_coordinate_2d_from(
shape_native=shape_native, pixel_scales=pixel_scales, origin=origin
)
Expand Down Expand Up @@ -629,8 +627,10 @@ def grid_pixel_indexes_2d_slim_from(

if use_jax:
grid_pixel_indexes_2d_slim = (
grid_pixels_2d_slim * np.array([shape_native[1], 1])
).sum(axis=1).astype(int)
(grid_pixels_2d_slim * np.array([shape_native[1], 1]))
.sum(axis=1)
.astype(int)
)
else:
grid_pixel_indexes_2d_slim = np.zeros(grid_pixels_2d_slim.shape[0])

Expand Down Expand Up @@ -690,7 +690,9 @@ def grid_scaled_2d_slim_from(
centres_scaled = np.array(centres_scaled)
pixel_scales = np.array(pixel_scales)
sign = np.array([-1, 1])
grid_scaled_2d_slim = (grid_pixels_2d_slim - centres_scaled - 0.5) * pixel_scales * sign
grid_scaled_2d_slim = (
(grid_pixels_2d_slim - centres_scaled - 0.5) * pixel_scales * sign
)
else:
grid_scaled_2d_slim = np.zeros((grid_pixels_2d_slim.shape[0], 2))

Expand Down Expand Up @@ -755,7 +757,7 @@ def grid_pixel_centres_2d_from(
centres_scaled = np.array(centres_scaled)
pixel_scales = np.array(pixel_scales)
sign = np.array([-1.0, 1.0])
grid_pixels_2d = (
grid_pixels_2d = (
(sign * grid_scaled_2d / pixel_scales) + centres_scaled + 0.5
).astype(int)
else:
Expand All @@ -764,17 +766,21 @@ def grid_pixel_centres_2d_from(
for y in range(grid_scaled_2d.shape[0]):
for x in range(grid_scaled_2d.shape[1]):
grid_pixels_2d[y, x, 0] = int(
(-grid_scaled_2d[y, x, 0] / pixel_scales[0]) + centres_scaled[0] + 0.5
(-grid_scaled_2d[y, x, 0] / pixel_scales[0])
+ centres_scaled[0]
+ 0.5
)
grid_pixels_2d[y, x, 1] = int(
(grid_scaled_2d[y, x, 1] / pixel_scales[1]) + centres_scaled[1] + 0.5
(grid_scaled_2d[y, x, 1] / pixel_scales[1])
+ centres_scaled[1]
+ 0.5
)

return grid_pixels_2d


def extent_symmetric_from(
extent: Tuple[float, float, float, float]
extent: Tuple[float, float, float, float],
) -> Tuple[float, float, float, float]:
"""
Given an input extent of the form (x_min, x_max, y_min, y_max), this function returns an extent which is
Expand Down
2 changes: 1 addition & 1 deletion autoarray/inversion/pixelization/border_relocator.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def sub_slim_indexes_for_slim_index_via_mask_2d_from(
sub_mask_1d_indexes_for_mask_1d_index = sub_mask_1d_indexes_for_mask_1d_index_from(mask=mask, sub_size=2)
"""

total_pixels = mask_2d_util.total_pixels_2d_from(mask_2d=mask_2d)
total_pixels = np.sum(~mask_2d)

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

Expand Down
2 changes: 1 addition & 1 deletion autoarray/inversion/pixelization/mesh/mesh_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@numba_util.jit()
def rectangular_neighbors_from(
shape_native: Tuple[int, int]
shape_native: Tuple[int, int],
) -> Tuple[np.ndarray, np.ndarray]:
"""
Returns the 4 (or less) adjacent neighbors of every pixel on a rectangular pixelization as an ndarray of shape
Expand Down
1 change: 1 addition & 0 deletions autoarray/mask/abstract_mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import logging

from autoarray.numpy_wrapper import np, use_jax

if use_jax:
import jax
from pathlib import Path
Expand Down
59 changes: 0 additions & 59 deletions autoarray/mask/mask_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,65 +379,6 @@ def circular_annular(
invert=invert,
)

@classmethod
def circular_anti_annular(
cls,
shape_native: Tuple[int, int],
inner_radius: float,
outer_radius: float,
outer_radius_2: float,
pixel_scales: ty.PixelScales,
origin: Tuple[float, float] = (0.0, 0.0),
centre: Tuple[float, float] = (0.0, 0.0),
invert: bool = False,
) -> "Mask2D":
"""
Returns a Mask2D (see *Mask2D.__new__*) where all `False` entries are within an inner circle and second
outer circle, forming an inverse annulus.

The `inner_radius`, `outer_radius`, `outer_radius_2` and `centre` are all input in scaled units.

Parameters
----------
shape_native
The (y,x) shape of the mask in units of pixels.
inner_radius
The inner radius in scaled units of the annulus within which pixels are `False` and unmasked.
outer_radius
The first outer radius in scaled units of the annulus within which pixels are `True` and masked.
outer_radius_2
The second outer radius in scaled units of the annulus within which pixels are `False` and unmasked and
outside of which all entries are `True` and masked.
pixel_scales
The (y,x) scaled units to pixel units conversion factors of every pixel. If this is input as a `float`,
it is converted to a (float, float) structure.
origin
The (y,x) scaled units origin of the mask's coordinate system.
centre
The (y,x) scaled units centre of the anti-annulus used to mask pixels.
invert
If `True`, the `bool`'s of the input `mask` are inverted, for example `False`'s become `True`
and visa versa.
"""

pixel_scales = geometry_util.convert_pixel_scales_2d(pixel_scales=pixel_scales)

mask = mask_2d_util.mask_2d_circular_anti_annular_from(
shape_native=shape_native,
pixel_scales=pixel_scales,
inner_radius=inner_radius,
outer_radius=outer_radius,
outer_radius_2_scaled=outer_radius_2,
centre=centre,
)

return cls(
mask=mask,
pixel_scales=pixel_scales,
origin=origin,
invert=invert,
)

@classmethod
def elliptical(
cls,
Expand Down
Loading
Loading