2. Installation.

Current version = 2.1.5

Up to version 1.2.0 the LightPipes for Python package, called LightPipes, consists of a collection of C++ routines which can be called from a Python script. From version 2.0.0 we transformed the package into pure Python using the numpy, scipy and pyFFTW packages. Because of these packages, the speed of the pure python version is about the same as with the C++ version or even faster because use can be made of multi-processor operation.

All versions of Lightpipes can be operated on Windows (32 and 64 bits), Linux (32 and 64 bits) and Macintosh (64 bits) computers. The C++ versions < 2.0.0 packages are for Python versions 2.7, 3.4, 3.5, 3.6 and 3.7. The pure Python versions will run on all (future) Python 3.+ versions. It cannot be used with the retired Python 2.7 version. Upgrade to Python 3.

LightPipes for Python is on PyPi and can be installed if you have pip installed on your computer. In a terminal window simply type the following commands: (If you have both Python versions 2.7 and 3.+ installed on your computer use pip3 in stead of pip.)

pip(3) install LightPipes

or:

pip(3) install --upgrade LightPipes

to upgrade the package.

To test if the installation was successful start Python and type at the prompt:

>>> from LightPipes import *
>>> LPtest()
LightPipes for Python: test passed.
>>>

The response should be: “LightPipes for Python: test passed.”

Most output from LightPipes python scripts should use the MatPlotLib plotting library. MatplotLib can be installed by typing in a terminal:

pip(3) install matplotlib

Another useful package is Tkinter to make graphical user interfaces (GUI). It is installed already with most Python installations. See http://www.tkdocs.com/tutorial/install.html how to install it on your platform.

Finally, a convenient editor to make Python scripts is Geany.

2.1. LightPipes release notes.

Version: 2.1.5 on PyPi

New commands:
  • ZernikeName2Noll

Bug fixes:
  • In zernikemath.py: line 41 – 44 changed: _np.math.factorial(..) to: math.factorial(..)

  • In example PhaseRecovery.py: added lines: dta=list(np.float64(data)) and changed np.asfarray(data) to: np.asarray(data)

Fred van Goor, August 5, 2024.


Version: 2.1.4 on PyPi

New commands:
  • LensFarfield

Bug fixes:
  • In __init__.py: line 212 changed: fig.canvas.set_window_title to: fig.canvas.manager.set_window_title

  • In user_func.py: line 115: changed: dtype=_np.object to: dtype=object

  • In Power command: core.py, line 892: added “*Fin.dx**2” to the result

  • In core.py: line 115: replaced ‘Centroid’ by ‘D4Sigma’

Command changes:
  • GaussLaguerre: added possibillity of sine, cosine or exponetial phase factor.

Fred van Goor, September, 4, 2023.


Version: 2.1.3 on PyPi

New commands:
  • AiryBeam1D: substitudes a 1D Airy beam in the field.

  • AiryBeam2D: substitudes a 2D Airy beam in the field.

Bug fixes:
  • None

Command changes:
  • None

Fred van Goor, May, 4, 2022.


Version: 2.1.2 on PyPi

New commands:
  • None

Bug fixes:
  • fixed float to integer conversion errors. IndexErrors were raised in zernikemath.py

Command changes:
  • Added option in Fresnel and Forvard commands to use the pyFFTW or the numpy Fast Fourier Transform package. Default is FFT in numpy. This allows the user to compare the two FFT methods.

  • Added a config.py file. Here one can make the usage of pyFFTW permanent. Change “_USEPYFFTW = False” to “_USEPYFFTW = True” in that file. See: Using LightPipes with the pyFFTW package. for more details.

In this version we also install the package matplotlib as a required installation. Matplotlib is used in almost all LightPipes applications to present the results.

Fred van Goor, December, 18, 2021.


Version: 2.1.1 on PyPi

New commands:
  • none

Bug fixes:
  • updated LPtest() command

Command changes:
  • none

Fred van Goor, October, 7, 2021.


Version: 2.1.0 on PyPi

New commands:
  • none

Bug fixes:
  • repaired some warning messages in core.py and zernike.py

  • when LightPipes is installed on an iPad with pyto the warning message that the package pyFFTW is not installed has been removed. pyFFTW is not pure python and cannot be installed by a user on his iPad.

  • updated LPtest() command

Command changes:
  • none

Fred van Goor, September, 9, 2021.


Version: 2.0.9 on PyPi

New commands:
  • none

Bug fixes:
  • none

Command changes:
  • Begin: type of the complex field array can be set to numpy.complex64 to save memory, thanks to leguyader, issue 62.

Fred van Goor, September, 9, 2021.


Version 2.0.8 on PyPi

New commands:
  • ABCD: propagation of a pure Gaussian field using ABCD matrix.

  • GLens: Lens filter for a pure Gaussian field using ABCD matrix.

  • GForvard: Free space propagation of a pure Gaussian field using ABCD matrix.

  • Propagate: Free space propagation of a field choosing the best propagation routine depending on Fresnel number (experimental)

  • Centroid: returns the centroid coordinates of an intensity distribution.

  • D4sigma: returns the beam width (\(D4\sigma\)) of an intensity distribution.

Command changes:
  • Lens: a check for Pure Gauss beam is performed so use can be made of analytical ABCD propagation if the input field is pure Gaussian, is in the grid-center and is not tilted.

  • All commands set the “IsPureGauss” flag to False to allow ABCD propagation only when it is possible.

Bug fixes:
  • A bug in Steps was fixed. Now scalar values of the refractive index can be passed as an argument.

Fred van Goor, March, 13, 2021.


2.2. Known installation problems.

  1. Too old version of numpy:

    After installation of LightPipes, using

    sudo pip install LightPipes
    

    for a brandnew MacBook Air computer the following error popped-up after an import-test in python:

    >>> import LightPipes
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    File "/Library/Python/2.7/site-packages/LightPipes/__init__.py", line 52, in <module>
    from ._LightPipes import * # noqa
    File "__init__.pxd", line 155, in init LightPipes._LightPipes (LightPipes/_LightPipes.cpp:10911)
    ValueError: numpy.dtype has the wrong size, try recompiling. Expected 88, got 96
    

    Solution:

    The version (1.8.0rc1) of the numpy package (installed as part of the macOS Sierra 10.12.6 update) is too old. You have to update numpy to the newest version. Use easy_install, not pip for this.

    sudo easy_install -U numpy
    

    (If the cpp-compiler is not installed a window pops up to ask you to install it and the numpy installation is interrupted. Say yes to install the compiler and repeat the numpy installation)

  2. Cannot install LightPipes (version 2.0.0 and higher) on a Raspberry Pi vs 4.0:

    This is caused by the fact that the required pyFFTW package cannot be installed on a Raspberry Pi (ARM processor) Maybe this will be solved in the future.

    In the mean time you can install pyFFTW on a Raspberry Pi as follows:

    Step1, download FFTW:

    Download from the FFTW Download page the file fftw-3.3.9.tar.gz or newer. At a terminal prompt goto your Downloads directory and type:

    cd ~/Downloads
    tar xzf fftw-3.3.9.tar.gz
    

    Step 2, install FFTW:

    cd fftw-3.3.9
    ./configure --enable-threads --enable-shared
    make
    sudo make install
    

    Step 3, install the cython compiler and ATLAS:

    sudo pip3 install cython
    sudo apt-get install libatlas-base-dev
    

    If an error pops up that says something like: “E: Encountered a section with no package header” and/or: “E: The package lists or status file could not be parsed or opened”, try:

    sudo rm -vf /var/lib/apt/lists/*
    sudo apt-get update
    

    Step 4, install LightPipes for Python:

    sudo pip(3) install lightpipes
    

    The installation of LightPipes for Python described above has been tested on a Raspberry Pi 4 model B with 8Gbyte memory and with NOOBS 3.5.0 operating system.

    It has also been tested with the recommended Raspberry Pi OS (32-bit) operating system installed using the Raspberry Pi Imager v1.4. See: Raspberry Pi OS (previously called Raspbian)

    With some examples (i.e. LaserModeTransformer.py) an error message popped-up:

    “Type Error: Couldn’t find foreign struct converter for ‘cairo.Context’

    This could be solved by typing:

    sudo apt install python3-gi-cairo
    

    As an alternative you can install the C++ version 1.2.0 of LightPipes when Python 3.7 is installed on the Raspberry Pi. Type at a terminal prompt:

    sudo pip(3) install LightPipes==1.2.0
    

2.3. Using LightPipes with the pyFFTW package.

Using the pyFFTW package we found that LightPipes propagation routines are faster. However, we experienced that with a new Python version it takes a while before new binaries of pyFFTW are available. Because of that we decided from LightPipes version 2.0.7. to skip pyFFTW from the list of required packages and let it be an option. As a consequence the FFT calculations are performed by the FFT of numpy which is slightly slower than pyFFTW. For reasonable small grid sizes (less than 1000 x 1000 gridpoints) you will not notice that. When pyFFTW becomes available you can install pyFFTW and from that moment pyFFTW can be used and the propagation will be faster. See the Fresnel and Forvard commands how to use pyFFTW. So for normal installation do:

sudo pip(3) install LightPipes

To install pyFFTW do:

sudo pip(3) install pyFFTW

To install LightPipes with pyFFTW do:

sudo pip(3) install LightPipes[pyfftw]

If pyFFTW is not installed, LightPipes will fall back to numpy FFT which is slightly slower than pyFFTW. A user can force the propagation routines Fresnel and Forvard to use pyFFTW or numpy FFT. If pyFFTW is not installed a warning message will be shown and LightPipes falls back to numpy FFT. The warning can be suppressed by editing the file config.py in your local python site-packages directory:

  1. Find your python installation directory: For windows:

    where python
    

    For Mac or Linux:

    which python
    
  2. You will find config.py in:

    .....\Python3x\Lib\site-packages\LightPipes (windows)
    ...../Python3x/Lib/site-packages/LightPipes (Linux, Mac)
    
  3. Open config.py in an editor and change:

    _USE_PYFFTW = False
    

    to:

    _USE_PYFFTW = True
    

4) After saving config.py LightPipes always uses pyFFTW, even if you ommit the usepyFFTW = True option in the Fresnel and Forvard commands.