Skip to content
MartinPdeSPublic

About

Unit-aware Python toolkit for optical materials, refractive-index data, dispersion models, Fresnel interfaces, and thin-film stacks.

Topics

Resources

Contributing

Stars

8 stars

Watchers

1 watching

Forks

Repository files navigation

PyOptik logo

Badge Status
Python versions Supported Python versions
Documentation Documentation status
Continuous integration Continuous integration status
Test coverage Test coverage
PyPI package PyPI version
PyPI downloads PyPI downloads
Anaconda package Anaconda version
Anaconda downloads Anaconda downloads

PyOptik

Optical materials and thin films, from data to calculation. PyOptik is an open-source Python package for wavelength-dependent optical constants, dispersion, Fresnel interfaces, and coherent thin-film stacks. It brings the RefractiveIndex.INFO database into unit-aware Python workflows while preserving the source of each dataset.

Features

  • Find materials by name or select a specific catalog source.
  • Evaluate dispersion formulas and tabulated complex refractive indices.
  • Calculate group index, group delay, and group-delay dispersion.
  • Model Fresnel interfaces and coherent, isotropic multilayer films.
  • Import, validate, and export custom material data.
  • Work with scalar or NumPy array wavelengths and physical units.

See PyOptik in action

Design an antireflection coating

Compare the reflectance of bare glass with an ideal quarter-wave coating. The example uses lossless, constant refractive indices at normal incidence; the coating minimizes reflection at its 550 nm design wavelength. Explore the coating tutorial.

Diagram of a coating on glass and reflectance spectra showing a minimum at 550 nanometers.

Explore dispersion in fused silica

Compare phase and group index and calculate group-delay dispersion through 1 mm of glass using the Malitson model. See the silica dispersion tutorial.

Phase index, group index, and group-delay dispersion of fused silica versus wavelength.

Inspect measured optical constants

Plot the refractive index and extinction coefficient of gold from the Johnson and Christy dataset. See the gold optical constants tutorial.

Measured refractive index and extinction coefficient of gold versus wavelength.

Installation

Install from PyPI or Anaconda:

python -m pip install PyOptik
# Or: conda install -c martinpdes pyoptik

Verify the installation with python -c "import PyOptik; print(PyOptik.__version__)". Material data is downloaded on first lookup and cached locally. To initialize the complete snapshot in advance, run pyoptik setup.

First calculation

Load a material by name and evaluate its refractive index at a wavelength with units:

from PyOptik import material
from TypedUnit import ureg

bk7 = material("N-BK7")
print(bk7.n(532 * ureg.nanometer))
print(bk7.catalog_id)  # specs/SCHOTT-optical/N-BK7
bk7.plot()

The first lookup needs an internet connection. The catalog preserves source identity: use material("main/Au/Johnson") to select a specific dataset, or find_materials("gold") to explore candidates. See the materials guide for defaults, source selection, and provenance.

Interfaces and thin films

An ideal coating can also be calculated without downloading material data:

import numpy as np
from PyOptik import ThinFilmLayer, thin_film_stack
from TypedUnit import ureg

wavelengths = np.linspace(350, 900, 600) * ureg.nanometer
coating_index = np.sqrt(1.52)
coating = ThinFilmLayer(coating_index, 550 * ureg.nanometer / (4 * coating_index))
result = thin_film_stack(wavelengths, [coating], substrate_index=1.52)
print(result.reflectance)

The stack model assumes coherent, isotropic layers; it does not model surface roughness, anisotropy, or incoherent thick substrates. See the interfaces and thin films guide.

Documentation

Wavelengths should carry units; bare numeric wavelengths are interpreted as metres for backward compatibility. Material data has a source-specific validity range; use out_of_range="raise" when extrapolation is unsuitable. See the physical conventions for the complex-index and dispersion conventions.

Citing PyOptik

If you use PyOptik in research, please cite the software using the metadata in CITATION.cff. Also cite the RefractiveIndex.INFO database and the original sources for the material datasets used in your work; source details are available through catalog_id and provenance.

Development and contributions

git clone https://github.com/MartinPdeS/PyOptik.git
cd PyOptik
python -m pip install -e ".[testing,documentation,dev]"
MPLBACKEND=Agg pytest -m "not network"
MPLBACKEND=Agg sphinx-build -b html -W docs/source docs/build/html

See CONTRIBUTING.md for contribution guidance. PyOptik is distributed under the MIT license.

About

Unit-aware Python toolkit for optical materials, refractive-index data, dispersion models, Fresnel interfaces, and thin-film stacks.

Topics

Resources

Contributing

Stars

8 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages