diffractsim

✨🔬 A flexible diffraction simulator for exploring and visualizing physical optics.

https://github.com/rafael-fuente/diffractsim

Science Score: 77.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 5 DOI reference(s) in README
  • Academic publication links
    Links to: zenodo.org
  • Committers with academic emails
    1 of 5 committers (20.0%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (13.1%) to scientific vocabulary

Keywords

angular-spectrum-method diffraction diffraction-pattern diffraction-simulations holography optics physics physics-simulations python wave-optics
Last synced: 6 months ago · JSON representation ·

Repository

✨🔬 A flexible diffraction simulator for exploring and visualizing physical optics.

Basic Info
Statistics
  • Stars: 914
  • Watchers: 19
  • Forks: 117
  • Open Issues: 14
  • Releases: 1
Topics
angular-spectrum-method diffraction diffraction-pattern diffraction-simulations holography optics physics physics-simulations python wave-optics
Created about 5 years ago · Last pushed 6 months ago
Metadata Files
Readme Funding License Citation

README.md

Diffractsim: A diffraction simulator for exploring and visualizing physical optics

DOI

animation

Flexible, and easy-to-use Python diffraction simulator that focuses on visualizing physical optics phenomena. The simulator uses mainly scalar diffraction techniques for light propagation, provides a nice interface for simulation set up, and includes several plotting options, counting with CIE Color matching functions for accurate color reproduction. The implemented methods are differentiable when using the JAX-backend, enabling optimization and design of the optical setups.

The basic use of this simulator using the angular spectrum method is described in this article. Take a look to the videos to see the animated simulations!

Features

  • [x] Arbitrary apertures and light spectrums
  • [x] Full-path optical propagation and arbitrary zoom in the region of interest
  • [x] Lenses
  • [x] Phase holograms generation and reconstruction
  • [x] GPU acceleration
  • [x] Differentiable propagation
  • [ ] Incoherent Light (coming soon)

Installation

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 diffraction_text.py

N|Solid

The examples from the video about diffraction with lenses can be found here.

GPU acceleration requires having either CuPy or JAX installed along with CUDA on your computer. To use GPU acceleration with CuPy in your simulations, after import diffractsim add the line:

python diffractsim.set_backend("CUDA")

Or when using JAX:

python diffractsim.set_backend("JAX")

JAX, in addition to offering GPU acceleration, will allow differentiable programming. Cupy, JAX 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.

Diffractsim can also be used to compute and visualize longitudinal profiles. Since the computation of each propagation distance is independent, it can be fully parallelized, and therefore GPU use is highly recommended.

python lens_longitudinal_profile.py

N|Solid

python axicon_longitudinal_profile.py

N|Solid

The problem of phase retrieval is a classic one in optics and arises when one is interested in retrieving the wavefront from two intensity measurements acquired in two different planes. Diffractsim provides a simple implementation of this problem.

In the following example, the GitHub logo is recovered at the Fourier plane from a coherently illuminated square-shaped aperture. The script generates a phase mask, which is stored as an image using an HSV colourmap and then placed on the aperture to reconstruct the desired image. The phase mask can be reproduced with, for example, spatial light modulators (SLMs) and metasurfaces.

python phase_hologram_github_logo_generation_and_reconstruction.py

animation

Citing Diffractsim

R. de la Fuente Herrezuelo, diffractsim: A flexible python diffraction simulator, GitHub (2022), https://doi.org/10.5281/zenodo.6147771

Owner

  • Name: Rafael de la Fuente
  • Login: rafael-fuente
  • Kind: user
  • Location: Spain
  • Company: NIL Technology

Citation (CITATION.cff)

cff-version: 1.2.0
message: "If you use this software, please cite it as below."
authors:
  - family-names: De la Fuente
    given-names: Rafael
    orcid: https://orcid.org/0000-0002-7126-448X
title: "diffractsim: A flexible python diffraction simulator"
doi: 10.5281/zenodo.6147771
url: https://github.com/rafael-fuente/diffractsim
license: Mozilla Public License 2.0

GitHub Events

Total
  • Issues event: 7
  • Watch event: 178
  • Issue comment event: 13
  • Push event: 10
  • Pull request event: 7
  • Fork event: 30
Last Year
  • Issues event: 7
  • Watch event: 178
  • Issue comment event: 13
  • Push event: 10
  • Pull request event: 7
  • Fork event: 30

Committers

Last synced: over 2 years ago

All Time
  • Total Commits: 104
  • Total Committers: 5
  • Avg Commits per committer: 20.8
  • Development Distribution Score (DDS): 0.087
Past Year
  • Commits: 4
  • Committers: 2
  • Avg Commits per committer: 2.0
  • Development Distribution Score (DDS): 0.25
Top Committers
Name Email Commits
Rafael de la Fuente r****o@g****m 95
Ira Horecka i****9@i****m 4
Daniel Brown d****n@a****u 3
Irfan Imaduddin i****n@g****m 1
Villads Egede Johansen v****j@n****m 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 27
  • Total pull requests: 17
  • Average time to close issues: 29 days
  • Average time to close pull requests: 4 months
  • Total issue authors: 24
  • Total pull request authors: 10
  • Average comments per issue: 1.81
  • Average comments per pull request: 0.35
  • Merged pull requests: 7
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 6
  • Pull requests: 10
  • Average time to close issues: 3 months
  • Average time to close pull requests: 6 days
  • Issue authors: 5
  • Pull request authors: 4
  • Average comments per issue: 1.83
  • Average comments per pull request: 0.1
  • Merged pull requests: 3
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • irfanimaduddin (2)
  • MarnixMeersman (2)
  • Drachenbauer (2)
  • Duc-Khoa-Dang (1)
  • shawnwwimer (1)
  • LtqxWYEG (1)
  • angeAnonyme (1)
  • stduhpf (1)
  • nophy (1)
  • Windaway (1)
  • eruarua (1)
  • FishWoWater (1)
  • a-photon-here (1)
  • ghost (1)
  • udithhaputhanthri (1)
Pull Request Authors
  • CSTEZCAN (6)
  • GuilhermeMonteiroPeixoto (4)
  • phansel (2)
  • LtqxWYEG (2)
  • s-enright (2)
  • danielbrown2 (1)
  • irfanimaduddin (1)
  • irahorecka (1)
  • hadmack (1)
  • villadsegede (1)
Top Labels
Issue Labels
Pull Request Labels

Dependencies

requirements.txt pypi
  • cycler >=0.10.0
  • kiwisolver >=1.3.1
  • matplotlib >=3.3.3
  • numpy >=1.19.4
  • pillow >=8.3.2
  • progressbar >=2.5
  • pyparsing >=2.4.7
  • python-dateutil >=2.8.1
  • scipy >=1.6.0
  • six >=1.15.0
setup.py pypi
  • Pillow *
  • autograd *
  • matplotlib *
  • numpy *
  • progressbar *
  • scipy *