Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: Time delay now tested for SIE #307

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/caustics/lenses/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,7 @@ def time_delay(
potential = self.potential(x, y, z_s)
TD = TD - potential
if geometric_time_delay:
ax, ay = self.physical_deflection_angle(x, y, z_s)
ax, ay = self.reduced_deflection_angle(x, y, z_s)
fp = 0.5 * (ax**2 + ay**2)
TD = TD + fp

Expand Down
2 changes: 1 addition & 1 deletion tests/test_sie.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from math import pi
from io import StringIO

import lenstronomy.Util.param_util as param_util
import torch
import lenstronomy.Util.param_util as param_util
from lenstronomy.LensModel.lens_model import LensModel
from utils import lens_test_helper

Expand Down
50 changes: 50 additions & 0 deletions tests/test_time_delay.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import torch
import numpy as np
import lenstronomy.Util.param_util as param_util
from lenstronomy.LensModel.lens_model import LensModel

import caustics

import pytest


@pytest.mark.parametrize("q", [0.5, 0.7, 0.9])
@pytest.mark.parametrize("phi", [0.0, np.pi / 3, np.pi / 2])
@pytest.mark.parametrize("bx,by", [(0.1, -0.05), (0.2, 0.1), (0.0, 0.0)])
def test_time_delay_pointsource(q, phi, bx, by):

# configuration parameters
bx = torch.tensor(bx)
by = torch.tensor(by)
z_l = torch.tensor(0.5)
z_s = torch.tensor(1.0)

# Define caustics lens
cosmo = caustics.FlatLambdaCDM(name="cosmo")
lens = caustics.SIE(cosmology=cosmo, z_l=z_l, x0=0.0, y0=0.0, q=q, phi=phi, b=1.0)
x, y = lens.forward_raytrace(bx, by, z_s)

# Define lenstronomy lens
lens_model_list = ["SIE"]
lens_ls = LensModel(
lens_model_list=lens_model_list, z_lens=z_l.item(), z_source=z_s.item()
)
e1, e2 = param_util.phi_q2_ellipticity(phi=phi, q=q)
kwargs_ls = [{"theta_E": 1.0, "e1": e1, "e2": e2, "center_x": 0.0, "center_y": 0.0}]

# Compute time delay caustics
tdc = lens.time_delay(x, y, z_s).detach().cpu().numpy()
tdc = tdc - np.min(tdc)
np.sort(tdc)

# Compute time delay lenstronomy
time_delays = lens_ls.arrival_time(
x.detach().cpu().numpy(),
y.detach().cpu().numpy(),
kwargs_ls,
)
time_delays = time_delays - np.min(time_delays)
np.sort(time_delays)

# Compare time delays
assert np.allclose(tdc, time_delays, atol=1e-3)
Loading