Rust API

The Python package is a thin layer over the Rust crate scatrs, which can also be used directly. Its API reference is generated by rustdoc from the sources, with every example compiled and run as a test:

Open the Rust API reference →

Add it with cargo add scatrs. The same reference is on docs.rs.

The crate and the Python package

Rust

Python

Contents

scatrs::mie

scatrs.mie

One sphere: coefficients, efficiencies, amplitudes, phase matrix, Greek coefficients and their derivatives.

scatrs::layered

scatrs.layered

One layered sphere (a core and concentric shells): the same outputs, with derivatives with respect to every layer.

scatrs::tmatrix

scatrs.tmatrix

One spheroid by the T-matrix method: orientation-averaged efficiencies, Greek coefficients and phase matrix, the T-matrix itself and its convergence, with derivatives.

scatrs::ensemble

scatrs.Ensemble, scatrs.Mixture

Averages of spheres, layered spheres and spheroids over size distributions, mixtures and batches (Python: grids), with error estimates and derivatives.

scatrs::special

scatrs.special

Gauss–Legendre quadrature and Wigner d-functions.

scatrs::scalar

The Real trait and the double-double and dual-number types. Rust only.

scatrs::error

scatrs.errors

The error type, and the exceptions that mirror it.

The two APIs compute the same things with the same conventions, but differ in shape:

  • Vectorization. Python functions take arrays and loop over them in Rust. In Rust, a Mie workspace solves one sphere at a time, and the outputs are read from the MieSolution, into caller-owned buffers where they are arrays. For many spheres at the same angles, an AngularTable evaluates the angular functions once for all of them (the Python amplitude and phase-matrix functions use one).

  • Precision and derivatives. The Rust kernels are generic over Real, so they also run in double-double precision and with Dual numbers, for higher derivatives too. Python returns f64 values with first derivatives.

  • Options. Keyword arguments in Python are builder methods in Rust, such as MieOptions::with_n_max and EnsembleOptions::with_rtol.

The rustdoc is the authoritative statement of each function’s accuracy contract and of its behaviour at the edges of its domain; the theory pages summarise it.