### LightPipes Examples Source: https://github.com/opticspy/lightpipes/blob/master/docs/genindex.html This section provides links to various examples demonstrating the usage of LightPipes for different optical phenomena and setups. ```APIDOC ## LightPipes Examples This section provides practical examples of using the LightPipes library for various optical simulations. ### Example Categories: * **Airy beam**: Demonstrates the creation and manipulation of Airy beams (1D and 2D). * **Annular slit**: Shows simulations involving annular slits. * **Arago spot**: Illustrates the generation of an Arago spot. * **Axicon**: Examples using the Axicon function. * **Bessel beam**: Demonstrates Bessel beam simulations. * **Circular Aperture**: Examples related to circular apertures. * **Circular Screen**: Examples involving circular screens. * **Computer practical**: Practical exercises using the library. * **Doughnut mode**: Examples of simulating doughnut laser modes. * **Fabry Perot interferometer**: Demonstrations of Fabry-Perot interferometry. * **Forward propagation**: Examples of forward propagation simulations. * **Interference**: Examples related to optical interference. * **Michelson Interferometer**: Simulations of a Michelson interferometer. * **Poisson Spot**: Examples demonstrating the Poisson spot phenomenon. * **Resonator geometric optics**: Examples related to geometric optics in resonators. * **Spherical Wavefront**: Simulations involving spherical wavefronts. * **Transformation to Doughnut Mode**: Examples of transforming beams into doughnut modes. * **Two Holes**: Experiments involving diffraction through two holes. * **Zernike Aberrations**: Examples of simulating Zernike aberrations. * **Young's Experiment**: Demonstrations of Young's double-slit experiment. ``` -------------------------------- ### Configure, build, and install FFTW Source: https://github.com/opticspy/lightpipes/blob/master/docs/_sources/install.rst.txt Commands to configure, compile, and install the FFTW library from source. This is part of the manual installation process for pyFFTW on specific architectures. ```bash cd fftw-3.3.9 ./configure --enable-threads --enable-shared make sudo make install ``` -------------------------------- ### Download and Install FFTW Source: https://github.com/opticspy/lightpipes/blob/master/docs/install.html Commands to download, configure, and install the FFTW library from source. ```bash cd ~/Downloads tar xzf fftw-3.3.9.tar.gz ``` ```bash cd fftw-3.3.9 ./configure --enable-threads --enable-shared make sudo make install ``` -------------------------------- ### Incorrect Waveguide Propagation Example Source: https://github.com/opticspy/lightpipes/blob/master/docs/manual.html This example demonstrates an incorrect setup where the grid size matches the aperture size, causing unwanted waveguide reflections. ```python from LightPipes import * import matplotlib.pyplot as plt Field=Begin(20*mm, 1*um, 256) Field = RectAperture(20*mm,20*mm,0, 0,0, Field) Field = Forvard(1*m, Field) I = Intensity(0,Field) x=[] for i in range(256): x.append((-20*mm/2+i*20*mm/256)/mm) fig=plt.figure(figsize=(15,6)) ax1 = fig.add_subplot(121) ax2 = fig.add_subplot(122) ax1.imshow(I,cmap='rainbow'); ax1.axis('off') ax2.plot(x,I[128]);ax2.set_xlabel('x [mm]');ax2.set_ylabel('Intensity [a.u.]') ax2.grid('on') plt.show() ``` -------------------------------- ### Install matplotlib Source: https://github.com/opticspy/lightpipes/blob/master/sphinx-sources/manual.md Install the matplotlib library for graphing and visualization of simulation results. ```bash >>> pip install matplotlib ``` -------------------------------- ### Install LightPipes Source: https://github.com/opticspy/lightpipes/blob/master/docs/_sources/install.rst.txt Standard installation command for the LightPipes package. This installs the core library without optional dependencies like pyFFTW. ```bash sudo pip(3) install LightPipes ``` -------------------------------- ### Install Dependencies and LightPipes Source: https://github.com/opticspy/lightpipes/blob/master/docs/install.html Commands to install Cython, ATLAS, and the LightPipes package. ```bash sudo pip3 install cython sudo apt-get install libatlas-base-dev ``` ```bash sudo rm -vf /var/lib/apt/lists/* sudo apt-get update ``` ```bash sudo pip(3) install lightpipes ``` ```bash sudo apt install python3-gi-cairo ``` ```bash sudo pip(3) install LightPipes==1.2.0 ``` -------------------------------- ### Install LightPipes with pyFFTW Source: https://github.com/opticspy/lightpipes/blob/master/docs/install.html Commands to install LightPipes and optional pyFFTW support. ```bash sudo pip(3) install LightPipes ``` ```bash sudo pip(3) install pyFFTW ``` ```bash sudo pip(3) install LightPipes[pyfftw] ``` -------------------------------- ### Install LightPipes Source: https://github.com/opticspy/lightpipes/blob/master/sphinx-sources/install.md Use this command to install the LightPipes package. If you have both Python 2.7 and 3.+ installed, use pip3 instead of pip. ```bash pip(3) install LightPipes ``` -------------------------------- ### Install LightPipes for Python Source: https://github.com/opticspy/lightpipes/blob/master/sphinx-sources/computerprac.md Use this command to install the LightPipes optical toolbox. This toolbox provides routines for optical propagation and simulation. ```bash pip install LightPipes ``` ```bash sudo pip install LightPipes ``` -------------------------------- ### Install dependencies Source: https://github.com/opticspy/lightpipes/blob/master/docs/manual.html Commands to install the required Python packages for plotting and numerical operations. ```bash pip install matplotlib ``` ```bash pip install numpy ``` -------------------------------- ### Import LightPipes Library Source: https://github.com/opticspy/lightpipes/blob/master/README.md Import the necessary LightPipes library for optical simulations. Ensure the library is installed before running. ```python from LightPipes import * ``` -------------------------------- ### Phase Recovery Example Source: https://github.com/opticspy/lightpipes/blob/master/docs/_sources/PhaseRecoveryGerchbergSaxton.rst.txt This example demonstrates phase recovery using Gerchberg-Saxton iteration. It requires the 'lightpipes' library and a plotting utility. ```python import numpy as np import matplotlib.pyplot as plt from lightpipes import * # Define simulation parameters wavelength_0 = 1.55e-6 N = 256 size = 20e-3 # Create a Field object # For simplicity, we start with a plane wave field = Field(wavelength_0, N, size) field.random_plane_wave() # Define the target intensity pattern (e.g., a Gaussian beam) target_intensity = np.zeros((N, N)) center_x, center_y = N // 2, N // 2 radius = 30 for i in range(N): for j in range(N): if (i - center_x)**2 + (j - center_y)**2 < radius**2: target_intensity[i, j] = 1 # Gerchberg-Saxton iteration num_iterations = 10 for _ in range(num_iterations): # Inverse Fourier transform to get the field in the object plane field_obj = field.fourier_transform(field) # Apply the phase constraint in the object plane (keep amplitude, set phase) field_obj.random_phase() # Fourier transform back to the image plane field = field_obj.inverse_fourier_transform(field_obj) # Apply the intensity constraint in the image plane field.set_intensity(target_intensity) # Plot the results plt.figure(figsize=(12, 5)) plt.subplot(1, 3, 1) plt.imshow(field.intensity, cmap='gray') plt.title('Initial Intensity') plt.axis('off') plt.subplot(1, 3, 2) plt.imshow(field.phase, cmap='hsv') plt.title('Recovered Phase') plt.axis('off') plt.subplot(1, 3, 3) plt.imshow(field.intensity, cmap='gray') plt.title('Recovered Intensity') plt.axis('off') plt.tight_layout() plt.show() ``` -------------------------------- ### Initialize AiryBeam1D environment Source: https://github.com/opticspy/lightpipes/blob/master/docs/command-reference.html Setup imports required for working with AiryBeam1D and visualization. ```python from LightPipes import * import matplotlib.pyplot as plt import numpy as np ``` -------------------------------- ### Install LightPipes using pip Source: https://github.com/opticspy/lightpipes/blob/master/docs/_sources/install.rst.txt Standard installation command for the LightPipes library. Ensure your numpy version is up-to-date to avoid compatibility issues. ```bash sudo pip install LightPipes ``` -------------------------------- ### Install pyFFTW package Source: https://github.com/opticspy/lightpipes/blob/master/docs/_sources/install.rst.txt Install the pyFFTW package separately. This is an optional step that enables faster FFT computations when used with LightPipes. ```bash sudo pip(3) install pyFFTW ``` -------------------------------- ### Install LightPipes via pip Source: https://github.com/opticspy/lightpipes/blob/master/README.md Standard installation command for the current pure Python version of LightPipes. ```bash pip install LightPipes ``` -------------------------------- ### Install visualization and numerical dependencies Source: https://github.com/opticspy/lightpipes/blob/master/docs/_sources/manual.rst.txt Commands to install matplotlib and numpy via pip for plotting and data handling. ```bash >>> pip install matplotlib ``` ```bash >>> pip install numpy ``` -------------------------------- ### Get Help for Begin Command in LightPipes Source: https://github.com/opticspy/lightpipes/blob/master/sphinx-sources/support.md Use the built-in help() function at the Python prompt to get detailed information about specific LightPipes commands like Begin. This requires importing all functions from the LightPipes library. ```python >>> from LightPipes import * >>> help(Begin) ``` ```bash Help on built-in function Begin: Begin(...) method of LightPipes._LightPipes.Init instance F = Begin(GridSize, Wavelength, N) :ref:`Creates a plane wave (phase = 0.0, amplitude = 1.0). ` Args:: GridSize: size of the grid Wavelength: wavelength of the field N: N x N grid points (N must be even) Returns:: F: N x N square array of complex numbers (1+0j). Example: :ref:`Diffraction from a circular aperture ` >>> ``` -------------------------------- ### Install matplotlib Source: https://github.com/opticspy/lightpipes/blob/master/sphinx-sources/computerprac.md Use this command to install the matplotlib plotting package. It is required for visualizing optical simulation results. ```bash pip install matplotlib ``` ```bash sudo pip install matplotlib ``` -------------------------------- ### Get Python Site Packages Source: https://github.com/opticspy/lightpipes/blob/master/docs/UserDefinedFunctions.html Demonstrates how to retrieve the list of site-packages directories for the current Python environment. ```python >>> import site >>> site.getsitepackages() ['/usr/local/lib/python3.6/dist-packages', '/usr/lib/python3/dist-packages', '/usr/lib/python3.6/dist-packages'] >>> print(site.getsitepackages()[1]) /usr/lib/python3/dist-packages ``` -------------------------------- ### Getting Help for LightPipes Commands Source: https://github.com/opticspy/lightpipes/blob/master/sphinx-sources/support.md Demonstrates how to use Python's built-in help function to get detailed information about specific LightPipes commands. ```APIDOC ## GET Help for Begin Command ### Description Retrieves detailed help information for the `Begin` command within the LightPipes library. ### Method Interactive Python Prompt ### Endpoint N/A (In-prompt command) ### Parameters None ### Request Example ```pycon >>> from LightPipes import * >>> help(Begin) ``` ### Response #### Success Response Displays the function signature, description, arguments, return values, and examples for the `Begin` command. #### Response Example ```bash Help on built-in function Begin: Begin(...) method of LightPipes._LightPipes.Init instance F = Begin(GridSize, Wavelength, N) :ref:`Creates a plane wave (phase = 0.0, amplitude = 1.0). ` Args:: GridSize: size of the grid Wavelength: wavelength of the field N: N x N grid points (N must be even) Returns:: F: N x N square array of complex numbers (1+0j). Example: :ref:`Diffraction from a circular aperture ` >>> ``` ``` -------------------------------- ### Far Field Propagation Examples Source: https://github.com/opticspy/lightpipes/blob/master/docs/manual.html These examples demonstrate far field propagation with different grid sizes to ensure accurate simulation results. ```python from LightPipes import * import matplotlib.pyplot as plt Field=Begin(400*mm, 1*um, 512) Field = RectAperture(20*mm,20*mm,0, 0,0, Field) Field = Forvard(500*m, Field) I = Intensity(0,Field) x=[] for i in range(512): x.append((-20*mm/2+i*20*mm/512)/mm) fig=plt.figure(figsize=(10,6)) ax1 = fig.add_subplot(121) ax2 = fig.add_subplot(122) ax1.imshow(I,cmap='rainbow'); ax1.axis('off') ax2.plot(x,I[256]);ax2.set_xlabel('x [mm]');ax2.set_ylabel('Intensity [a.u.]') ax2.grid('on') plt.show() ``` ```python from LightPipes import * import matplotlib.pyplot as plt Field=Begin(60*mm, 1*um, 512) Field = RectAperture(20*mm,20*mm,0, 0,0, Field) Field = Forvard(500*m, Field) I = Intensity(0,Field) x=[] for i in range(512): x.append((-20*mm/2+i*20*mm/512)/mm) fig=plt.figure(figsize=(10,6)) ax1 = fig.add_subplot(121) ax2 = fig.add_subplot(122) ax1.imshow(I,cmap='rainbow'); ax1.axis('off') ax2.plot(x,I[256]);ax2.set_xlabel('x [mm]');ax2.set_ylabel('Intensity [a.u.]') ax2.grid('on') plt.show() ``` -------------------------------- ### Install LightPipes with pyFFTW support Source: https://github.com/opticspy/lightpipes/blob/master/docs/_sources/install.rst.txt Install LightPipes along with the pyFFTW package for enhanced performance. This command ensures that LightPipes can leverage pyFFTW for its FFT calculations. ```bash sudo pip(3) install LightPipes[pyfftw] ``` -------------------------------- ### Correct Near Field Propagation Example Source: https://github.com/opticspy/lightpipes/blob/master/docs/manual.html This example shows the correct configuration for near field propagation by increasing the grid size relative to the aperture. ```python from LightPipes import * import matplotlib.pyplot as plt Field=Begin(40*mm, 1*um, 256) Field = RectAperture(20*mm,20*mm,0, 0,0, Field) Field = Forvard(1*m, Field) I = Intensity(0,Field) x=[] for i in range(256): x.append((-40*mm/2+i*40*mm/256)/mm) fig=plt.figure(figsize=(10,6)) ax1 = fig.add_subplot(121) ax2 = fig.add_subplot(122) ax1.imshow(I,cmap='rainbow'); ax1.axis('off') ax2.plot(x,I[128]);ax2.set_xlabel('x [mm]');ax2.set_ylabel('Intensity [a.u.]') ax2.grid('on') plt.show() ``` -------------------------------- ### Test LightPipes Installation Source: https://github.com/opticspy/lightpipes/blob/master/docs/_sources/install.rst.txt After installation, run these commands in a Python interpreter to verify that LightPipes is working correctly. A successful test will output 'LightPipes for Python: test passed.' ```python >>> from LightPipes import * >>> LPtest() LightPipes for Python: test passed. >>> ``` -------------------------------- ### Begin Source: https://github.com/opticspy/lightpipes/blob/master/docs/command-reference.html Initiates a field with a grid size, a wavelength, and a grid dimension. ```APIDOC ## Begin ### Description Initiates a field with a grid size, a wavelength and a grid dimension. By setting dtype to numpy.complex64 memory can be saved. ### Parameters #### Request Body - **size** (int, float) - Required - Size of the square grid. - **labda** (int, float) - Required - The wavelength of the output field. - **N** (int) - Required - The grid dimension. - **dtype** (complex, numpy.complex64, numpy.complex128) - Optional - Type of the field array (default = None). ### Response - **output** (Field) - N x N square array of complex numbers. ``` -------------------------------- ### Begin Command Signature and Description Source: https://github.com/opticspy/lightpipes/blob/master/docs/_sources/support.rst.txt This is the output from the `help(Begin)` command, detailing its signature, purpose, arguments, and return value. It's used to create a plane wave. ```bash Help on built-in function Begin: Begin(...) method of LightPipes._LightPipes.Init instance F = Begin(GridSize, Wavelength, N) :ref:`Creates a plane wave (phase = 0.0, amplitude = 1.0). ` Args:: GridSize: size of the grid Wavelength: wavelength of the field N: N x N grid points (N must be even) Returns:: F: N x N square array of complex numbers (1+0j). Example: :ref:`Diffraction from a circular aperture ` >>> ``` -------------------------------- ### Initialize Field with Begin Source: https://github.com/opticspy/lightpipes/blob/master/docs/command-reference.html Initiates a field with specified grid size, wavelength, and dimension. Use numpy.complex64 for memory saving. ```python from LightPipes import * siz = 20*mm wavelength = 500*nm N = 5 F = Begin(siz, wavelength, N) ``` -------------------------------- ### Illustrate Wave Front Tilt with LightPipes Source: https://github.com/opticspy/lightpipes/blob/master/docs/_sources/manual.rst.txt This example demonstrates how to apply a wave front tilt and propagate it, showing the resulting transversal shift in the intensity distribution and phase tilt. It requires the Tilt command and propagation. ```python import numpy as np import matplotlib.pyplot as plt import lightpipes as lp from lightpipes. অপটিক্স import * # Parameters wavelength = 633e-9 # meters size = 10e-3 # meters N = 1024 # grid size alpha = 0.1e-3 # tilt in X and Y directions, radians z = 8 # propagation distance, meters # Initialize Field F = lp.Begin(size, wavelength, N) # Apply tilt F = lp.Tilt(alpha, alpha, F) # Propagate F = lp.Propagate(z, F) # Plotting intensity = lp.Intensity(0, F) phase = lp.Phase(F) plt.figure(figsize=(12, 5)) plt.subplot(1, 2, 1) plt.imshow(intensity, extent=(-size/2, size/2, -size/2, size/2)) plt.title('Intensity') plt.xlabel('x [m]') plt.ylabel('y [m]') plt.subplot(1, 2, 2) plt.imshow(phase, extent=(-size/2, size/2, -size/2, size/2), cmap='viridis') plt.title('Phase') plt.xlabel('x [m]') plt.ylabel('y [m]') plt.tight_layout() plt.show() ``` -------------------------------- ### Install LightPipes using pip Source: https://github.com/opticspy/lightpipes/blob/master/docs/_sources/install.rst.txt Use this command to install or upgrade the LightPipes package. If you have both Python 2.7 and 3 installed, use pip3 instead of pip. ```bash pip(3) install LightPipes ``` ```bash pip(3) install --upgrade LightPipes ``` -------------------------------- ### Install LightPipes for Python 3 Source: https://github.com/opticspy/lightpipes/blob/master/docs/_sources/install.rst.txt Installs the LightPipes library using pip for Python 3. This command is used after fulfilling prerequisites for systems where direct installation might fail. ```bash sudo pip(3) install lightpipes ``` -------------------------------- ### Initialize Field with Begin Command - Python Source: https://github.com/opticspy/lightpipes/blob/master/docs/manual.html Use the Begin command to define the grid size, dimension, and wavelength for calculations. This initializes a uniform field with intensity 1 and phase 0. ```python from LightPipes import * GridSize = 30*mm GridDimension = 5 lambda_ = 500*nm #lambda_ is used because lambda is a Python build-in function. Field = Begin(GridSize, lambda_, GridDimension) print(Field.field) ``` -------------------------------- ### Apply Custom Phase and Intensity Filters Source: https://github.com/opticspy/lightpipes/blob/master/docs/_sources/manual.rst.txt Examples for creating arbitrary intensity/phase distributions and importing external bitmap files as masks. ```python ./Examples/Commands/subintphase1.py ``` ```python ./Examples/Commands/subintphase2.py ``` -------------------------------- ### Visualize simulation results with LightPipes Source: https://github.com/opticspy/lightpipes/blob/master/docs/manual.html Full example demonstrating field initialization, grid interpolation, and plotting using matplotlib. ```python from LightPipes import * import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D import numpy as np GridSize = 10*mm GridDimension = 128 lambda_ = 1000*nm #lambda_ is used because lambda is a Python build-in function. R=2.5*mm xs=0*mm; ys=0*mm T=0.8 Field = Begin(GridSize, lambda_, GridDimension) Field=GaussAperture(R,xs,ys,T,Field) NewGridDimension=int(GridDimension/4) Field=Interpol(GridSize,NewGridDimension,0,0,0,1,Field) I=Intensity(0,Field) I=np.array(I) #plot cross section: x=[] for i in range(NewGridDimension): x.append((-GridSize/2+i*GridSize/NewGridDimension)/mm) plt.plot(x,I[int(NewGridDimension/2)]) plt.xlabel('x [mm]');plt.ylabel('Intensity [a.u.]') plt.show() #3d plot: X=range(NewGridDimension) Y=range(NewGridDimension) X, Y=np.meshgrid(X,Y) fig=plt.figure(figsize=(10,6)) ax = plt.axes(projection='3d') ax.plot_surface(X, Y,I, rstride=1, cstride=1, cmap='rainbow', linewidth=0.0, ) ax.set_zlabel('Intensity [a.u.]') plt.show() ``` -------------------------------- ### Find Python Installation Directory (Windows) Source: https://github.com/opticspy/lightpipes/blob/master/sphinx-sources/install.md Command to locate your Python installation directory on Windows. ```bash where python ``` -------------------------------- ### Simulate Poisson's Spot with LightPipes Source: https://github.com/opticspy/lightpipes/blob/master/docs/PoissonSpot.html This script initializes a plane wave, applies a circular obstacle, performs Fresnel propagation, and prepares parameters for visualizing the resulting intensity pattern. ```python 1 import numpy as np 2 from LightPipes import * 3 import matplotlib.pyplot as plt 4 5 # Parameters 6 wavelength=5*um 7 size=25.0*mm 8 N=2000 9 N2=int(N/2) 10 z=20*cm 11 12 # Begin with a plane wave 13 F = Begin(size, wavelength, N) 14 15 # Gaussian laser beam 16 w0=size/3 17 F=GaussBeam(F, w0) 18 19 # Circular opaque disk (obstacle) 20 disk_diameter = 6.0 * mm 21 F = CircScreen(F,disk_diameter/2) 22 23 # Fresnel propagation 24 F = Fresnel(F, z) 25 26 # Intensity at the screen 27 I = Intensity(0, F) 28 29 # Coordinates for plotting 30 x = np.linspace(-size/2, size/2, N) / mm 31 32 s1 = r'LightPipes for Python' + '\n' 33 s2 = r'Poisson.py'+ '\n\n'\ 34 f'size = {size/mm:4.2f} mm' + '\n'\ 35 f'$\lambda$ = {wavelength/um:4.2f} $\mu$m' + '\n'\ 36 f'N = {N:d}' + '\n' +\ 37 f'd = {disk_diameter/mm:4.2f} mm disk diameter' + '\n' ``` -------------------------------- ### Find Python Installation Directory (Mac/Linux) Source: https://github.com/opticspy/lightpipes/blob/master/sphinx-sources/install.md Command to locate your Python installation directory on Mac or Linux. ```bash which python ``` -------------------------------- ### Install python3-gi-cairo Source: https://github.com/opticspy/lightpipes/blob/master/docs/_sources/install.rst.txt Install the python3-gi-cairo package, which may be a prerequisite for certain Python functionalities on Debian-based systems. ```bash sudo apt install python3-gi-cairo ``` -------------------------------- ### Install numpy Source: https://github.com/opticspy/lightpipes/blob/master/sphinx-sources/manual.md Install the numpy library, which is used for numerical operations and array manipulation, particularly for plotting cross-sections. ```bash >>> pip install numpy ``` -------------------------------- ### Install legacy C++ version of LightPipes Source: https://github.com/opticspy/lightpipes/blob/master/README.md Command to install the specific legacy C++ version 1.2.0 of LightPipes. ```bash pip install LightPipes==1.2.0 ``` ```bash sudo pip3 install LightPipes==1.2.0 ``` -------------------------------- ### Install Matplotlib Source: https://github.com/opticspy/lightpipes/blob/master/docs/_sources/install.rst.txt Install the Matplotlib library, which is commonly used with LightPipes for plotting and visualizing results. This command can be run in a terminal. ```bash pip(3) install matplotlib ``` -------------------------------- ### Install cython and ATLAS Source: https://github.com/opticspy/lightpipes/blob/master/docs/_sources/install.rst.txt Installs the cython compiler and ATLAS development libraries, which are necessary dependencies for building pyFFTW on certain systems. ```bash sudo pip3 install cython sudo apt-get install libatlas-base-dev ``` -------------------------------- ### LPhelp Source: https://github.com/opticspy/lightpipes/blob/master/docs/command-reference.html Navigates to the LightPipes documentation website. ```APIDOC ## LPhelp ### Description Go to the LightPipes documentation website. ### Method LightPipes Function ### Endpoint N/A (Python function) ### Parameters None ### Request Example ```python LPhelp() ``` ### Response #### Success Response (200) * Opens the LightPipes documentation website in a browser. #### Response Example ```json { "status": "documentation opened" } ``` ``` -------------------------------- ### Demonstrate Steps command reversibility Source: https://github.com/opticspy/lightpipes/blob/master/docs/_sources/manual.rst.txt Shows how the Steps command can be used for inverse propagation by negating the step size. ```bash Field = Steps( 0.1, 1, n, Field) Field = Steps(-0.1, 1, n ,Field) ``` -------------------------------- ### Simulate Poisson’s Spot with LightPipes Source: https://github.com/opticspy/lightpipes/blob/master/sphinx-sources/PoissonSpot.md This script initializes a Gaussian beam, applies an opaque circular screen, propagates the field using Fresnel diffraction, and visualizes the resulting intensity pattern. ```python import numpy as np from LightPipes import * import matplotlib.pyplot as plt # Parameters wavelength=5*um size=25.0*mm N=2000 N2=int(N/2) z=20*cm # Begin with a plane wave F = Begin(size, wavelength, N) # Gaussian laser beam w0=size/3 F=GaussBeam(F, w0) # Circular opaque disk (obstacle) disk_diameter = 6.0 * mm F = CircScreen(F,disk_diameter/2) # Fresnel propagation F = Fresnel(F, z) # Intensity at the screen I = Intensity(0, F) # Coordinates for plotting x = np.linspace(-size/2, size/2, N) / mm s1 = r'LightPipes for Python' + '\n' s2 = r'Poisson.py'+ '\n\n'\ f'size = {size/mm:4.2f} mm' + '\n'\ f'$\lambda$ = {wavelength/um:4.2f} $\mu$m' + '\n'\ f'N = {N:d}' + '\n' +\ f'd = {disk_diameter/mm:4.2f} mm disk diameter' + '\n'\ f'w0 = {w0/mm:4.2f} mm radius Gauss beam' + '\n'\ f'z = {z/cm:4.2f} cm distance from disk' + '\n'\ r'${\copyright}$ Fred van Goor, February 2026' fig=plt.figure(figsize=(11,6)) fig.suptitle("The spot of Poisson") ax1 = fig.add_subplot(221);ax1.axis('off') ax2 = fig.add_subplot(222) ax3 = fig.add_subplot(223);ax3.axis('off') ax1.set_xlim(N2-300,N2+300) ax1.set_ylim(N2-300,N2+300) ax1.imshow(I,cmap='jet') ax1.set_title(f'Intensity pattern after {z/cm:4.1f} cm propagation') X=np.linspace(-size/2,size/2,N) ax2.plot(X/mm,I[N2]); ax2.set_xlabel('x[mm]'); ax2.set_ylabel('Intensity [a.u.]') ax2.set_xlim(-1,1); ax2.set_title('The intensity cross-section of the spot') ax3.text(0.0,1.0,s1,fontsize=12, fontweight='bold') ax3.text(0.0,0.3,s2) plt.show() ``` -------------------------------- ### Upgrade LightPipes Source: https://github.com/opticspy/lightpipes/blob/master/sphinx-sources/install.md Use this command to upgrade an existing installation of the LightPipes package. If you have both Python 2.7 and 3.+ installed, use pip3 instead of pip. ```bash pip(3) install --upgrade LightPipes ``` -------------------------------- ### Simulate a Michelson interferometer with mirror tilt Source: https://github.com/opticspy/lightpipes/blob/master/docs/_sources/MichelsonInterferometer.rst.txt This script sets up a Michelson interferometer with unequal arm lengths and a tilted mirror in one arm to observe interference patterns. ```python #! /usr/bin/env python from LightPipes import * import matplotlib.pyplot as plt wavelength=632.8*nm #wavelength of HeNe laser size=15*mm # size of the grid N=500 # number (NxN) of grid pixels R=9*mm # laser beam radius z1=8*cm # length of arm 1 z2=7*cm # length of arm 2 z3=3*cm # distance laser to beamsplitter z4=5*cm # distance beamsplitter to screen Rbs=0.5 # reflection beam splitter tx=0.5*mrad; ty=0.0*mrad # tilt of mirror 1 #Generate a laser beam: F=Begin(size,wavelength,N) F=GaussBeam(F, R) #Propagate to the beamsplitter: F=Forvard(F,z3) #Split the beam and propagate to mirror #2: F2=IntAttenuator(F, 1-Rbs) F2=Forvard(F2,z2) #Introduce aberration and propagate back to the beamsplitter: F2=Tilt(F2,tx,ty) F2=Forvard(F2,z2) F2=IntAttenuator(F2,Rbs) #Split off the second beam and propagate to- and back from the mirror #1: F10=IntAttenuator(F,Rbs) F1=Forvard(F10,z1*2) F1=IntAttenuator(F1,1-Rbs) #Recombine the two beams and propagate to the screen: F=BeamMix(F1,F2) F=Forvard(F,z4) I=Intensity(F) #Present the results: s1 = r'LightPipes for Python ' + LPversion + '\n\n'\ r'Michelson interferometer with mirror tilt in one arm' + '\n' s2 = r'Michelson.py'+ '\n\n'\ f'size = {size/mm:4.2f} mm' + '\n'\ f'$\lambda$ = {wavelength/um:4.2f} $\mu$m' + '\n'\ f'N = {N:d}' + '\n'\ f'R = {R/mm:4.2f} mm beam radius of the laser' + '\n'\ f'z1 = {z1/mm:4.2f} mm length of arm 1' + '\n'\ f'z2 = {z2/mm:4.2f} mm length of arm 2' + '\n'\ f'z3 = {z3/mm:4.2f} mm distance from the laser to the beam splitter' + '\n'\ f'z4 = {z4/mm:4.2f} mm distance from the beam splitter to the screen' + '\n'\ f'tx, ty = {tx/mrad:4.2f}, {ty/mrad:4.2f} mrad tilt of mirror 2' + '\n\n'\ r'${\copyright}$ Fred van Goor, June 2020' fig=plt.figure(figsize=(6,9)); ax1 = fig.add_subplot(311);ax1.axis('off') ax2 = fig.add_subplot(312);ax2.axis('off') ax3 = fig.add_subplot(313);ax3.axis('off') ax1.imshow(I,cmap='jet');ax1.set_title('intensity pattern') ax2.text(0.0,0.6,s1,fontsize=12, fontweight='bold') ax3.text(0.0,0.50,s2) plt.show() ```