Skip to content

Commit 16539ed

Browse files
Jammy2211Jammy2211
authored andcommitted
fix time_delays_from removing astropy API
1 parent 8771e6d commit 16539ed

1 file changed

Lines changed: 25 additions & 18 deletions

File tree

autolens/lens/tracer_util.py

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -322,29 +322,36 @@ def time_delays_from(
322322
f"{len(plane_redshifts)} planes with redshifts {plane_redshifts}."
323323
)
324324

325-
# Constants
326-
mpc_in_m = 3.08567758e22 # Mpc in meters
327-
arcsec_to_rad = np.deg2rad(1.0 / 3600.0) # arcsec to radians
328-
seconds_per_day = 86400
329-
c = 299792458 # speed of light in m/s
330-
331-
factor = arcsec_to_rad**2 / seconds_per_day
332-
333-
# Angular diameter distances
334-
Dd = cosmology.angular_diameter_distance(plane_redshifts[0]).value # [Mpc]
335-
Ds = cosmology.angular_diameter_distance(plane_redshifts[1]).value # [Mpc]
336-
Dds = cosmology.angular_diameter_distance_z1z2(
337-
z1=plane_redshifts[0], z2=plane_redshifts[1]
338-
).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.asarray(np.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+
)
339346

340-
# Time-delay distance in meters
341-
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 = (xp.asarray(1.0) + xp.asarray(z_l)) * (Dd_kpc * Ds_kpc / Dds_kpc) * kpc_in_m
342349

343-
# Fermat potential
350+
# Fermat potential (should be in arcsec^2 for this formula)
344351
fermat_potential = galaxies.fermat_potential_from(grid=grid, xp=xp)
345352

346353
# Final time delay in days
347-
return D_dt / c * fermat_potential * factor
354+
return (D_dt_m / c) * fermat_potential * factor
348355

349356

350357
def ordered_plane_redshifts_with_slicing_from(

0 commit comments

Comments
 (0)