Skip to main content

A minimalistic Python package to generate individual or a series of Zernike polynomials of arbitrary orders with visualization.

Project description

ZernikePy is a minimalistic Python library to compute and visualize Zernike polynomials of any given orders. A typical usage is to generate basis functions for phase modulation in optics.

Installation

pip install ZernikePy

Requirements

numpy
scipy
matplotlib

How to use

After installation, first import the main function from the library

from zernikepy import zernike_polynomials

Examples

Generate a (256, 256)-sized Zernike polynomial of order 4 (defocusing):

p = zernike_polynomials(mode=4, size=256)

or

p = zernike_polynomials(mode='defocusing', size=256)

Generate the first 15 modes and display them:

ps = zernike_polynomials(mode=14, select='all', show=True)

Example image of the first 15 modes

Generate the following selected modes defocusing, vertical coma, oblique astigmatism and display them:

ps = zernike_polynomials(mode=10, select=[4, 'vertical coma', 'oblique astigmatism'], show=True)

Note that regardless of the order of the elements in the list select, the output stores the polynomials in ascending order in the last dimension. Hence, in the output ps[:, :, 0] is oblique astigmatism, ps[:, :, 1] is defocusing and ps[:, :, 2] is vertical coma.

Detailed explanation

The main function zernike_polynomials(mode, size, select, show) takes four variables:

  • mode: which (or up to which) order of the polynomial. It follows the OSA standard indexing convention and should be a nonnegative integer. It is also possible to pass a string of the corresponding name for the first 15 modes. Default is 'defocus'.
  • size: numerical size of the square Cartesian mesh. It should be a postive integer. Default is 128.
  • select: in the case of passing more than one polynomial, i.e. some selected modes up to the given mode, give a list of integers or strings or a mixture of both. A special case is select='all' where all the polynomials up to the given mode is passed. Default is None in which case only a single polynomial of the given mode is passed.
  • show: boolen variable to determine whether to display the polynomials. Default is False.

The output is a Numpy array, either 2D for a single mode, or 3D for multiple modes.

Name of the first 15 modes

Mode / OSA index Name
0 piston
1 vertical tilt
2 horizontal tilt
3 oblique astigmatism
4 defocus
5 vertical astigmatism
6 vertical trefoil
7 vertical coma
8 horizontal coma
9 oblique trefoil
10 oblique quadrafoil
11 oblique secondary astigmatism
12 primary spherical
13 vertical secondary astigmatism
14 vertical quadrafoil

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zernikepy-0.0.5.tar.gz (6.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ZernikePy-0.0.5-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file zernikepy-0.0.5.tar.gz.

File metadata

  • Download URL: zernikepy-0.0.5.tar.gz
  • Upload date:
  • Size: 6.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.6

File hashes

Hashes for zernikepy-0.0.5.tar.gz
Algorithm Hash digest
SHA256 12ed018d3450fd7add4fd7a909199a03506c14c845dcd6a8baf8260744d30f3e
MD5 7b385021f0079852da6a3e5bd626ea33
BLAKE2b-256 0babf4644e5d1c244c3ff66c3b153692f5e8863d3bacda54c686df452d34b966

See more details on using hashes here.

File details

Details for the file ZernikePy-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: ZernikePy-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.6

File hashes

Hashes for ZernikePy-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 00726b90c7143b4f34f3b5e9d15b137d4989efd3cf9bd8f845461ff88407114c
MD5 945bb0c85ae77fd5eb18dc3287e82aba
BLAKE2b-256 13c82a116c02f21d991c38a30ba80650cfd83749662568bbf032c5a8f380f575

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page