Skip to content

Commit

Permalink
Merge pull request #299 from Ciela-Institute/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
ConnorStoneAstro authored Jan 14, 2025
2 parents 0f16b02 + 9c66dfc commit a6bd307
Show file tree
Hide file tree
Showing 9 changed files with 1,595 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
ls -ltrh
ls -ltrh dist
- name: Publish to Test PyPI
uses: pypa/[email protected].2
uses: pypa/[email protected].3
with:
repository-url: https://test.pypi.org/legacy/
verbose: true
Expand Down Expand Up @@ -95,5 +95,5 @@ jobs:
name: artifact
path: dist

- uses: pypa/[email protected].2
- uses: pypa/[email protected].3
if: startsWith(github.ref, 'refs/tags')
1 change: 1 addition & 0 deletions docs/source/_toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ chapters:
- file: getting_started
- file: install
- file: websim
- file: gravlensingintro
- file: tutorials/index
sections:
- file: tutorials/Introduction
Expand Down
Binary file added docs/source/assets/Einstein.npy
Binary file not shown.
Binary file added docs/source/assets/lensconfiguration.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/assets/multiplanelensing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1,540 changes: 1,540 additions & 0 deletions docs/source/gravlensingintro.ipynb

Large diffs are not rendered by default.

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)

0 comments on commit a6bd307

Please sign in to comment.