Skip to content

Commit cfe9f37

Browse files
Jammy2211Jammy2211
authored andcommitted
reduced1
1 parent f8a7d5e commit cfe9f37

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

autoarray/inversion/pixelization/border_relocator.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ def ellipse_params_via_border_pca_from(border_grid, xp=np, eps=1e-12):
263263
return origin, a, b, phi
264264

265265

266-
def relocated_grid_via_ellipse_border_from(grid, origin, a, b, phi, xp=np, eps=1e-12):
266+
def relocated_grid_via_ellipse_border_fro1m(grid, origin, a, b, phi, xp=np, eps=1e-12):
267267
"""
268268
Rotated ellipse centered at origin with semi-axes a (major, x'), b (minor, y'),
269269
rotated by phi radians (counterclockwise).
@@ -284,14 +284,12 @@ def relocated_grid_via_ellipse_border_from(grid, origin, a, b, phi, xp=np, eps=1
284284
Numerical safety epsilon.
285285
"""
286286

287-
import jax.numpy as jnp
288-
289287
# shift to origin
290288
dy = grid[:, 0] - origin[0]
291289
dx = grid[:, 1] - origin[1]
292290

293-
c = jnp.cos(phi)
294-
s = jnp.sin(phi)
291+
c = xp.cos(phi)
292+
s = xp.sin(phi)
295293

296294
# rotate into ellipse-aligned frame
297295
xprime = c * dx + s * dy
@@ -301,7 +299,7 @@ def relocated_grid_via_ellipse_border_from(grid, origin, a, b, phi, xp=np, eps=1
301299
q = (xprime / a) ** 2 + (yprime / b) ** 2
302300

303301
outside = q > 1.0
304-
scale = 1.0 / jnp.sqrt(jnp.maximum(q, 1.0 + eps))
302+
scale = 1.0 / xp.sqrt(xp.maximum(q, 1.0 + eps))
305303

306304
# scale back to boundary
307305
xprime2 = xprime * scale
@@ -311,10 +309,14 @@ def relocated_grid_via_ellipse_border_from(grid, origin, a, b, phi, xp=np, eps=1
311309
dx2 = c * xprime2 - s * yprime2
312310
dy2 = s * xprime2 + c * yprime2
313311

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

316-
return jnp.where(outside[:, None], moved, grid)
314+
return xp.where(outside[:, None], moved, grid)
317315

316+
def relocated_grid_via_ellipse_border_from_v0(grid, origin, a, b, phi, xp=np, eps=1e-12):
317+
outside = grid[:, 0] > xp.asarray(0.0, dtype=grid.dtype)
318+
moved = grid # identical
319+
return xp.where(outside[:, None], moved, grid)
318320

319321
class BorderRelocator:
320322
def __init__(

0 commit comments

Comments
 (0)