.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_demos/demo.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_auto_demos_demo.py: Fresnel Propagator demo ======================= This demo will compute and display the Fresnel transform of a given aperture. .. GENERATED FROM PYTHON SOURCE LINES 6-13 .. code-block:: default import numpy as np from matplotlib import pyplot as plt from optics.propagators import FresnelPropagator from typing import Sequence .. GENERATED FROM PYTHON SOURCE LINES 14-17 Build the aperture ------------------ First we define a circle function. .. GENERATED FROM PYTHON SOURCE LINES 17-27 .. code-block:: default def circle(shape: Sequence[int], radius: float): """Create a circle of a given radius centered in an array of a given shape.""" for dim in shape: assert radius < dim x, y = np.meshgrid(np.arange(shape[0]), np.arange(shape[1])) r = np.abs((x - (shape[0] - 1) / 2) ** 2 + (y - (shape[1] - 1) / 2) ** 2) < radius ** 2 return r.astype('int') .. GENERATED FROM PYTHON SOURCE LINES 28-29 Then we define some parameters and build the aperture. .. GENERATED FROM PYTHON SOURCE LINES 29-44 .. code-block:: default input_shape = (300, 300) dx = (1e-2, 1e-2) z = 1e5 wavelength = 1e-6 aperture = circle(shape=input_shape, radius=50) aperture = aperture - circle(shape=input_shape, radius=10) diag_idx = np.diag_indices(300) aperture[diag_idx[0], diag_idx[1]] = 0 aperture[np.flip(diag_idx[0]), diag_idx[1]] = 0 plt.imshow(aperture) plt.title('Aperture') plt.show() .. image-sg:: /auto_demos/images/sphx_glr_demo_001.png :alt: Aperture :srcset: /auto_demos/images/sphx_glr_demo_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 45-47 Call the Fresnel Propagator --------------------------- .. GENERATED FROM PYTHON SOURCE LINES 47-56 .. code-block:: default fresnel_propagator = FresnelPropagator( input_shape=input_shape, dx=dx, z=z, wavelength=wavelength, ) y = fresnel_propagator(aperture) .. GENERATED FROM PYTHON SOURCE LINES 57-59 Plot the field at distance :math:`z` ------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 59-66 .. code-block:: default fig, (ax1, ax2) = plt.subplots(1, 2) ax1.imshow(abs(y) ** 2) ax1.set_title("Intensity") ax2.imshow(np.angle(y)) ax2.set_title("Phase") plt.show() .. image-sg:: /auto_demos/images/sphx_glr_demo_002.png :alt: Intensity, Phase :srcset: /auto_demos/images/sphx_glr_demo_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.283 seconds) .. _sphx_glr_download_auto_demos_demo.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: demo.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: demo.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_