pyzernike
pyzernike computes, fits and displays the Zernike polynomials, on the unit disk and on elliptic annuli
(off-axis pupils, telescopes with a central obscuration, ...), with numpy only.
The Zernike polynomials are defined on the unit disk for |m| <= n and n - m even by:
with:
where n is the radial order, m is the azimuthal frequency, ρ is the normalized radial coordinate (0 <= ρ <= 1)
and θ is the azimuthal angle.
Features
- Polynomials and derivatives of any order, with exact integer coefficients, in polar coordinates or in Cartesian coordinates on an elliptic annulus (shifted, scaled and rotated ellipse with an optional central hole).
- Accuracy at high orders: all the polynomials up to an order are computed with a stable recurrence relation.
- Conventions: OSA/ANSI, Noll and Fringe indexings, and normalization of Noll.
- Coefficients: evaluation of a sum of polynomials and of its derivatives, conversion between the conventions, rotation and change of pupil, RMS, peak-to-valley and Strehl ratio.
- Fitting: linear least squares fit of sampled data, and residual and Jacobian functions to estimate the position and the size of a pupil with any least squares solver.
- Optional features: symbolic expressions (
sympy) and static or interactive figures (matplotlib).
All the computations are performed in double precision (numpy.float64).
Installation
pip install pyzernike-polynomials
The optional features need extra dependencies:
pip install "pyzernike-polynomials[display]" # matplotlib, for the display functions
pip install "pyzernike-polynomials[symbolic]" # sympy, for the symbolic expressions
pip install "pyzernike-polynomials[all]" # all the optional features
Or install the development version from GitHub:
pip install git+https://github.com/Artezaru/pyzernike.git
See the installation guide for more details.
Quick start
Fit a wavefront sampled on a grid and evaluate its RMS:
import numpy
import pyzernike
x, y = numpy.meshgrid(numpy.linspace(-1, 1, 201), numpy.linspace(-1, 1, 201))
rho, theta = numpy.hypot(x, y), numpy.arctan2(y, x)
wavefront = 0.3 * pyzernike.zernike_polynomial(rho, theta, n=2, m=0) # NaN outside the unit disk
coefficients = pyzernike.zernike_fit(rho, theta, wavefront, order=4, normalize=True)
print(pyzernike.zernike_rms(coefficients, normalize=True))
More examples (wavefront on an elliptic pupil, alignment of a pupil, distortion of a sensor, ...) are available in the examples gallery.
Command line
The command pyzernike opens an interactive window to explore the polynomials and their derivatives on the unit
disk, and pyzernike --xy on an elliptic annulus (matplotlib is required):
pyzernike
pyzernike --xy
Documentation
The online documentation contains:
- the mathematical description of the polynomials, the conventions, the elliptic annulus, the coefficients and the fits;
- the API reference of all the functions;
- the examples gallery.
Author
-
Artezaru artezaru.github@proton.me
-
Git platform: https://github.com/Artezaru/pyzernike
-
Online documentation: https://Artezaru.github.io/pyzernike
License
Copyright 2025 Artezaru
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Metadata
Release files for pyzernike-polynomials 4.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyzernike_polynomials-4.0.0.tar.gz | 2.0 MB | Without provenance | Details for pyzernike_polynomials-4.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyzernike_polynomials-4.0.0-py3-none-any.whl | Python 3 | none | any | Details for pyzernike_polynomials-4.0.0-py3-none-any.whl |
Total release size: 2.4 MB
Release files / pyzernike_polynomials-4.0.0.tar.gz
| Download URL | pyzernike_polynomials-4.0.0.tar.gz |
|---|---|
| Size | 2.0 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b885a12d6e2e4c5ed45b4f26a57aeb5d10163d10d26cec2bd31116eaed27bbb6
|
|
BLAKE2b-256 checksum How to use checksums |
0227795beca9353ebf86f95197a211b070f9607a7cbeda9724d274817a9c4af1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.18
|
Release files / pyzernike_polynomials-4.0.0-py3-none-any.whl
| Download URL | pyzernike_polynomials-4.0.0-py3-none-any.whl |
|---|---|
| Size | 410.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ffbf30bd67ff5e44eee1b396c2e0f5f323eeb5d7413dff758f7c16b60c619fa4
|
|
BLAKE2b-256 checksum How to use checksums |
1abb24f3c0eb1c0d1a720e14759fffee731da683a1a28095e89f4b4321dc6c80
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.18
|
Security for pyzernike-polynomials 4.0.0
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.