From 4c6a13f9533cdb9547d82be1bf327d7d6d9792d9 Mon Sep 17 00:00:00 2001 From: Connor Stone Date: Sat, 21 Dec 2024 09:35:38 -0500 Subject: [PATCH] remove automatic setting for external shear --- src/caustics/lenses/external_shear.py | 21 ++++----------------- tests/test_external_shear.py | 17 ----------------- 2 files changed, 4 insertions(+), 34 deletions(-) diff --git a/src/caustics/lenses/external_shear.py b/src/caustics/lenses/external_shear.py index ab17d946..dc2d5014 100644 --- a/src/caustics/lenses/external_shear.py +++ b/src/caustics/lenses/external_shear.py @@ -98,21 +98,8 @@ def parametrization(self, value: str): f"Invalid parametrization: {value}. Must be 'cartesian' or 'angular'." ) if value == "angular" and self._parametrization != "angular": - try: - gamma = torch.sqrt(self.gamma_1.value**2 + self.gamma_2.value**2) - if gamma.item() == 0: - theta = 0.0 - else: - theta = 0.5 * torch.acos(self.gamma_1.value / gamma) - except TypeError: - gamma = None - theta = None - self.gamma = Param( - "gamma", value=gamma, shape=self.gamma_1.shape, units="unitless" - ) - self.theta = Param( - "theta", value=theta, shape=self.gamma_1.shape, units="radians" - ) + self.gamma = Param("gamma", shape=self.gamma_1.shape, units="unitless") + self.theta = Param("theta", shape=self.gamma_1.shape, units="radians") self.gamma_1.value = lambda p: func.gamma_theta_to_gamma1( p["gamma"].value, p["theta"].value ) @@ -125,10 +112,10 @@ def parametrization(self, value: str): self.gamma_2.link(self.theta) if value == "cartesian" and self._parametrization != "cartesian": try: - del self.gamma - del self.theta self.gamma_1 = None self.gamma_2 = None + del self.gamma + del self.theta except AttributeError: pass diff --git a/tests/test_external_shear.py b/tests/test_external_shear.py index e0a0eba3..e8e3e499 100644 --- a/tests/test_external_shear.py +++ b/tests/test_external_shear.py @@ -80,22 +80,5 @@ def test_external_shear_parametrization(): assert not hasattr(lens, "gamma") assert not hasattr(lens, "theta") - # Check set to angular when gamma1 and gamma2 have values - lens.gamma_1 = 0.0 - lens.gamma_2 = 1.0 - lens.parametrization = "angular" - assert np.allclose(lens.gamma.value.item(), 1.0) - assert np.allclose(lens.gamma_1.value.item(), 0.0, atol=1e-5) - assert np.allclose(lens.gamma_2.value.item(), 1.0, atol=1e-5) - - # Check case where gamma = 0 - lens.parametrization = "cartesian" - lens.gamma_1 = 0.0 - lens.gamma_2 = 0.0 - lens.parametrization = "angular" - assert np.allclose(lens.gamma.value.item(), 0.0, atol=1e-5) - assert np.allclose(lens.gamma_1.value.item(), 0.0, atol=1e-5) - assert np.allclose(lens.gamma_2.value.item(), 0.0, atol=1e-5) - with pytest.raises(ValueError): lens.parametrization = "weird"