|
4 | 4 | import autoarray as aa |
5 | 5 | import autogalaxy as ag |
6 | 6 |
|
| 7 | +from autolens import exc |
| 8 | + |
7 | 9 |
|
8 | 10 | def plane_redshifts_from(galaxies: List[ag.Galaxy]) -> List[float]: |
9 | 11 | """ |
@@ -249,6 +251,92 @@ def grid_2d_at_redshift_from( |
249 | 251 | return traced_grid_list[plane_index_insert] |
250 | 252 |
|
251 | 253 |
|
| 254 | +def time_delays_from( |
| 255 | + galaxies: List[ag.Galaxy], |
| 256 | + grid: aa.type.Grid2DLike, |
| 257 | + cosmology: ag.cosmo.LensingCosmology = ag.cosmo.Planck15(), |
| 258 | +) -> aa.type.Grid2DLike: |
| 259 | + """ |
| 260 | + Returns the gravitational lensing time delay in days for a grid of 2D (y, x) coordinates. |
| 261 | +
|
| 262 | + This function calculates the time delay at each image-plane position due to both geometric and gravitational |
| 263 | + (Shapiro) effects, as described by the Fermat potential, which are computed using the deflection angles of the |
| 264 | + galaxies in the lens system. |
| 265 | +
|
| 266 | + It requires a two-plane system (lens and source), and does not currently support multi-plane time delay |
| 267 | + calculations involving more than two planes, but it could be extended to do so in the future. |
| 268 | +
|
| 269 | + The time delay is computed as: |
| 270 | +
|
| 271 | + .. math:: |
| 272 | + \Delta t(\boldsymbol{\theta}) = \frac{D_{\Delta t}}{c} \, \phi(\boldsymbol{\theta}) |
| 273 | +
|
| 274 | + where: |
| 275 | +
|
| 276 | + - \( \boldsymbol{\theta} \): image-plane coordinate |
| 277 | + - \( \phi(\boldsymbol{\theta}) \): Fermat potential at each coordinate |
| 278 | + - \( c \): speed of light |
| 279 | + - \( D_{\Delta t} \): time-delay distance |
| 280 | +
|
| 281 | + The time-delay distance is given by: |
| 282 | +
|
| 283 | + .. math:: |
| 284 | + D_{\Delta t} = (1 + z_l) \frac{D_d D_s}{D_{ds}} |
| 285 | +
|
| 286 | + with \( D_d, D_s, D_{ds} \) the angular diameter distances to the lens, to the source, and from lens to source. |
| 287 | +
|
| 288 | + The time delay is computed using the Fermat potential, |
| 289 | +
|
| 290 | + An input `AstroPy` cosmology object can change the cosmological model, which is used to compute the scaling |
| 291 | + factors between planes (which are derived from their redshifts and angular diameter distances). It is these |
| 292 | + scaling factors that account for multi-plane ray tracing effects. |
| 293 | +
|
| 294 | + Parameters |
| 295 | + ---------- |
| 296 | + galaxies |
| 297 | + List of galaxies whose mass profiles define the lens and source planes. Must contain exactly two redshifts. |
| 298 | + grid |
| 299 | + The 2D (y, x) image-plane coordinates where the time delay is computed. |
| 300 | + cosmology |
| 301 | + The cosmological model used to calculate angular diameter distances. Defaults to Planck15. |
| 302 | +
|
| 303 | + Returns |
| 304 | + ------- |
| 305 | + The time delay at each (y, x) coordinate in the input grid, in units of days. |
| 306 | + """ |
| 307 | + plane_redshifts = plane_redshifts_from(galaxies=galaxies) |
| 308 | + |
| 309 | + if len(plane_redshifts) != 2: |
| 310 | + raise exc.RayTracingException( |
| 311 | + "The time delay calculation requires exactly two planes, but the input galaxies have " |
| 312 | + f"{len(plane_redshifts)} planes with redshifts {plane_redshifts}." |
| 313 | + ) |
| 314 | + |
| 315 | + # Constants |
| 316 | + mpc_in_m = 3.08567758e22 # Mpc in meters |
| 317 | + arcsec_to_rad = np.deg2rad(1.0 / 3600.0) # arcsec to radians |
| 318 | + seconds_per_day = 86400 |
| 319 | + c = 299792458 # speed of light in m/s |
| 320 | + |
| 321 | + factor = arcsec_to_rad**2 / seconds_per_day |
| 322 | + |
| 323 | + # Angular diameter distances |
| 324 | + Dd = cosmology.angular_diameter_distance(plane_redshifts[0]).value # [Mpc] |
| 325 | + Ds = cosmology.angular_diameter_distance(plane_redshifts[1]).value # [Mpc] |
| 326 | + Dds = cosmology.angular_diameter_distance_z1z2( |
| 327 | + z1=plane_redshifts[0], z2=plane_redshifts[1] |
| 328 | + ).value # [Mpc] |
| 329 | + |
| 330 | + # Time-delay distance in meters |
| 331 | + D_dt = (1 + plane_redshifts[0]) * Dd * Ds / Dds * mpc_in_m |
| 332 | + |
| 333 | + # Fermat potential |
| 334 | + fermat_potential = galaxies.fermat_potential_from(grid=grid) |
| 335 | + |
| 336 | + # Final time delay in days |
| 337 | + return D_dt / c * fermat_potential * factor |
| 338 | + |
| 339 | + |
252 | 340 | def ordered_plane_redshifts_with_slicing_from( |
253 | 341 | lens_redshifts, planes_between_lenses, source_plane_redshift |
254 | 342 | ): |
|
0 commit comments