Skip to content

Commit

Permalink
remove automatic setting for external shear
Browse files Browse the repository at this point in the history
  • Loading branch information
ConnorStoneAstro committed Dec 21, 2024
1 parent e4950e4 commit 4c6a13f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 34 deletions.
21 changes: 4 additions & 17 deletions src/caustics/lenses/external_shear.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -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

Check warning on line 120 in src/caustics/lenses/external_shear.py

View check run for this annotation

Codecov / codecov/patch

src/caustics/lenses/external_shear.py#L119-L120

Added lines #L119 - L120 were not covered by tests

Expand Down
17 changes: 0 additions & 17 deletions tests/test_external_shear.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 4c6a13f

Please sign in to comment.