Skip to content

Commit dbe4beb

Browse files
Jammy2211Jammy2211
authored andcommitted
all tests pass with new border relocator used, also remove old slower umba API
1 parent 8305157 commit dbe4beb

File tree

3 files changed

+32
-26
lines changed

3 files changed

+32
-26
lines changed

autoarray/inversion/pixelization/border_relocator.py

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -235,25 +235,25 @@ def ellipse_params_via_border_pca_from(border_grid, xp=np, eps=1e-12):
235235
dx = border_grid[:, 1] - origin[1]
236236

237237
# Build data matrix in (x, y) order for PCA
238-
X = xp.stack([dx, dy], axis=1) # (M,2)
238+
X = xp.stack([dx, dy], axis=1) # (M,2)
239239

240240
# Covariance matrix
241241
denom = xp.maximum(X.shape[0] - 1, 1)
242-
C = (X.T @ X) / denom # (2,2)
242+
C = (X.T @ X) / denom # (2,2)
243243

244244
# Eigen-decomposition (ascending eigenvalues)
245245
evals, evecs = xp.linalg.eigh(C)
246246

247247
# Major axis = eigenvector with largest eigenvalue
248-
v_major = evecs[:, -1] # (2,) in (x,y)
248+
v_major = evecs[:, -1] # (2,) in (x,y)
249249

250250
phi = xp.arctan2(v_major[1], v_major[0])
251251

252252
# Rotate border points into ellipse-aligned frame
253253
c = xp.cos(phi)
254254
s = xp.sin(phi)
255255

256-
xprime = c * dx + s * dy
256+
xprime = c * dx + s * dy
257257
yprime = -s * dx + c * dy
258258

259259
# Semi-axes from maximal extent
@@ -292,7 +292,7 @@ def relocated_grid_via_ellipse_border_from(grid, origin, a, b, phi, xp=np, eps=1
292292
s = xp.sin(phi)
293293

294294
# rotate into ellipse-aligned frame
295-
xprime = c * dx + s * dy
295+
xprime = c * dx + s * dy
296296
yprime = -s * dx + c * dy
297297

298298
# ellipse radius in normalized coords
@@ -306,13 +306,10 @@ def relocated_grid_via_ellipse_border_from(grid, origin, a, b, phi, xp=np, eps=1
306306
yprime2 = yprime * scale
307307

308308
# rotate back to original frame
309-
dx2 = c * xprime2 - s * yprime2
310-
dy2 = s * xprime2 + c * yprime2
309+
dx2 = c * xprime2 - s * yprime2
310+
dy2 = s * xprime2 + c * yprime2
311311

312-
moved = xp.stack(
313-
[origin[0] + dy2, origin[1] + dx2],
314-
axis=1
315-
)
312+
moved = xp.stack([origin[0] + dy2, origin[1] + dx2], axis=1)
316313

317314
return xp.where(outside[:, None], moved, grid)
318315

@@ -416,11 +413,17 @@ def relocated_grid_from(self, grid: Grid2D, xp=np) -> Grid2D:
416413
if len(self.sub_border_grid) == 0:
417414
return grid
418415

419-
origin, a, b, phi = ellipse_params_via_border_pca_from(grid.array[self.border_slim], xp=xp)
416+
origin, a, b, phi = ellipse_params_via_border_pca_from(
417+
grid.array[self.border_slim], xp=xp
418+
)
420419

421-
values = relocated_grid_via_ellipse_border_from(grid=grid.array, origin=origin, a=a, b=b, phi=phi, xp=xp)
420+
values = relocated_grid_via_ellipse_border_from(
421+
grid=grid.array, origin=origin, a=a, b=b, phi=phi, xp=xp
422+
)
422423

423-
over_sampled = relocated_grid_via_ellipse_border_from(grid=grid.over_sampled.array, origin=origin, a=a, b=b, phi=phi, xp=xp)
424+
over_sampled = relocated_grid_via_ellipse_border_from(
425+
grid=grid.over_sampled.array, origin=origin, a=a, b=b, phi=phi, xp=xp
426+
)
424427

425428
return Grid2D(
426429
values=values,
@@ -447,9 +450,13 @@ def relocated_mesh_grid_from(
447450
if len(self.sub_border_grid) == 0:
448451
return mesh_grid
449452

450-
origin, a, b, phi = ellipse_params_via_border_pca_from(grid.array[self.border_slim], xp=xp)
453+
origin, a, b, phi = ellipse_params_via_border_pca_from(
454+
grid.array[self.border_slim], xp=xp
455+
)
451456

452-
relocated_grid = relocated_grid_via_ellipse_border_from(grid=mesh_grid.array, origin=origin, a=a, b=b, phi=phi, xp=xp)
457+
relocated_grid = relocated_grid_via_ellipse_border_from(
458+
grid=mesh_grid.array, origin=origin, a=a, b=b, phi=phi, xp=xp
459+
)
453460

454461
return Grid2DIrregular(
455462
values=relocated_grid,

autoarray/inversion/pixelization/mesh/delaunay.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,20 +126,17 @@ def mapper_grids_from(
126126

127127
relocated_mesh_grid = self.relocated_mesh_grid_from(
128128
border_relocator=border_relocator,
129-
source_plane_data_grid=relocated_grid.over_sampled,
129+
source_plane_data_grid=Grid2DIrregular(relocated_grid.over_sampled),
130130
source_plane_mesh_grid=source_plane_mesh_grid,
131131
xp=xp,
132132
)
133133

134-
try:
135-
source_plane_mesh_grid = self.mesh_grid_from(
136-
source_plane_data_grid=relocated_grid.over_sampled,
137-
source_plane_mesh_grid=relocated_mesh_grid,
138-
preloads=preloads,
139-
xp=xp,
140-
)
141-
except ValueError as e:
142-
raise e
134+
source_plane_mesh_grid = self.mesh_grid_from(
135+
source_plane_data_grid=relocated_grid.over_sampled,
136+
source_plane_mesh_grid=relocated_mesh_grid,
137+
preloads=preloads,
138+
xp=xp,
139+
)
143140

144141
return MapperGrids(
145142
mask=mask,

test_autoarray/inversion/pixelization/mesh/test_abstract.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ def test__grid_is_relocated_via_border(grid_2d_7x7):
1818
)
1919
image_mesh = image_mesh.image_plane_mesh_grid_from(mask=mask, adapt_data=None)
2020

21+
image_mesh = aa.Grid2DIrregular(image_mesh)
22+
2123
grid[8, 0] = 100.0
2224

2325
border_relocator = aa.BorderRelocator(mask=mask, sub_size=1)

0 commit comments

Comments
 (0)