{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Simple propagation\n\nBasic example of physical optics propagation through a simple optical system \nconsisting of a square aperture illuminated by a point source and focused by\na thin lens.\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Import libraries required for simulation\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": [ "Create the wavefront arriving at the first plane of the optical system as \ndescribed in :doc:`point_source`. Check the section about propagation for \nsome tips about the definition of the mesh parameters.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "ptSrc = srw.emitters.PointSource()\n\nobserver = srw.wavefronts.Observer(centerCoord=[0, 0, .5],\n obsXextension=10e-3, \n obsYextension=10e-3,\n obsXres=1e-6,\n obsYres=1e-6)\n\nwfr = srw.computePtSrcWfr(ptSrc, observer, wavelength=600)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We use a basic optical system consisting of a square aperture and a thin lens\nand we observe the intensity at the image plane of the lens.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "w = 500e-6\nf = 50e-3\ns1 = observer.zPos\ns2 = s1 * f / (s1 - f)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The optical system is created as a dictionary representing the three optical \nelements. Note that \"aperture\", \"lens\" and \"image\" are arbitrary names. The \nnature of each optical element is defined by its \"type\" key\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "optSystem = {\n \"aperture\": {\n \"type\": \"rectAp\",\n \"extension\": [w, w],\n \"centre\": [0,0]\n },\n \"lens\": {\n \"type\": \"lens\",\n \"f\": f,\n \"centre\": [0,0]\n },\n \"image\": {\n \"type\": \"drift\",\n \"length\": s2\n }\n}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The propagation is performed using the \n:py:func:`~pysrw.computations.propagateWfr` function. Since we leave all \noptional arguments to their default values, the sequence [\"lens\", \"drift\"] \nwill be grouped, the intensity stored on all planes and the wavefront only\nat the last \"image\" plane.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "propData = srw.propagateWfr(wfr, optSystem)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We plot the resulting intensity distribution at the \"aperture\" and\n\"image\" planes\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "srw.plotI(propData[\"aperture\"][\"intensity\"])\nsrw.plotI(propData[\"image\"][\"intensity\"])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As expected, the final spot is much smaller with respect to the simulated \nwavefront. The extended wavefront is necessary at the entrance of the optical\nsystem, to leave enough margin around the aperture. However, the extension \ncan be significantly reduced at the image plane, as the light is focused by\nthe lens. This can be achieved by adding some resize parameters to reduce \nby a factor 10 the extension and increase by a factor 2 the resolution to \nobtain a smoother profile\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "optSystem[\"image\"][\"resParam\"] = {\"hRangeChange\": 1/10, \"hResChange\": 2.0,\n \"vRangeChange\": 1/10, \"vResChange\": 2.0,\n \"hCentreChange\": 0.0, \"vCentreChange\": 0.0}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The computation is then repeated. To save time and memory, we store the \nintensity only at the final \"image\" plane\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "propData = srw.propagateWfr(wfr, optSystem, saveIntAt=[\"image\"])\nsrw.plotI(propData[\"image\"][\"intensity\"])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can finally extract a profile and compare the simulated pattern with the\nsinc profile of the diffraction from a rectangular aperture\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "cuts = srw.extractCrossCuts(propData[\"image\"][\"intensity\"])\nyax = cuts[\"yax\"]\nint_srw = cuts[\"ydata\"]\nint_theo = np.sinc(w * yax / (s2 * wfr.wavelength*1e-9))**2\n\nfig, ax = plt.subplots()\nax.plot(yax*1e3, int_srw / np.max(int_srw))\nax.plot(yax*1e3, int_theo, label=\"theo\", linestyle=\"--\")\nax.set_xlabel(\"y position [mm]\")\nax.set_ylabel(\"Intensity [arb. unit]\")\nax.legend()\nplt.show()\nplt.tight_layout()" ] } ], "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 }