Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions autogalaxy/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def ell_comps_from(axis_ratio: float, angle: float, xp=np) -> Tuple[float, float
return (ellip_y, ellip_x)



def axis_ratio_and_angle_from(
ell_comps: Tuple[float, float], xp=np
) -> Tuple[float, float]:
Expand Down Expand Up @@ -60,7 +61,7 @@ def axis_ratio_and_angle_from(
ell_comps
The elliptical components of the light or mass profile which are converted to an angle.
"""
angle = xp.arctan2(ell_comps[0], ell_comps[1]) / 2
angle = 0.5 * xp.arctan2(ell_comps[0], xp.where((ell_comps[0] == 0) & (ell_comps[1] == 0), 1.0, ell_comps[1]))
angle *= 180.0 / xp.pi
Comment on lines +64 to 65
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add regression coverage for the new (0,0) elliptical-components branch. In particular, test that axis_ratio_and_angle_from(ell_comps=(0.0, 0.0)) returns finite values (axis_ratio ~ 1.0, angle ~ 0.0) for both NumPy and JAX backends (e.g. xp=jax.numpy) to ensure the original NaN/undefined-backend behavior can’t regress.

Copilot uses AI. Check for mistakes.

angle = xp.where(angle < -45, angle + 180, angle)
Expand Down Expand Up @@ -197,7 +198,7 @@ def shear_magnitude_and_angle_from(
gamma_2
The gamma 2 component of the shear.
"""
angle = xp.arctan2(gamma_2, gamma_1) / 2 * 180.0 / xp.pi
angle = 0.5 * xp.arctan2(gamma_2, xp.where((gamma_1 == 0) & (gamma_2 == 0), 1.0, gamma_1)) * 180.0 / xp.pi
magnitude = xp.sqrt(gamma_1**2 + gamma_2**2)
Comment on lines +201 to 202
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add regression coverage for the new (0,0) shear-components branch (e.g. shear_magnitude_and_angle_from(gamma_1=0.0, gamma_2=0.0, xp=jax.numpy)), asserting the returned magnitude/angle are finite and as expected. This ensures the backend-specific edge case this guard is addressing can’t regress.

Copilot uses AI. Check for mistakes.

angle = xp.where(angle < 0, angle + 180.0, angle)
Expand Down Expand Up @@ -297,9 +298,15 @@ def multipole_k_m_and_phi_m_from(
-------
The normalization and angle parameters of the multipole.
"""
phi_m = (
xp.arctan2(multipole_comps[0], multipole_comps[1]) * 180.0 / xp.pi / float(m)
)
phi_m = xp.arctan2(
multipole_comps[0],
xp.where(
(multipole_comps[0] == 0) & (multipole_comps[1] == 0),
1.0,
multipole_comps[1],
),
) * 180.0 / xp.pi / float(m)
Comment on lines +301 to +308
Copy link

Copilot AI Feb 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add regression coverage for the new (0,0) multipole-components handling (e.g. multipole_k_m_and_phi_m_from(multipole_comps=(0.0, 0.0), m=2, xp=jax.numpy)), checking the returned k_m / phi_m are finite and stable. This validates the intent of the xp.where guard across supported backends.

Copilot uses AI. Check for mistakes.

k_m = xp.sqrt(multipole_comps[1] ** 2 + multipole_comps[0] ** 2)

phi_m = xp.where(phi_m < -90.0 / m, phi_m + 360.0 / m, phi_m)
Expand Down
3 changes: 1 addition & 2 deletions autogalaxy/profiles/geometry_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ def _cartesian_grid_via_radial_from(
"""
grid_angles = xp.arctan2(grid.array[:, 0], grid.array[:, 1])

cos_theta = xp.cos(grid_angles)
sin_theta = xp.sin(grid_angles)
cos_theta, sin_theta = self.angle_to_profile_grid_from(grid_angles=grid_angles, xp=xp, **kwargs)

return xp.multiply(radius[:, None], xp.vstack((sin_theta, cos_theta)).T)

Expand Down
Loading