diff --git a/autogalaxy/convert.py b/autogalaxy/convert.py index ff1c2a17d..fa0b12b91 100644 --- a/autogalaxy/convert.py +++ b/autogalaxy/convert.py @@ -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]: @@ -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 angle = xp.where(angle < -45, angle + 180, angle) @@ -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) angle = xp.where(angle < 0, angle + 180.0, angle) @@ -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) + 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) diff --git a/autogalaxy/profiles/geometry_profiles.py b/autogalaxy/profiles/geometry_profiles.py index 1df8ccec1..920247bdf 100644 --- a/autogalaxy/profiles/geometry_profiles.py +++ b/autogalaxy/profiles/geometry_profiles.py @@ -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)