.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/gaussian_beam.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_examples_gaussian_beam.py: Gaussian beam ============= Basic example of computation of the field emitted by a coherent Gaussian beam. .. GENERATED FROM PYTHON SOURCE LINES 9-10 Import required libraries .. GENERATED FROM PYTHON SOURCE LINES 10-16 .. code-block:: default import matplotlib.pyplot as plt import numpy as np import pysrw as srw .. GENERATED FROM PYTHON SOURCE LINES 17-19 Starts creating a coherent Gaussian beam with a waist of 20 um. We leave the default initial position and angle of the source (all zero) .. GENERATED FROM PYTHON SOURCE LINES 19-22 .. code-block:: default sigma = 20e-6 gsnBeam = srw.emitters.GaussianBeam(xSigma=sigma, ySigma=sigma) .. GENERATED FROM PYTHON SOURCE LINES 23-25 Create a 10 mm x 10 mm observation mesh, with a resolution of 100 um, placed 1 m downstream of the source .. GENERATED FROM PYTHON SOURCE LINES 25-31 .. code-block:: default observer = srw.wavefronts.Observer(centerCoord=[0, 0, 1], obsXextension=10e-3, obsYextension=10e-3, obsXres=100e-6, obsYres=100e-6) .. GENERATED FROM PYTHON SOURCE LINES 32-34 Compute the wavefront at the observation wavelength of 600 nm. The multiprocessing version is reported for comparison .. GENERATED FROM PYTHON SOURCE LINES 34-38 .. code-block:: default wl = 600 wfr = srw.computeGsnBeamWfr(gsnBeam, observer, wavelength=wl) wfr_mp = srw.computeGsnBeamWfrMultiProcess(4, gsnBeam, observer, wavelength=600) .. GENERATED FROM PYTHON SOURCE LINES 39-40 Compute the corresponding optical intensity .. GENERATED FROM PYTHON SOURCE LINES 40-43 .. code-block:: default intensity = wfr.getWfrI() intensity_mp = wfr_mp.getWfrI() .. GENERATED FROM PYTHON SOURCE LINES 44-45 Plot the 2D intensity distribution .. GENERATED FROM PYTHON SOURCE LINES 45-48 .. code-block:: default srw.plotI(intensity) srw.plotI(intensity_mp) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /examples/images/sphx_glr_gaussian_beam_001.png :alt: gaussian beam :srcset: /examples/images/sphx_glr_gaussian_beam_001.png :class: sphx-glr-multi-img * .. image-sg:: /examples/images/sphx_glr_gaussian_beam_002.png :alt: gaussian beam :srcset: /examples/images/sphx_glr_gaussian_beam_002.png :class: sphx-glr-multi-img .. GENERATED FROM PYTHON SOURCE LINES 49-50 Extract cross-cut using :py:func:`~pysrw.tools.extractCrossCuts` .. GENERATED FROM PYTHON SOURCE LINES 50-54 .. code-block:: default crosscuts = srw.extractCrossCuts(intensity) xax = crosscuts["xax"] xcut = crosscuts["xdata"] .. GENERATED FROM PYTHON SOURCE LINES 55-59 Compare the intensity profile with the theoretical distribution. For a Gaussian beam :math:`\sigma \cdot \sigma' = \lambda / 4 \pi`. We omit the spherical attenuation as it's negligible with respect to the decay due to the finite divergence of the beam .. GENERATED FROM PYTHON SOURCE LINES 59-62 .. code-block:: default sigma_p = wl*1e-9 / (4 * np.pi * sigma) #rad xcut_theo = srw.gaussian1p(xax, sigma_p * observer.zPos) .. GENERATED FROM PYTHON SOURCE LINES 63-64 Summary plot of the intensity cuts .. GENERATED FROM PYTHON SOURCE LINES 64-70 .. code-block:: default fig, ax = plt.subplots() ax.plot(xax * 1e3, xcut, label="sim") ax.plot(xax * 1e3, np.max(xcut) * xcut_theo, linestyle="--", label="theo") ax.set_xlabel("x position [mm]") ax.set_ylabel("Intensity [ph/(s mm^2 0.1%BW)]") ax.legend() plt.show() .. image-sg:: /examples/images/sphx_glr_gaussian_beam_003.png :alt: gaussian beam :srcset: /examples/images/sphx_glr_gaussian_beam_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.796 seconds) **Estimated memory usage:** 10 MB .. _sphx_glr_download_examples_gaussian_beam.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: gaussian_beam.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: gaussian_beam.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_