@@ -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
349359def ordered_plane_redshifts_with_slicing_from (
0 commit comments