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
8 changes: 1 addition & 7 deletions autoarray/inversion/inversion/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,9 +327,6 @@ def regularization_matrix(self) -> Optional[np.ndarray]:
For multiple mappers, the regularization matrix is computed as the block diagonal of each individual mapper.
The scipy function `block_diag` has an overhead associated with it and if there is only one mapper and
regularization it is bypassed.

If the `settings.force_edge_pixels_to_zeros` is `True`, the edge pixels of each mapper in the inversion
are regularized so high their value is forced to zero.
"""
if self._xp.__name__.startswith("jax"):
from jax.scipy.linalg import block_diag
Expand Down Expand Up @@ -425,10 +422,7 @@ def reconstruction(self) -> np.ndarray:
"""
if self.settings.use_positive_only_solver:

if (
self.preloads.source_pixel_zeroed_indices is not None
and self.settings.force_edge_pixels_to_zeros
):
if self.preloads.source_pixel_zeroed_indices is not None:

# ids of values which are not zeroed and therefore kept in soluiton, which is computed in preloads.
ids_to_keep = self.preloads.source_pixel_zeroed_indices_to_keep
Expand Down
2 changes: 0 additions & 2 deletions autoarray/inversion/inversion/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ def __init__(
use_positive_only_solver: Optional[bool] = None,
positive_only_uses_p_initial: Optional[bool] = None,
use_border_relocator: Optional[bool] = None,
force_edge_pixels_to_zeros: bool = True,
no_regularization_add_to_curvature_diag_value: float = None,
use_w_tilde_numpy: bool = False,
use_source_loop: bool = False,
Expand Down Expand Up @@ -52,7 +51,6 @@ def __init__(
self._use_positive_only_solver = use_positive_only_solver
self._positive_only_uses_p_initial = positive_only_uses_p_initial
self._use_border_relocator = use_border_relocator
self.force_edge_pixels_to_zeros = force_edge_pixels_to_zeros
self._no_regularization_add_to_curvature_diag_value = (
no_regularization_add_to_curvature_diag_value
)
Expand Down
1 change: 1 addition & 0 deletions autoarray/inversion/pixelization/image_mesh/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .hilbert import Hilbert
from .overlay import Overlay
from .kmeans import KMeans
from .abstract import append_with_circle_edge_points
36 changes: 33 additions & 3 deletions autoarray/inversion/pixelization/image_mesh/abstract.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,46 @@
from typing import Optional

import numpy as np
import os

from autoarray.mask.mask_2d import Mask2D
from autoarray.structures.arrays.uniform_2d import Array2D
from autoarray.structures.grids.irregular_2d import Grid2DIrregular
from autoarray.inversion.inversion.settings import SettingsInversion

from autoarray.structures.grids import grid_2d_util

from autoarray import exc

def append_with_circle_edge_points(image_plane_mesh_grid, centre, radius, n_points):
"""
Generate N uniformly spaced (y, x) coordinates around a circle.

Parameters
----------
centre : (float, float)
The (y, x) centre of the circle.
radius : float
Circle radius.
n_points : int
Number of points around the circle.
xp : array namespace (np or jnp)
Function will use NumPy or JAX depending on what is passed.

Returns
-------
coords : (n_points, 2) xp.ndarray
Array of (y, x) coordinates sampled uniformly around the circle.
"""
y0, x0 = centre

# angles from 0 to 2π
theta = np.linspace(0, 2 * np.pi, n_points, endpoint=False)

# parametric circle
ys = y0 + radius * np.sin(theta)
xs = x0 + radius * np.cos(theta)

circle_edge_points = np.stack([ys, xs], axis=-1)

return Grid2DIrregular(np.vstack([image_plane_mesh_grid, circle_edge_points]))


class AbstractImageMesh:
Expand Down
1 change: 0 additions & 1 deletion autoarray/inversion/pixelization/image_mesh/hilbert.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from autoarray.inversion.pixelization.image_mesh.abstract_weighted import (
AbstractImageMeshWeighted,
)
from autoarray.inversion.inversion.settings import SettingsInversion
from autoarray.structures.grids.irregular_2d import Grid2DIrregular

from autoarray import exc
Expand Down
4 changes: 0 additions & 4 deletions test_autoarray/inversion/inversion/test_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,6 @@ def test__inversion_imaging__via_linear_obj_func_and_mapper__force_edge_pixels_t
linear_obj_list=[linear_obj, delaunay_mapper_9_3x3],
settings=aa.SettingsInversion(
no_regularization_add_to_curvature_diag_value=False,
force_edge_pixels_to_zeros=True,
),
)

Expand All @@ -295,7 +294,6 @@ def test__inversion_imaging__via_linear_obj_func_and_mapper__force_edge_pixels_t
settings=aa.SettingsInversion(
use_positive_only_solver=True,
no_regularization_add_to_curvature_diag_value=False,
force_edge_pixels_to_zeros=True,
),
)

Expand Down Expand Up @@ -362,7 +360,6 @@ def test__inversion_imaging__linear_obj_func_and_non_func_give_same_terms(
linear_obj_list=[linear_obj, rectangular_mapper_7x7_3x3],
settings=aa.SettingsInversion(
use_positive_only_solver=True,
force_edge_pixels_to_zeros=False,
),
)

Expand All @@ -377,7 +374,6 @@ def test__inversion_imaging__linear_obj_func_and_non_func_give_same_terms(
linear_obj_list=[rectangular_mapper_7x7_3x3],
settings=aa.SettingsInversion(
use_positive_only_solver=True,
force_edge_pixels_to_zeros=False,
),
)

Expand Down
1 change: 0 additions & 1 deletion test_autoarray/inversion/inversion/test_settings_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ def make_settings_dict():
"arguments": {
"use_positive_only_solver": False,
"positive_only_uses_p_initial": False,
"force_edge_pixels_to_zeros": True,
"no_regularization_add_to_curvature_diag_value": 1e-08,
"use_w_tilde_numpy": False,
"use_source_loop": False,
Expand Down
29 changes: 29 additions & 0 deletions test_autoarray/inversion/pixelization/image_mesh/test_abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,35 @@ def test__mesh_pixels_per_image_pixels_from(mask, mesh_grid, image_mesh):
)


def test__append_with_circle_edge_points():

image_plane_mesh_grid = aa.Grid2DIrregular(
values=[(0.0, 0.0), (1.0, 1.0), (2.0, 2.0)]
)

grid_with_circle = aa.image_mesh.append_with_circle_edge_points(
image_plane_mesh_grid=image_plane_mesh_grid,
centre=(0.0, 0.0),
radius=3.0,
n_points=4,
)

assert grid_with_circle == pytest.approx(
np.array(
[
[0.0, 0.0],
[1.0, 1.0],
[2.0, 2.0],
[0.0, 3.0],
[3.0, 0.0],
[0.0, -3.0],
[-3.0, 0.0],
]
),
1.0e-4,
)


def test__check_mesh_pixels_per_image_pixels(mask, mesh_grid, image_mesh):
image_mesh.check_mesh_pixels_per_image_pixels(
mask=mask,
Expand Down
Loading