Skip to content

feature/ell_comps_division_0_bug_fix#278

Merged
Jammy2211 merged 2 commits intomainfrom
feature/ell_comps_division_0_bug_fix
Feb 12, 2026
Merged

feature/ell_comps_division_0_bug_fix#278
Jammy2211 merged 2 commits intomainfrom
feature/ell_comps_division_0_bug_fix

Conversation

@Jammy2211
Copy link
Copy Markdown
Collaborator

This pull request introduces improvements to the handling of elliptical component conversions and grid geometry in the codebase. The changes focus on making the angle calculation more robust and updating how grid angles are processed.

Elliptical component conversion improvements:

  • Updated the axis_ratio_and_angle_from function in autogalaxy/convert.py to handle cases where both elliptical components are zero, preventing division by zero in angle calculations. The calculation now uses xp.where to substitute a value of 1.0 for the denominator when both components are zero.
  • Added a blank line before the axis_ratio_and_angle_from function definition for improved code readability.

Grid geometry processing:

  • Modified the _cartesian_grid_via_radial_from method in autogalaxy/profiles/geometry_profiles.py to use the angle_to_profile_grid_from method for calculating cos_theta and sin_theta, ensuring consistency and potentially improved handling of grid angles.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves numerical robustness and consistency in angle-related conversions and grid geometry operations, particularly targeting edge cases that can behave poorly in alternative numerical backends (e.g., JAX).

Changes:

  • Added zero-component guards to multiple arctan2-based conversions in autogalaxy/convert.py using xp.where.
  • Refactored _cartesian_grid_via_radial_from to compute trig terms via angle_to_profile_grid_from for consistency.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
autogalaxy/profiles/geometry_profiles.py Routes trig computation through angle_to_profile_grid_from when reconstructing Cartesian vectors from radial form.
autogalaxy/convert.py Adds explicit handling for (0,0) component edge cases in ellipticity, shear, and multipole angle conversions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +201 to 202
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)
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.
Comment on lines +301 to +308
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)
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.
Comment on lines +64 to 65
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
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.
@Jammy2211 Jammy2211 merged commit d6b4c62 into main Feb 12, 2026
14 checks passed
@Jammy2211 Jammy2211 deleted the feature/ell_comps_division_0_bug_fix branch February 13, 2026 13:43
@Jammy2211 Jammy2211 restored the feature/ell_comps_division_0_bug_fix branch February 13, 2026 13:43
@Jammy2211 Jammy2211 deleted the feature/ell_comps_division_0_bug_fix branch April 2, 2026 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants