Skip to content

Commit cde35d9

Browse files
Jammy2211Jammy2211
authored andcommitted
Voronoi areas?
1 parent 4cf886e commit cde35d9

File tree

1 file changed

+23
-25
lines changed

1 file changed

+23
-25
lines changed

autoarray/structures/mesh/delaunay_2d.py

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,28 @@ def scipy_delaunay(points_np, query_points_np, use_voronoi_areas, areas_factor):
4646
points,
4747
)
4848

49+
# --- DEBUG / SAFETY CHECK: Voronoi areas ---
50+
if not np.isfinite(areas).all():
51+
n_nan = np.isnan(areas).sum()
52+
n_inf = np.isinf(areas).sum()
53+
print(
54+
f"[pure_callback] Voronoi areas NON-FINITE: "
55+
f"n_nan={n_nan} n_inf={n_inf} "
56+
f"min={np.nanmin(areas)} max={np.nanmax(areas)}"
57+
)
58+
59+
# Save everything needed to reproduce offline
60+
np.savez(
61+
"callback_bad_voronoi_areas.npz",
62+
points=points,
63+
areas=areas,
64+
)
65+
66+
raise FloatingPointError(
67+
"voronoi_areas_numpy produced NaN/inf; "
68+
"saved callback_bad_voronoi_areas.npz"
69+
)
70+
4971
max_area = np.percentile(areas, 90.0)
5072

5173
areas[areas == -1] = max_area
@@ -67,17 +89,6 @@ def scipy_delaunay(points_np, query_points_np, use_voronoi_areas, areas_factor):
6789
area_weights=split_point_areas,
6890
)
6991

70-
# DEBUG: split_points must be finite for KDTree/query
71-
if not np.isfinite(split_points).all():
72-
n_nan = np.isnan(split_points).sum()
73-
n_inf = np.isinf(split_points).sum()
74-
print(f"[pure_callback] split_points NON-FINITE: n_nan={n_nan} n_inf={n_inf} "
75-
f"min={np.nanmin(split_points)} max={np.nanmax(split_points)}")
76-
np.savez("callback_bad_split_points.npz",
77-
points=points_np, split_point_areas=split_point_areas, split_points=split_points)
78-
raise FloatingPointError("split_points contains NaN/inf; saved callback_bad_split_points.npz")
79-
80-
8192
# ---------- find_simplex for split cross points ----------
8293
split_points_idx = tri.find_simplex(split_points)
8394

@@ -341,23 +352,10 @@ def pix_indexes_for_sub_slim_index_delaunay_from(
341352
# Case 2: Outside → KDTree NN
342353
# ---------------------------
343354
if outside_mask.any():
344-
x = source_plane_data_grid[outside_mask]
345-
346-
if not np.isfinite(x).all():
347-
n_nan = np.isnan(x).sum()
348-
n_inf = np.isinf(x).sum()
349-
print(f"[pure_callback] KDTree.query input NON-FINITE: n_nan={n_nan} n_inf={n_inf} "
350-
f"shape={x.shape} dtype={x.dtype}")
351-
np.savez("callback_bad_kdtree_x.npz",
352-
x=x, source_plane_data_grid=source_plane_data_grid, outside_mask=outside_mask,
353-
delaunay_points=delaunay_points)
354-
raise FloatingPointError("KDTree.query got NaN/inf; saved callback_bad_kdtree_x.npz")
355-
356355
tree = cKDTree(delaunay_points)
357-
_, idx = tree.query(x, k=1)
356+
_, idx = tree.query(source_plane_data_grid[outside_mask], k=1)
358357
out[outside_mask, 0] = idx.astype(np.int32)
359358

360-
361359
out = out.astype(np.int32)
362360

363361
return out

0 commit comments

Comments
 (0)