{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Plot line cut, volume cut, through z-stack\n\nThis demo shows how the ``itom.plot`` ``1D line cut``,\n``2D volume cut`` and ``through z-stack`` feature are used. First, a 3D ``dataObject``\nis created representing a Gaussian 2D profile along the beam waist.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from itom import dataObject\nfrom itom import plot\nimport numpy as np" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Function to calculate 2D Gaussian beam profile.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "def gaussianBeam2D(xValues: float, yValues: float, fwhm: float, centroid: list, amplitude: float) -> np.ndarray:\n \"\"\"Create 2D Gaussian Beam intensity.\n\n Args:\n xValues (float): X value vector\n yValues (float): Y value vector\n fwhm (float): Full width half maximum of the Gauss\n centroid (list): Centroid position of the Gauss\n amplitude (float): Amplitude of Gauss\n\n Returns:\n np.ndarray: 2D Gaussian intensity profile.\n \"\"\"\n intensity = amplitude * np.exp(\n -4 * np.log(2) * ((xValues - centroid[0]) ** 2 + (yValues - centroid[1]) ** 2) / fwhm**2\n )\n return np.array(intensity)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Calculate waist vs. z vector.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "def waistAtZ(w0: float, zValues: np.ndarray, RayleighLength: float) -> np.ndarray:\n \"\"\"Calculate w0 at z position.\n\n Args:\n w0 (float): Waist radius.\n zValues (np.ndarray): Z value vector\n RayleighLength (float): Rayleigh length.\n\n Returns:\n float: Waist vs. z position vector.\n \"\"\"\n omegaZ = w0 * np.sqrt(1 + ((zValues) / (RayleighLength)) ** 2)\n return omegaZ" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Define some variables.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "zSampling = 100\nxSampling = 640\nySampling = 640\n\nzRange = [-100, 100]\nxRange = [-30, 30]\n\n# Scaling value is sampline - 1\nzScale = np.abs(zRange[1] - zRange[0]) / (zSampling - 1)\nzOffset = (zSampling - 1) / 2\n\nxScale = np.abs(xRange[1] - xRange[0]) / (xSampling - 1)\nxOffset = (xSampling - 1) / 2\n\nzValues = np.linspace(zRange[0], zRange[1], zSampling)\nxValues = np.linspace(xRange[0], xRange[1], xSampling)\nyValues = xValues[:, np.newaxis]\n\nRayleightL = 20\ncentroidPos = [0, 0]\namplitude = 1" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Calculate Gaussian 2D profile at Z positions as a 3D ``dataObject`` of shape ``[z, y, x]``.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "widthZ = waistAtZ(5, zValues, RayleightL)\ngauss3D = dataObject([zSampling, ySampling, xSampling], \"float64\")\n\nfor cnt in range(0, gauss3D.shape[0]):\n gauss3D[cnt, :, :] = gaussianBeam2D(xValues, yValues, widthZ[cnt], centroidPos, amplitude)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Define the 3D meta information.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "gauss3D.setAxisDescription(0, \"z axis\")\ngauss3D.setAxisDescription(1, \"y axis\")\ngauss3D.setAxisDescription(2, \"x axis\")\ngauss3D.setAxisUnit(0, \"\\u00B5m\")\ngauss3D.setAxisUnit(2, \"\\u00B5m\")\ngauss3D.setAxisUnit(1, \"\\u00B5m\")\ngauss3D.setAxisScale(0, zScale)\ngauss3D.setAxisScale(1, xScale)\ngauss3D.setAxisScale(2, xScale)\ngauss3D.setAxisOffset(0, zOffset)\ngauss3D.setAxisOffset(1, xOffset)\ngauss3D.setAxisOffset(2, xOffset)\ngauss3D.valueDescription = \"intensity\"\ngauss3D.valueUnit = \"a. u.\"" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Generate further ``volume``, ``line`` plots from the 3D stack.\n\nPer default the ``z=0`` plane is plotted. Above the image there are buttons to cut the 3D stack.\n\nIn this 3D stack plot, a sectional view through the volume can now be generated shown in the upper right plot.\nFurthermore, a line cut between two pixels can be created form this 2D plot shown in the lower right plot.\n\nIn this plot, a distance between two pixels can then be calculated by the ``picker``. In this example, the\nGaussien width is about 6.47 \\\\u00B5m.\n\nAdditionally a line cut ``through z`` can be created shown in the lower left plot.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "plot(gauss3D, properties={\"keepAspectRatio\": True, \"colorMap\": \"viridis\"})" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n\n" ] } ], "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.8.10" } }, "nbformat": 4, "nbformat_minor": 0 }