Skip to content

Repository files navigation

PyOptik logo

Badge Status
Python versions Python
Documentation Documentation Status
Scientific article Scientific article
Continuous integration Unittest Status
Test coverage Unittest coverage
Google Colab Google Colab
PyPI package PyPI version
PyPI downloads PyPI downloads
Anaconda package Anaconda version
Anaconda downloads Anaconda downloads
Latest Anaconda release Latest release date

PyMieSim

PyMieSim is an open-source Python package for fast and flexible Mie scattering simulations. It supports spherical, cylindrical and core--shell particles and provides helper classes for custom sources and detectors. The project targets both quick single-scatterer studies and large parametric experiments.

Try the live web GUI: PyMieSim Parameter Sweep Lab.

Features

  • Solvers for spheres, cylinders and core--shell geometries.
  • Built-in models for plane wave and Gaussian sources.
  • Multiple detector types including photodiodes and coherent modes.
  • Simple data analysis with pandas DataFrame outputs.

Installation

PyMieSim is available on PyPI and Anaconda. Install it with:

pip install PyMieSim
conda install PyMieSim  --channels MartinPdeS

See the online documentation for detailed usage and additional examples.

Quick example

Below is a short example computing the scattering efficiency of a sphere.

from PyMieSim import Gaussian, PolarizationState, Simulation, Sphere, ureg

source = Gaussian(
    wavelength=750 * ureg.nanometer,
    polarization=PolarizationState(angle=0 * ureg.degree),
    optical_power=1e-3 * ureg.watt,
    numerical_aperture=0.2,
)

scatterer = Sphere(
    diameter=200 * ureg.nanometer,
    material=4 + 1j,
    medium=1.0,
)

simulation = Simulation(scatterer=scatterer, source=source)
qsca = simulation.run("Qsca")
print(qsca)

For wavelength, size, or material sweeps, use the experiment API described in the experiment examples.

Scattering efficiency of a 200 nm sphere with refractive index 4.0.

Code structure

Here is the architecture for a standard workflow using PyMieSim:

Code structure of a standard workflow using PyMieSim.

Building from source

For development or manual compilation, clone the repository and run:

git submodule update --init
mkdir build && cd build
cmake ../ -G"Unix Makefiles"
sudo make install
cd ..
python -m pip install .

Testing

Run the unit tests with:

pip install PyMieSim[testing]
pytest

Citing PyMieSim

If you use PyMieSim in academic work, please cite:

@article{PoinsinetdeSivry-Houle:23,
    author = {Martin Poinsinet de Sivry-Houle and Nicolas Godbout and Caroline Boudoux},
    journal = {Opt. Continuum},
    title = {PyMieSim: an open-source library for fast and flexible far-field Mie scattering simulations},
    volume = {2},
    number = {3},
    pages = {520--534},
    year = {2023},
    doi = {10.1364/OPTCON.473102},
}

Contact

For questions or contributions, contact martin.poinsinet.de.sivry@gmail.com.

About

Python framework for fast Lorenz Mie scattering simulations, including far field scattering, efficiencies, cross sections, and detector coupling for spheres and cylinders.

Topics

Resources

Stars

38 stars

Watchers

5 watching

Forks

Releases

Packages

Used by

Contributors

Languages