dif

diffsim

Implementation of the angular spectrum method in Python to simulate arbitrary light diffraction patterns.

Showing:

Popularity

Downloads/wk

0

GitHub Stars

120

Maintenance

Last Commit

9d ago

Contributors

2

Package

Dependencies

0

License

MIT

Categories

Readme

Diffraction Simulator - Angular Spectrum Method

animation

Accurate and easy to use light diffraction simulator, implemented with the angular spectrum method in Python. You can use it for simulating the diffraction pattern of an arbitrary aperture, both with monochromatic and polychromatic light.

How the method and the simulator work is described in this Article. Take a look to the Youtube video to see the animated simulations!

Features

  • Arbitrary apertures
  • Arbitrary light spectrums
  • Lenses
  • GPU acceleration

Installation

pip install diffractsim

Alternatively, to download the examples and the apertures as well, you can also build from source by cloning the repository and running from the main folder project on the command prompt:

python setup.py install

Examples

To perform the simulations, just run from the examples subdirectory the corresponding Python scripts on the command prompt. To compute your own diffraction pattern, you'll need to specify in the script the aperture as an image and input its size.

python hexagon_monochromatic.py

N|Solid

python hexagon_polychromatic.py

N|Solid

python rectangular_grating_small.py

N|Solid

python rectangular_grating_big.py

N|Solid

python bahtinov_mask.py

N|Solid

python rings.py

N|Solid

python hexagonal_grating.py

N|Solid

python text.py

N|Solid

For a more detailed discussion about simulating diffraction patterns using lenses, take a look at these examples.

GPU acceleration requires having CuPy installed and CUDA in your computer. To use GPU acceleration in your simulations, after import diffractsim add the line:

diffractsim.set_backend("CUDA")

Cupy and CUDA aren't required to install and use this package, but they can offer a significant speed boost.

The first GPU accelerated run can be slow because Python is caching the required functions. The next time it can be about 10x and 100x faster than a CPU backend depending on your GPU. The speed boost raises as the grid gets larger.

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial