Skip to content

Commit

Permalink
style: pre-commit fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci[bot] committed May 29, 2024
1 parent 5b8946c commit 8aac654
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 22 deletions.
6 changes: 5 additions & 1 deletion src/caustics/lenses/func/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@
concentration_tnfw,
)

from .multipole import reduced_deflection_angle_multipole, potential_multipole, convergence_multipole
from .multipole import (
reduced_deflection_angle_multipole,
potential_multipole,
convergence_multipole,
)

__all__ = (
"forward_raytrace",
Expand Down
18 changes: 11 additions & 7 deletions src/caustics/lenses/func/multipole.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,21 @@ def reduced_deflection_angle_multipole(x0, y0, m, a_m, phi_m, x, y):
Equation (B11) and (B12) https://arxiv.org/pdf/1307.4220, Xu et al. 2014
"""
x, y = translate_rotate(x, y, x0, y0)

phi = torch.arctan2(y, x)
ax = torch.cos(phi) * a_m / (1 - m**2) * torch.cos(m * (phi - phi_m)) + torch.sin(phi) * m * a_m / (1 - m**2) * torch.sin(m * (phi - phi_m))
ay = torch.sin(phi) * a_m / (1 - m**2) * torch.cos(m * (phi - phi_m)) - torch.cos(phi) * m * a_m / (1 - m**2) * torch.sin(m * (phi - phi_m))
ax = torch.cos(phi) * a_m / (1 - m**2) * torch.cos(m * (phi - phi_m)) + torch.sin(
phi
) * m * a_m / (1 - m**2) * torch.sin(m * (phi - phi_m))
ay = torch.sin(phi) * a_m / (1 - m**2) * torch.cos(m * (phi - phi_m)) - torch.cos(
phi
) * m * a_m / (1 - m**2) * torch.sin(m * (phi - phi_m))

return derotate(ax, ay, phi)


def potential_multipole(x0, y0, m, a_m, phi_m, x, y):
"""
Compute the lensing potential.
Compute the lensing potential.
Parameters
----------
Expand Down Expand Up @@ -78,12 +82,12 @@ def potential_multipole(x0, y0, m, a_m, phi_m, x, y):
x, y = translate_rotate(x, y, x0, y0)
r = torch.sqrt(x**2 + y**2)
phi = torch.arctan2(y, x)
return r * a_m / (1 - m**2) * torch.cos(m * (phi - phi_m))
return r * a_m / (1 - m**2) * torch.cos(m * (phi - phi_m))


def convergence_multipole(x0, y0, m, a_m, phi_m, x, y):
"""
Compute the lensing convergence.
Compute the lensing convergence.
Parameters
----------
Expand Down Expand Up @@ -117,4 +121,4 @@ def convergence_multipole(x0, y0, m, a_m, phi_m, x, y):
x, y = translate_rotate(x, y, x0, y0)
r = torch.sqrt(x**2 + y**2)
phi = torch.arctan2(y, x)
return 1/r * a_m * torch.cos(m * (phi - phi_m))
return 1 / r * a_m * torch.cos(m * (phi - phi_m))
13 changes: 3 additions & 10 deletions src/caustics/lenses/multipole.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,15 @@ class Multipole(ThinLens):
Orientation of multiple.
m: Optional[Union[Tensor, int]]
Order of multipole.
"""

_null_params = {
"x0": 0.0,
"y0": 0.0,
"a_m": 0.1,
"phi_m": 0.,
"m": 3
}
_null_params = {"x0": 0.0, "y0": 0.0, "a_m": 0.1, "phi_m": 0.0, "m": 3}

def __init__(
self,
cosmology: CosmologyType,
z_l: ZLType = None,

x0: Annotated[
Optional[Union[Tensor, float]], "The x-coordinate of the lens center", True
] = None,
Expand Down Expand Up @@ -228,7 +221,7 @@ def convergence(
The projected mass density.
*Unit: unitless*
Equation (B10) and (B3) https://arxiv.org/pdf/1307.4220, Xu et al. 2014
"""
Expand Down
2 changes: 1 addition & 1 deletion src/caustics/models/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def _get_kwargs_field_definitions(
if k != "name":
anno = v.annotation
dtype = anno.__origin__
cls_param = ClassParam(*anno.__metadata__) # gooooo
cls_param = ClassParam(*anno.__metadata__) # gooooo
if cls_param.isParam:
kwargs_field_definitions[PARAMS][k] = (
dtype,
Expand Down
17 changes: 14 additions & 3 deletions tests/test_multipole.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import torch
from lenstronomy.LensModel.lens_model import LensModel
from utils import lens_test_helper, alpha_test_helper, kappa_test_helper, Psi_test_helper
from utils import (
lens_test_helper,
alpha_test_helper,
kappa_test_helper,
Psi_test_helper,
)
import yaml

from caustics.cosmology import FlatLambdaCDM
Expand Down Expand Up @@ -37,9 +42,15 @@ def test(sim_source, device, lens_models):

# Parameters m, a_m ,phi_m
z_s = torch.tensor(1.2)
x = torch.tensor([-0.342, 0.51, 0.1, 3.14/4, 3])
x = torch.tensor([-0.342, 0.51, 0.1, 3.14 / 4, 3])
kwargs_ls = [
{"center_x": x[0].item(), "center_y": x[1].item(), "a_m": x[2].item(), "phi_m": x[3].item(), "m": x[4].item()}
{
"center_x": x[0].item(),
"center_y": x[1].item(),
"a_m": x[2].item(),
"phi_m": x[3].item(),
"m": x[4].item(),
}
]

lens_test_helper(lens, lens_ls, z_s, x, kwargs_ls, rtol, atol, device=device)

Check failure on line 56 in tests/test_multipole.py

View workflow job for this annotation

GitHub Actions / build (3.10, ubuntu-latest)

test[yaml-cpu] AssertionError

Check failure on line 56 in tests/test_multipole.py

View workflow job for this annotation

GitHub Actions / build (3.10, ubuntu-latest)

test[no_yaml-cpu] AssertionError

Check failure on line 56 in tests/test_multipole.py

View workflow job for this annotation

GitHub Actions / build (3.10, macOS-latest)

test[yaml-cpu] AssertionError

Check failure on line 56 in tests/test_multipole.py

View workflow job for this annotation

GitHub Actions / build (3.10, macOS-latest)

test[no_yaml-cpu] AssertionError
Expand Down

0 comments on commit 8aac654

Please sign in to comment.