🌈 pyTMat

pyTMat is a blazing-fast, user-friendly Python package for simulating optical multilayer stacks using the Transfer Matrix Method (TMM). Powered by a Rust core for maximum performance, pyTMat makes it easy to compute reflection and transmission spectra for complex photonic structures—perfect for research, engineering, and education.


🚀 Features

  • Ultra-fast: Rust-powered core for high-performance calculations
  • Easy-to-use: Simple Python API, no need to write Rust
  • Parallelized: Automatically uses all your CPU cores for large wavelength arrays
  • Polarization Support: TE, TM, and arbitrary polarization angles
  • Flexible: Any number of layers, complex refractive indices, and arbitrary thicknesses
  • Perfect for DBRs, filters, sensors, and more!

📦 Installation

Install the latest release directly from PyPI:

pip install pytmat

import numpy as np import pytmat

Define layer thicknesses (nm)

d = np.array([100, 200, 100]) # Example: 3 layers

Define complex refractive indices for each layer at each wavelength

Shape: (num_layers, num_wavelengths)

n = np.array([ [1.0+0j, 1.0+0j, 1.0+0j], # Layer 1 [2.0+0j, 2.0+0j, 2.0+0j], # Layer 2 [1.5+0j, 1.5+0j, 1.5+0j], # Layer 3])

Wavelengths (nm)

wl = np.linspace(400, 700, 3)

Angle of incidence (radians) and polarization angle (radians)

theta = 0.0 # normal incidence phi = 0.0 # TE polarization

Create the TMM data object

data = pytmat.Data(d, n, wl, theta, phi)

Compute reflection and transmission spectra

R = data.get_r_power_vec() T = data.get_t_power_vec()

print(“Reflection:”, R) print(“Transmission:”, T)