.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/relativity/lensing/plot_einstein_ring_and_microlensing.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_api_gallery_relativity_lensing_plot_einstein_ring_and_microlensing.py: Einstein rings, multiple images, and microlensing ========================================================== When a point source, a point (or compact) lens of mass :math:`M`, and an observer are exactly aligned, gravitational lensing bends the source's light into a complete ring of angular radius .. math:: \theta_E = \sqrt{\frac{4M D_{LS}}{D_L D_S}} -- an Einstein ring, predicted by Einstein in 1936 and finally imaged around a galaxy-scale lens in 1988, where :math:`D_L`, :math:`D_S`, and :math:`D_{LS}` are the observer-lens, observer-source, and lens-source distances. For any imperfect alignment (true angular source offset :math:`\beta \ne 0`), the thin-lens equation :math:`\beta = \theta - \theta_E^2/\theta` splits the source into two images at .. math:: \theta_\pm = \frac{\beta \pm \sqrt{\beta^2 + 4\theta_E^2}}{2} with a combined magnification (Paczynski 1986), in terms of :math:`u = \beta/\theta_E`, .. math:: \mu_\pm = \frac{1}{2}\left[\frac{u^2+2}{u\sqrt{u^2+4}} \pm 1\right] that can grow dramatically as the alignment tightens (:math:`u \to 0`) -- the basis of gravitational microlensing surveys, used to detect exoplanets and dark, compact objects that emit no light of their own. .. GENERATED FROM PYTHON SOURCE LINES 36-43 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from physicskit.relativity.chapters.lensing import PointMassLens, exact_deflection_angle from physicskit.relativity.chapters.schwarzschild import SchwarzschildBlackHole .. GENERATED FROM PYTHON SOURCE LINES 44-46 Image positions as the source moves across the lens ------------------------------------------------------------ .. GENERATED FROM PYTHON SOURCE LINES 46-71 .. code-block:: Python lens = PointMassLens(M=1.0, D_L=1000.0, D_S=2000.0) theta_E = lens.einstein_angle() print(f"Einstein ring angular radius: {theta_E:.5f} rad ({np.degrees(theta_E) * 3600:.2f} arcsec-equivalent)") beta_values = np.linspace(-4.0 * theta_E, 4.0 * theta_E, 200) theta_plus, theta_minus = lens.image_angles(beta_values) fig, ax = plt.subplots(figsize=(7, 5)) ax.plot(beta_values / theta_E, theta_plus / theta_E, label=r"$\theta_+$ (primary image)") ax.plot(beta_values / theta_E, theta_minus / theta_E, label=r"$\theta_-$ (secondary image)") ax.plot( beta_values / theta_E, beta_values / theta_E, "k--", linewidth=1, alpha=0.5, label="unlensed source", ) ax.axhline(0, color="gray", linewidth=0.5) ax.set_xlabel(r"source position $\beta / \theta_E$") ax.set_ylabel(r"image position $\theta / \theta_E$") ax.set_title("Point-lens image positions") ax.legend() plt.tight_layout() .. image-sg:: /api/gallery/relativity/lensing/images/sphx_glr_plot_einstein_ring_and_microlensing_001.png :alt: Point-lens image positions :srcset: /api/gallery/relativity/lensing/images/sphx_glr_plot_einstein_ring_and_microlensing_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Einstein ring angular radius: 0.04472 rad (9224.44 arcsec-equivalent) .. GENERATED FROM PYTHON SOURCE LINES 72-74 The microlensing magnification light curve ------------------------------------------------------------ .. GENERATED FROM PYTHON SOURCE LINES 74-86 .. code-block:: Python u_values = np.linspace(0.02, 3.0, 300) totals = np.array([lens.magnification(u * theta_E)[2] for u in u_values]) plt.figure(figsize=(7, 4.5)) plt.plot(u_values, totals) plt.axvline(1.0, color="k", linestyle="--", linewidth=1, alpha=0.5, label="$u=1$ (canonical threshold)") plt.xlabel(r"impact parameter $u = \beta/\theta_E$") plt.ylabel("total magnification") plt.title("Paczynski microlensing light curve") plt.legend() plt.tight_layout() .. image-sg:: /api/gallery/relativity/lensing/images/sphx_glr_plot_einstein_ring_and_microlensing_002.png :alt: Paczynski microlensing light curve :srcset: /api/gallery/relativity/lensing/images/sphx_glr_plot_einstein_ring_and_microlensing_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 87-94 Strong-field correction: the exact deflection angle vs. the weak-field 4M/b -------------------------------------------------------------------------------- :class:`PointMassLens` uses the weak-field deflection :math:`\hat\alpha(b) \approx 4M/b`, valid for :math:`b \gg M`. As the impact parameter shrinks toward the photon sphere, the true deflection (found here by numerically integrating the actual null geodesic) grows well beyond this linear estimate. .. GENERATED FROM PYTHON SOURCE LINES 94-101 .. code-block:: Python bh = SchwarzschildBlackHole(M=1.0) impact_params = np.array([200.0, 50.0, 20.0, 15.0]) for b in impact_params: exact = exact_deflection_angle(bh, b, n_steps=600000) weak = bh.light_deflection_angle(b) print(f"b={b:>6.1f}M: exact={exact:.4f} rad, weak-field 4M/b={weak:.4f} rad") .. rst-class:: sphx-glr-script-out .. code-block:: none b= 200.0M: exact=0.0188 rad, weak-field 4M/b=0.0200 rad b= 50.0M: exact=0.0847 rad, weak-field 4M/b=0.0800 rad b= 20.0M: exact=0.2360 rad, weak-field 4M/b=0.2000 rad b= 15.0M: exact=0.3363 rad, weak-field 4M/b=0.2667 rad .. GENERATED FROM PYTHON SOURCE LINES 102-111 The full 2D microlensing magnification map ------------------------------------------------------------ The light curve above only scans one straight-line path of the source behind the lens. Because :meth:`PointMassLens.magnification` depends only on the angular separation :math:`\beta`, evaluating it over an entire 2D grid of source offsets :math:`(\beta_x, \beta_y)` -- rather than along a single 1D track -- traces out the full magnification map any real microlensing survey scans across as source and lens drift past each other, with the Einstein ring (:math:`u=\beta/\theta_E=1`) as its natural scale. .. GENERATED FROM PYTHON SOURCE LINES 111-133 .. code-block:: Python n_grid = 300 extent = 3.0 * theta_E bx = np.linspace(-extent, extent, n_grid) by = np.linspace(-extent, extent, n_grid) BX, BY = np.meshgrid(bx, by) beta_mag = np.sqrt(BX**2 + BY**2) beta_mag[beta_mag < 1.0e-6 * theta_E] = 1.0e-6 * theta_E # avoid the beta=0 singularity _, _, total_mag = lens.magnification(beta_mag) fig, ax = plt.subplots(figsize=(6.5, 5.5)) im = ax.pcolormesh(bx / theta_E, by / theta_E, np.log10(total_mag), shading="auto", cmap="inferno") plt.colorbar(im, ax=ax, label=r"$\log_{10}$(total magnification)") ring = plt.Circle((0, 0), 1.0, fill=False, color="cyan", linestyle="--", linewidth=1.5) ax.add_patch(ring) ax.plot([], [], color="cyan", linestyle="--", label="Einstein ring (u=1)") ax.set_aspect("equal") ax.set_xlabel(r"$\beta_x / \theta_E$") ax.set_ylabel(r"$\beta_y / \theta_E$") ax.set_title("2D microlensing magnification map") ax.legend(loc="upper right", fontsize=8) plt.tight_layout() plt.show() .. image-sg:: /api/gallery/relativity/lensing/images/sphx_glr_plot_einstein_ring_and_microlensing_003.png :alt: 2D microlensing magnification map :srcset: /api/gallery/relativity/lensing/images/sphx_glr_plot_einstein_ring_and_microlensing_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.833 seconds) .. _sphx_glr_download_api_gallery_relativity_lensing_plot_einstein_ring_and_microlensing.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_einstein_ring_and_microlensing.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_einstein_ring_and_microlensing.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_einstein_ring_and_microlensing.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_