Skip to content

Commit f64e54c

Browse files
authored
Merge pull request #198 from Jammy2211/feature/image_mesh_border
Feature/image mesh border
2 parents 52420b3 + 6cf9016 commit f64e54c

File tree

8 files changed

+64
-18
lines changed

8 files changed

+64
-18
lines changed

autoarray/inversion/inversion/abstract.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -327,9 +327,6 @@ def regularization_matrix(self) -> Optional[np.ndarray]:
327327
For multiple mappers, the regularization matrix is computed as the block diagonal of each individual mapper.
328328
The scipy function `block_diag` has an overhead associated with it and if there is only one mapper and
329329
regularization it is bypassed.
330-
331-
If the `settings.force_edge_pixels_to_zeros` is `True`, the edge pixels of each mapper in the inversion
332-
are regularized so high their value is forced to zero.
333330
"""
334331
if self._xp.__name__.startswith("jax"):
335332
from jax.scipy.linalg import block_diag
@@ -425,10 +422,7 @@ def reconstruction(self) -> np.ndarray:
425422
"""
426423
if self.settings.use_positive_only_solver:
427424

428-
if (
429-
self.preloads.source_pixel_zeroed_indices is not None
430-
and self.settings.force_edge_pixels_to_zeros
431-
):
425+
if self.preloads.source_pixel_zeroed_indices is not None:
432426

433427
# ids of values which are not zeroed and therefore kept in soluiton, which is computed in preloads.
434428
ids_to_keep = self.preloads.source_pixel_zeroed_indices_to_keep

autoarray/inversion/inversion/settings.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ def __init__(
1313
use_positive_only_solver: Optional[bool] = None,
1414
positive_only_uses_p_initial: Optional[bool] = None,
1515
use_border_relocator: Optional[bool] = None,
16-
force_edge_pixels_to_zeros: bool = True,
1716
no_regularization_add_to_curvature_diag_value: float = None,
1817
use_w_tilde_numpy: bool = False,
1918
use_source_loop: bool = False,
@@ -52,7 +51,6 @@ def __init__(
5251
self._use_positive_only_solver = use_positive_only_solver
5352
self._positive_only_uses_p_initial = positive_only_uses_p_initial
5453
self._use_border_relocator = use_border_relocator
55-
self.force_edge_pixels_to_zeros = force_edge_pixels_to_zeros
5654
self._no_regularization_add_to_curvature_diag_value = (
5755
no_regularization_add_to_curvature_diag_value
5856
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
from .hilbert import Hilbert
22
from .overlay import Overlay
33
from .kmeans import KMeans
4+
from .abstract import append_with_circle_edge_points

autoarray/inversion/pixelization/image_mesh/abstract.py

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,46 @@
11
from typing import Optional
22

33
import numpy as np
4-
import os
54

65
from autoarray.mask.mask_2d import Mask2D
76
from autoarray.structures.arrays.uniform_2d import Array2D
87
from autoarray.structures.grids.irregular_2d import Grid2DIrregular
9-
from autoarray.inversion.inversion.settings import SettingsInversion
108

119
from autoarray.structures.grids import grid_2d_util
1210

13-
from autoarray import exc
11+
12+
def append_with_circle_edge_points(image_plane_mesh_grid, centre, radius, n_points):
13+
"""
14+
Generate N uniformly spaced (y, x) coordinates around a circle.
15+
16+
Parameters
17+
----------
18+
centre : (float, float)
19+
The (y, x) centre of the circle.
20+
radius : float
21+
Circle radius.
22+
n_points : int
23+
Number of points around the circle.
24+
xp : array namespace (np or jnp)
25+
Function will use NumPy or JAX depending on what is passed.
26+
27+
Returns
28+
-------
29+
coords : (n_points, 2) xp.ndarray
30+
Array of (y, x) coordinates sampled uniformly around the circle.
31+
"""
32+
y0, x0 = centre
33+
34+
# angles from 0 to 2π
35+
theta = np.linspace(0, 2 * np.pi, n_points, endpoint=False)
36+
37+
# parametric circle
38+
ys = y0 + radius * np.sin(theta)
39+
xs = x0 + radius * np.cos(theta)
40+
41+
circle_edge_points = np.stack([ys, xs], axis=-1)
42+
43+
return Grid2DIrregular(np.vstack([image_plane_mesh_grid, circle_edge_points]))
1444

1545

1646
class AbstractImageMesh:

autoarray/inversion/pixelization/image_mesh/hilbert.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
from autoarray.inversion.pixelization.image_mesh.abstract_weighted import (
1010
AbstractImageMeshWeighted,
1111
)
12-
from autoarray.inversion.inversion.settings import SettingsInversion
1312
from autoarray.structures.grids.irregular_2d import Grid2DIrregular
1413

1514
from autoarray import exc

test_autoarray/inversion/inversion/test_factory.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,6 @@ def test__inversion_imaging__via_linear_obj_func_and_mapper__force_edge_pixels_t
281281
linear_obj_list=[linear_obj, delaunay_mapper_9_3x3],
282282
settings=aa.SettingsInversion(
283283
no_regularization_add_to_curvature_diag_value=False,
284-
force_edge_pixels_to_zeros=True,
285284
),
286285
)
287286

@@ -295,7 +294,6 @@ def test__inversion_imaging__via_linear_obj_func_and_mapper__force_edge_pixels_t
295294
settings=aa.SettingsInversion(
296295
use_positive_only_solver=True,
297296
no_regularization_add_to_curvature_diag_value=False,
298-
force_edge_pixels_to_zeros=True,
299297
),
300298
)
301299

@@ -362,7 +360,6 @@ def test__inversion_imaging__linear_obj_func_and_non_func_give_same_terms(
362360
linear_obj_list=[linear_obj, rectangular_mapper_7x7_3x3],
363361
settings=aa.SettingsInversion(
364362
use_positive_only_solver=True,
365-
force_edge_pixels_to_zeros=False,
366363
),
367364
)
368365

@@ -377,7 +374,6 @@ def test__inversion_imaging__linear_obj_func_and_non_func_give_same_terms(
377374
linear_obj_list=[rectangular_mapper_7x7_3x3],
378375
settings=aa.SettingsInversion(
379376
use_positive_only_solver=True,
380-
force_edge_pixels_to_zeros=False,
381377
),
382378
)
383379

test_autoarray/inversion/inversion/test_settings_dict.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ def make_settings_dict():
1515
"arguments": {
1616
"use_positive_only_solver": False,
1717
"positive_only_uses_p_initial": False,
18-
"force_edge_pixels_to_zeros": True,
1918
"no_regularization_add_to_curvature_diag_value": 1e-08,
2019
"use_w_tilde_numpy": False,
2120
"use_source_loop": False,

test_autoarray/inversion/pixelization/image_mesh/test_abstract.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,35 @@ def test__mesh_pixels_per_image_pixels_from(mask, mesh_grid, image_mesh):
4242
)
4343

4444

45+
def test__append_with_circle_edge_points():
46+
47+
image_plane_mesh_grid = aa.Grid2DIrregular(
48+
values=[(0.0, 0.0), (1.0, 1.0), (2.0, 2.0)]
49+
)
50+
51+
grid_with_circle = aa.image_mesh.append_with_circle_edge_points(
52+
image_plane_mesh_grid=image_plane_mesh_grid,
53+
centre=(0.0, 0.0),
54+
radius=3.0,
55+
n_points=4,
56+
)
57+
58+
assert grid_with_circle == pytest.approx(
59+
np.array(
60+
[
61+
[0.0, 0.0],
62+
[1.0, 1.0],
63+
[2.0, 2.0],
64+
[0.0, 3.0],
65+
[3.0, 0.0],
66+
[0.0, -3.0],
67+
[-3.0, 0.0],
68+
]
69+
),
70+
1.0e-4,
71+
)
72+
73+
4574
def test__check_mesh_pixels_per_image_pixels(mask, mesh_grid, image_mesh):
4675
image_mesh.check_mesh_pixels_per_image_pixels(
4776
mask=mask,

0 commit comments

Comments
 (0)