Skip to content

Commit 532d855

Browse files
Jammy2211Jammy2211
authored andcommitted
fix test__voronoi_areas_via_delaunay_from
1 parent 3448545 commit 532d855

2 files changed

Lines changed: 10 additions & 33 deletions

File tree

autoarray/structures/mesh/delaunay_2d.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ def voronoi_areas_from(points_np):
2222
# --- Voronoi ---
2323
vor = Voronoi(points_np, qhull_options="Qbb Qc Qx Qm")
2424

25-
areas = np.zeros(N, dtype=points_np.dtype)
26-
2725
voronoi_vertices = vor.vertices
2826
voronoi_regions = vor.regions
2927
voronoi_point_region = vor.point_region
@@ -488,6 +486,11 @@ def interpolated_array_from(
488486
pixel_values=values,
489487
)
490488

489+
return Array2D.no_mask(
490+
values=interpolated_array, pixel_scales=interpolation_grid.pixel_scales
491+
)
492+
493+
491494
@property
492495
def areas_for_magnification(self) -> np.ndarray:
493496
"""

test_autoarray/structures/mesh/test_delaunay.py

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -105,37 +105,11 @@ def test__voronoi_areas_via_delaunay_from():
105105
[[0.0, 0.0], [1.1, 0.6], [2.1, 0.1], [0.4, 1.1], [1.1, 7.1], [2.1, 1.1]]
106106
)
107107

108-
delaunay = scipy.spatial.Delaunay(mesh_grid)
108+
delaunay = aa.Mesh2DDelaunay(mesh_grid)
109109

110-
voronoi_areas = voronoi_areas_from(
111-
mesh_grid,
112-
)
113-
114-
voronoi = scipy.spatial.Voronoi(
115-
mesh_grid,
116-
qhull_options="Qbb Qc Qx Qm",
117-
)
118-
119-
voronoi_vertices = voronoi.vertices
120-
voronoi_regions = voronoi.regions
121-
voronoi_point_region = voronoi.point_region
122-
123-
pixels = mesh_grid.shape[0]
124-
125-
region_areas = np.zeros(pixels)
126-
127-
for i in range(pixels):
128-
region_vertices_indexes = voronoi_regions[voronoi_point_region[i]]
129-
if -1 in region_vertices_indexes:
130-
region_areas[i] = -1
131-
else:
132-
region_areas[i] = aa.util.grid_2d.compute_polygon_area(
133-
voronoi_vertices[region_vertices_indexes]
134-
)
135-
136-
assert voronoi_areas[1] == pytest.approx(region_areas[1], 1.0e-4)
137-
assert voronoi_areas[3] == pytest.approx(region_areas[3], 1.0e-4)
110+
voronoi_areas = delaunay.delaunay.voronoi_areas
138111

139-
# Old Voronoi cell code put -1 in edge pixels, new code puts large area
140112

141-
assert voronoi_areas[4] == pytest.approx(32.83847776, 1.0e-4)
113+
assert voronoi_areas[1] == pytest.approx(1.39137102, 1.0e-4)
114+
assert voronoi_areas[3] == pytest.approx(29.836324, 1.0e-4)
115+
assert voronoi_areas[4] == pytest.approx(-1.0, 1.0e-4)

0 commit comments

Comments
 (0)