Skip to content

Commit ae2a010

Browse files
authored
Merge pull request #382 from Jammy2211/feature/cosmology_jax
Feature/cosmology jax
2 parents addb7b3 + c798247 commit ae2a010

5 files changed

Lines changed: 37 additions & 27 deletions

File tree

autolens/analysis/analysis/dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def __init__(
5959
Contains the adapt-images which are used to make a pixelization's mesh and regularization adapt to the
6060
reconstructed galaxy's morphology.
6161
cosmology
62-
The AstroPy Cosmology assumed for this analysis.
62+
The Cosmology assumed for this analysis.
6363
settings_inversion
6464
Settings controlling how an inversion is fitted during the model-fit, for example which linear algebra
6565
formalism is used.

autolens/analysis/analysis/lens.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def __init__(
4040
cosmology
4141
The Cosmology assumed for this analysis.
4242
"""
43-
from autogalaxy.cosmology.wrap import Planck15
43+
from autogalaxy.cosmology.model import Planck15
4444

4545
self.cosmology = cosmology or Planck15()
4646
self.positions_likelihood_list = positions_likelihood_list

autolens/lens/tracer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ def traced_grid_2d_list_from(
231231
returned list of traced grids will contain three entries corresponding to the input grid after ray-tracing to
232232
redshifts 0.5, 1.0 and 2.0.
233233
234-
An input `AstroPy` cosmology object can change the cosmological model, which is used to compute the scaling
234+
An input cosmology object can change the cosmological model, which is used to compute the scaling
235235
factors between planes (which are derived from their redshifts and angular diameter distances). It is these
236236
scaling factors that account for multi-plane ray tracing effects.
237237
@@ -308,7 +308,7 @@ def grid_2d_at_redshift_from(
308308
at a set of redshift. The galaxy mass profiles are used to compute deflection angles. Any redshift can be input
309309
even if a plane does not exist there, including redshifts before the first plane of the lens system.
310310
311-
An input `AstroPy` cosmology object can change the cosmological model, which is used to compute the scaling
311+
An input cosmology object can change the cosmological model, which is used to compute the scaling
312312
factors between planes (which are derived from their redshifts and angular diameter distances). It is these
313313
scaling factors that account for multi-plane ray tracing effects.
314314

autolens/lens/tracer_util.py

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def traced_grid_2d_list_from(
106106
returned list of traced grids will contain three entries corresponding to the input grid after ray-tracing to
107107
redshifts 0.5, 1.0 and 2.0.
108108
109-
An input `AstroPy` cosmology object can change the cosmological model, which is used to compute the scaling
109+
An input cosmology object can change the cosmological model, which is used to compute the scaling
110110
factors between planes (which are derived from their redshifts and angular diameter distances). It is these
111111
scaling factors that account for multi-plane ray tracing effects.
112112
@@ -152,6 +152,7 @@ def traced_grid_2d_list_from(
152152
redshift_0=redshift_list[previous_plane_index],
153153
redshift_1=galaxies[0].redshift,
154154
redshift_final=redshift_list[-1],
155+
xp=xp,
155156
)
156157

157158
scaled_deflections = (
@@ -193,7 +194,7 @@ def grid_2d_at_redshift_from(
193194
at a set of redshift. The galaxy mass profiles are used to compute deflection angles. Any redshift can be input
194195
even if a plane does not exist there, including redshifts before the first plane of the lens system.
195196
196-
An input `AstroPy` cosmology object can change the cosmological model, which is used to compute the scaling
197+
An input cosmology object can change the cosmological model, which is used to compute the scaling
197198
factors between planes (which are derived from their redshifts and angular diameter distances). It is these
198199
scaling factors that account for multi-plane ray tracing effects.
199200
@@ -292,9 +293,9 @@ def time_delays_from(
292293
293294
with \( D_d, D_s, D_{ds} \) the angular diameter distances to the lens, to the source, and from lens to source.
294295
295-
The time delay is computed using the Fermat potential,
296+
The time delay is computed using the Fermat potential, as described by the equations above.
296297
297-
An input `AstroPy` cosmology object can change the cosmological model, which is used to compute the scaling
298+
An input cosmology object can change the cosmological model, which is used to compute the scaling
298299
factors between planes (which are derived from their redshifts and angular diameter distances). It is these
299300
scaling factors that account for multi-plane ray tracing effects.
300301
@@ -321,29 +322,38 @@ def time_delays_from(
321322
f"{len(plane_redshifts)} planes with redshifts {plane_redshifts}."
322323
)
323324

324-
# Constants
325-
mpc_in_m = 3.08567758e22 # Mpc in meters
326-
arcsec_to_rad = np.deg2rad(1.0 / 3600.0) # arcsec to radians
327-
seconds_per_day = 86400
328-
c = 299792458 # speed of light in m/s
329-
330-
factor = arcsec_to_rad**2 / seconds_per_day
331-
332-
# Angular diameter distances
333-
Dd = cosmology.angular_diameter_distance(plane_redshifts[0]).value # [Mpc]
334-
Ds = cosmology.angular_diameter_distance(plane_redshifts[1]).value # [Mpc]
335-
Dds = cosmology.angular_diameter_distance_z1z2(
336-
z1=plane_redshifts[0], z2=plane_redshifts[1]
337-
).value # [Mpc]
325+
z_l, z_s = plane_redshifts[0], plane_redshifts[1]
326+
327+
# -----------------
328+
# Constants (SI)
329+
# -----------------
330+
kpc_in_m = xp.asarray(3.085677581491367e19) # kpc in meters
331+
arcsec_to_rad = xp.pi / 648000.0 # arcsec -> rad (pi / (180*3600))
332+
seconds_per_day = xp.asarray(86400.0)
333+
c = xp.asarray(299792458.0) # m/s
334+
335+
# This factor converts Fermat potential in arcsec^2 into days once multiplied by D_dt/c
336+
factor = (arcsec_to_rad * arcsec_to_rad) / seconds_per_day
337+
338+
# -----------------
339+
# Angular diameter distances (kpc)
340+
# -----------------
341+
Dd_kpc = cosmology.angular_diameter_distance_to_earth_in_kpc_from(z_l, xp=xp)
342+
Ds_kpc = cosmology.angular_diameter_distance_to_earth_in_kpc_from(z_s, xp=xp)
343+
Dds_kpc = cosmology.angular_diameter_distance_between_redshifts_in_kpc_from(
344+
redshift_0=z_l, redshift_1=z_s, xp=xp
345+
)
338346

339-
# Time-delay distance in meters
340-
D_dt = (1 + plane_redshifts[0]) * Dd * Ds / Dds * mpc_in_m
347+
# Time-delay distance in meters: (1+z_l) * Dd * Ds / Dds
348+
D_dt_m = (
349+
(1.0 + z_l) * (Dd_kpc * Ds_kpc / Dds_kpc) * kpc_in_m
350+
)
341351

342-
# Fermat potential
352+
# Fermat potential (should be in arcsec^2 for this formula)
343353
fermat_potential = galaxies.fermat_potential_from(grid=grid, xp=xp)
344354

345355
# Final time delay in days
346-
return D_dt / c * fermat_potential * factor
356+
return (D_dt_m / c) * fermat_potential * factor
347357

348358

349359
def ordered_plane_redshifts_with_slicing_from(

test_autolens/lens/test_tracer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,7 @@ def test__output_to_and_load_from_json():
896896
g0 = al.Galaxy(redshift=0.5, mass_profile=al.mp.IsothermalSph(einstein_radius=1.0))
897897
g1 = al.Galaxy(redshift=1.0)
898898

899-
tracer = al.Tracer(galaxies=[g0, g1], cosmology=al.cosmo.wrap.Planck15())
899+
tracer = al.Tracer(galaxies=[g0, g1], cosmology=al.cosmo.Planck15())
900900

901901
output_to_json(tracer, file_path=json_file)
902902

0 commit comments

Comments
 (0)