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

added time delays and observer times for time series predictions #52

Merged
merged 2 commits into from
Sep 11, 2023
Merged
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
35 changes: 35 additions & 0 deletions sim_pipeline/galaxy_galaxy_lens.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,41 @@ def deflector_magnitude(self, band):
band_string = str("mag_" + band)
return self._lens_dict[band_string]

def point_source_arrival_times(self):
"""Arrival time of images relative to a straight line without lensing. Negative
values correspond to images arriving earlier, and positive signs correspond to
images arriving later.

:return: arrival times for each image [days]
:rtype: numpy array
"""
lens_model_list, kwargs_lens = self.lens_model_lenstronomy()
lens_model = LensModel(
lens_model_list=lens_model_list,
cosmo=self.cosmo,
z_lens=self.lens_redshift,
z_source=self.source_redshift,
)
x_image, y_image = self.image_positions()
arrival_times = lens_model.arrival_time(
x_image, y_image, kwargs_lens=kwargs_lens
)
return arrival_times

def image_observer_times(self, t_obs):
"""Calculates time of the source at the different images, not correcting for
redshifts, but for time delays. The time is relative to the first arriving
image.

:param t_obs: time of observation [days]
:return: time of the source when seen in the different images (without redshift
correction)
:rtype: numpy array
"""
arrival_times = self.point_source_arrival_times()
observer_times = t_obs + arrival_times - np.min(arrival_times)
return observer_times

def point_source_magnitude(self, band, lensed=False):
"""Point source magnitude, either unlensed (single value) or lensed (array) with
macro-model magnifications.
Expand Down
14 changes: 14 additions & 0 deletions tests/test_galaxy_galaxy_lens.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import pytest
import numpy as np
from numpy import testing as npt
from astropy.cosmology import FlatLambdaCDM
from astropy.table import Table
from sim_pipeline.galaxy_galaxy_lens import (
Expand Down Expand Up @@ -86,6 +88,18 @@ def test_los_linear_distortions(self):
losd = self.gg_lens.los_linear_distortions()
assert losd != 0

def test_point_source_arrival_times(self):
dt_days = self.gg_lens.point_source_arrival_times()
assert np.min(dt_days) > -1000
assert np.max(dt_days) < 1000

def test_image_observer_times(self):
t_obs = 1000
dt_days = self.gg_lens.image_observer_times(t_obs=t_obs)
arrival_times = self.gg_lens.point_source_arrival_times()
observer_times = t_obs + arrival_times - np.min(arrival_times)
npt.assert_almost_equal(dt_days, observer_times, decimal=5)


if __name__ == "__main__":
pytest.main()