Skip to main content

optika

tests codecov Black Ruff Documentation Status PyPI version DOI

A Python library for simulating optical systems, similar to Zemax.

optika computes the spectral response and resolution of an arbitrary optical system, and can optimize it using scipy.optimize. Surfaces carry their own sag profile, aperture, material, and rulings, and are placed in global coordinates, so a system is an ordinary Python object that can be built, modified, and swept over programmatically.

Because every parameter can be an array from named-arrays, a whole configuration space of designs propagates through the raytrace at once, and an uncertain parameter carries its uncertainty through to the performance of the system.

More information is available in the documentation.

Installation

Optika can be installed using pip:

pip install optika

Features

  • Sequential raytrace modeling of an optical system
  • Stratified random sampling of input rays for faster convergence
  • Image simulation of a given scene using an optical system
  • A fast linear forward model approximating a raytraced system, for imaging many scenes without raytracing each one
  • Spherical, conical, and toroidal surface sag profiles
  • Circular, rectangular, and polygonal apertures
  • Mirrors and arbitrary multilayer coatings
  • Refractive glass materials with Sellmeier dispersion (e.g. N-BK7, F2)
  • Diffraction gratings, with constant, polynomial, and holographic ruling spacing, and sinusoidal, square, rectangular, sawtooth, and triangular ruling profiles
  • CCD/CMOS sensor simulation, including quantum efficiency, noise, and charge diffusion
  • n-dimensional configurations of the optical system using named-arrays
  • Uncertainty propagation using named-arrays

Key concepts

Surfaces are placed in global coordinates. Unlike Zemax, where each surface is positioned relative to the one before it, an optika surface carries a transformation giving its position and orientation in the coordinate system of the whole instrument. Moving one surface therefore does not move everything downstream of it.

The field of view and entrance pupil are computed, not specified. The apertures of the surfaces determine them, so marking a surface with is_pupil_stop or is_field_stop is enough.

Rulings are a property of a surface. A diffraction grating is an ordinary surface with a rulings field, so switching between ruling designs does not mean switching to a different type of surface.

Any parameter can be an array. Giving a parameter an extra named axis sweeps the system over that axis, and every ray traced through it carries that axis along, which is how optika explores a configuration space without a loop. An UncertainScalarArray parameter propagates its uncertainty through the raytrace by the Monte Carlo method.

Simulate a Newtonian telescope using optika

Newtonian telescope example image simulation

Compute the reflectivity of a multilayer mirror by specifying the materials and thicknesses of the layers.

multilayer example

Model the quantum efficiency of a backilluminated CCD

QE example

Compute the transmissivity of a thin filter, such as the aluminum filters used to reject visible light on solar instruments.

import matplotlib.pyplot as plt
import astropy.units as u
import named_arrays as na
import optika

# Define the wavelengths at which to compute the transmissivity
wavelength = na.geomspace(100, 800, axis="wavelength", num=201) * u.AA

# Compute the efficiency of a 100 nm layer of aluminum
reflectivity, transmissivity = optika.materials.multilayer_efficiency(
    wavelength=wavelength,
    layers=optika.materials.Layer(
        chemical="Al",
        thickness=1000 * u.AA,
    ),
)

# Plot the transmissivity, which drops sharply at the aluminum L edge
fig, ax = plt.subplots(constrained_layout=True)
na.plt.plot(wavelength, transmissivity.average, ax=ax, axis="wavelength");
ax.set_xscale("log");
ax.set_xlabel(f"wavelength ({wavelength.unit:latex_inline})");
ax.set_ylabel("transmissivity");

aluminum filter example

Citation

If you use optika in your research, please cite it. The citation metadata is kept in CITATION.cff, which the "Cite this repository" button on GitHub can export as BibTeX or APA.

Every release of optika is archived on Zenodo with its own DOI. The concept DOI, 10.5281/zenodo.23074621, always resolves to the latest version, and the Zenodo page lists the DOI of every version. Please include the version of optika that you used, which is given by importlib.metadata.version("optika"). The BibTeX entry below uses the concept DOI. To cite a specific version instead, replace doi with the DOI of that version.

@software{optika,
  author = {Smart, Roy T. and Parker, Jacob D. and Kankelborg, Charles C.},
  title = {optika},
  version = {X.Y.Z},
  doi = {10.5281/zenodo.23074621},
  url = {https://github.com/sun-data/optika},
}

Development

Install the package in editable mode along with its test dependencies, and run the test suite using pytest:

pip install -e .[test]
pytest

This project is formatted using black, linted using ruff, and type-checked using mypy, all of which are checked by continuous integration:

black .
ruff check .
mypy optika

To build the documentation locally:

pip install -e .[doc]
sphinx-build docs docs/_build/html

Metadata

Release files for optika 3.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for optika 3.0.0
File Size Uploaded
optika-3.0.0.tar.gz 4.4 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for optika 3.0.0
File Interpreter ABI Platform
optika-3.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 9.4 MB

Release files / optika-3.0.0.tar.gz

Download URL optika-3.0.0.tar.gz
Size 4.4 MB
Tags Source
SHA-256 checksum
How to use checksums
31e2ea87523d0ab4ed31fe760fea0818c37819788fad1537e9d4772f4b0a1f14
BLAKE2b-256 checksum
How to use checksums
e0c6989c0e615322ac04cab25da6a0d6cedded95967ae44656573e50668641d6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 8, 2026.

Transparency log

Release files / optika-3.0.0-py3-none-any.whl

Download URL optika-3.0.0-py3-none-any.whl
Size 5.0 MB
Tags Python 3
SHA-256 checksum
How to use checksums
f16054c2cbd157676f8dc674c157333f2bec7af1d9936f7a0fb9d5a76feab197
BLAKE2b-256 checksum
How to use checksums
fc8d257a2e0d712a28a228bc3914bcaa9ec88f67cd84197242eb5351017e826c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 8, 2026.

Transparency log

Release history Release notifications | RSS feed

3.1.0

2 release files

This release

3.0.0 This release

2 release files

2.11.0

2 release files

2.10.0

2 release files

2.9.0

2 release files

2.8.0

2 release files

2.7.0

2 release files

2.6.0

2 release files

2.5.0

2 release files

2.4.0

2 release files

2.3.0

2 release files

2.2.0

2 release files

2.1.0

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.14.0

2 release files

0.13.0

2 release files

0.12.2

2 release files

0.12.1

2 release files

0.12.0

2 release files

0.10.0

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.10

1 release file

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

0.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page