Skip to content

Commit f246790

Browse files
Jammy2211Jammy2211
authored andcommitted
added append_with_circle_edge_points
1 parent a3015a3 commit f246790

File tree

4 files changed

+56
-4
lines changed

4 files changed

+56
-4
lines changed
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: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,47 @@
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]))
44+
1445

1546

1647
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/pixelization/image_mesh/test_abstract.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,27 @@ 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([[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
60+
)
61+
62+
63+
64+
65+
4566
def test__check_mesh_pixels_per_image_pixels(mask, mesh_grid, image_mesh):
4667
image_mesh.check_mesh_pixels_per_image_pixels(
4768
mask=mask,

0 commit comments

Comments
 (0)