{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Gaussian beam\n\nBasic example of computation of the field emitted by a coherent Gaussian beam.\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Import required libraries\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import matplotlib.pyplot as plt\nimport numpy as np\n\nimport pysrw as srw" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Starts creating a coherent Gaussian beam with a waist of 20 um.\nWe leave the default initial position and angle of the source (all zero)\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "sigma = 20e-6\ngsnBeam = srw.emitters.GaussianBeam(xSigma=sigma, ySigma=sigma)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create a 10 mm x 10 mm observation mesh, with a resolution of 100 um, \nplaced 1 m downstream of the source\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "observer = srw.wavefronts.Observer(centerCoord=[0, 0, 1],\n obsXextension=10e-3, \n obsYextension=10e-3,\n obsXres=100e-6,\n obsYres=100e-6)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Compute the wavefront at the observation wavelength of 600 nm.\nThe multiprocessing version is reported for comparison\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "wl = 600\nwfr = srw.computeGsnBeamWfr(gsnBeam, observer, wavelength=wl)\nwfr_mp = srw.computeGsnBeamWfrMultiProcess(4, gsnBeam, observer, wavelength=600)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Compute the corresponding optical intensity\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "intensity = wfr.getWfrI()\nintensity_mp = wfr_mp.getWfrI()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Plot the 2D intensity distribution\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "srw.plotI(intensity)\nsrw.plotI(intensity_mp)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Extract cross-cut using :py:func:`~pysrw.tools.extractCrossCuts`\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "crosscuts = srw.extractCrossCuts(intensity)\nxax = crosscuts[\"xax\"]\nxcut = crosscuts[\"xdata\"]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Compare the intensity profile with the theoretical distribution.\nFor a Gaussian beam $\\sigma \\cdot \\sigma' = \\lambda / 4 \\pi$.\nWe omit the spherical attenuation as it's negligible with respect to the \ndecay due to the finite divergence of the beam\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "sigma_p = wl*1e-9 / (4 * np.pi * sigma) #rad\nxcut_theo = srw.gaussian1p(xax, sigma_p * observer.zPos)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Summary plot of the intensity cuts\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "fig, ax = plt.subplots()\nax.plot(xax * 1e3, xcut, label=\"sim\")\nax.plot(xax * 1e3, np.max(xcut) * xcut_theo, linestyle=\"--\", label=\"theo\")\nax.set_xlabel(\"x position [mm]\")\nax.set_ylabel(\"Intensity [ph/(s mm^2 0.1%BW)]\")\nax.legend()\nplt.show()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.9" } }, "nbformat": 4, "nbformat_minor": 0 }