{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Point source\n\nBasic example of computation of the field emitted by an isotropic point source.\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": [ "Ccreate the point emitter radiating 1 ph/(s mm^2)\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "ptSrc = srw.emitters.PointSource(flux=1)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create a 10 mm x 10 mm observation mesh, with a resolution of 10 um, \nplaced 10 cm 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=10e-6,\n obsYres=10e-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": [ "wfr = srw.computePtSrcWfr(ptSrc, observer, wavelength=600)\nwfr_mp = srw.computePtSrcWfrMultiProcess(4, ptSrc, 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 with the intensity decay due to spherical attenuation\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "theta = np.arctan(xax / observer.zPos)\nxcut_theo = 1/(4 * np.pi * observer.zPos**2) * np.cos(theta)**3 * 1e-6 # ph / (s mm^2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Plot the resulting 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, 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 }