Skip to content

Commit f8a7d5e

Browse files
Jammy2211Jammy2211
authored andcommitted
use jn
1 parent ba513a3 commit f8a7d5e

File tree

1 file changed

+27
-25
lines changed

1 file changed

+27
-25
lines changed

autoarray/inversion/pixelization/border_relocator.py

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -284,34 +284,36 @@ 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+
287289
# shift to origin
288290
dy = grid[:, 0] - origin[0]
289291
dx = grid[:, 1] - origin[1]
290-
#
291-
# c = xp.cos(phi)
292-
# s = xp.sin(phi)
293-
#
294-
# # rotate into ellipse-aligned frame
295-
# xprime = c * dx + s * dy
296-
# yprime = -s * dx + c * dy
297-
#
298-
# # ellipse radius in normalized coords
299-
# q = (xprime / a) ** 2 + (yprime / b) ** 2
300-
301-
outside = a > 1.0
302-
# scale = 1.0 / xp.sqrt(xp.maximum(q, 1.0 + eps))
303-
#
304-
# # scale back to boundary
305-
# xprime2 = xprime * scale
306-
# yprime2 = yprime * scale
307-
#
308-
# # rotate back to original frame
309-
# dx2 = c * xprime2 - s * yprime2
310-
# dy2 = s * xprime2 + c * yprime2
311-
312-
moved = xp.stack([origin[0] + dy, origin[1] + dx], axis=1)
313-
314-
return xp.where(outside[:, None], moved, grid)
292+
293+
c = jnp.cos(phi)
294+
s = jnp.sin(phi)
295+
296+
# rotate into ellipse-aligned frame
297+
xprime = c * dx + s * dy
298+
yprime = -s * dx + c * dy
299+
300+
# ellipse radius in normalized coords
301+
q = (xprime / a) ** 2 + (yprime / b) ** 2
302+
303+
outside = q > 1.0
304+
scale = 1.0 / jnp.sqrt(jnp.maximum(q, 1.0 + eps))
305+
306+
# scale back to boundary
307+
xprime2 = xprime * scale
308+
yprime2 = yprime * scale
309+
310+
# rotate back to original frame
311+
dx2 = c * xprime2 - s * yprime2
312+
dy2 = s * xprime2 + c * yprime2
313+
314+
moved = jnp.stack([origin[0] + dy2, origin[1] + dx2], axis=1)
315+
316+
return jnp.where(outside[:, None], moved, grid)
315317

316318

317319
class BorderRelocator:

0 commit comments

Comments
 (0)