Routines for analysis of polarization
Project description
pypolar
pypolar is a Python library for simulating, analyzing, and visualizing the polarization state of light as it propagates through optical systems. The package supports modeling with both Jones and Mueller calculus frameworks and includes functionality relevant to education, research, ellipsometry, and polarimetric system design.
The library provides computational tools, visualization utilities, and symbolic analysis support, making it suitable for laboratory instruction, computational optics coursework, and applied research in polarization optics.
Modules
pypolar is organized into several computational and symbolic components:
Numerical computation modules
pypolar.fresnel — Fresnel reflection and transmission calculations
pypolar.jones — Analysis of polarization using Jones calculus
pypolar.mueller — Polarization modeling using the Mueller calculus
pypolar.ellipsometry — Ellipsometry modeling tools
Visualization support
pypolar.poincare — Dedicated Poincaré sphere plotting routines
pypolar.visualization — Poincaré sphere and vector-based visualization routines
Symbolic computation
pypolar.sym_fresnel — Symbolic Fresnel reflection and transmission expressions
pypolar.sym_jones — Symbolic polarization modeling using Jones calculus
pypolar.sym_mueller — Symbolic Mueller matrix manipulation
Installation
pypolar may be installed via pip:
pip install pypolar
or using conda:
conda install -c conda-forge pypolar
Quickstart
This short example combines numerical Jones/Mueller calculations with a symbolic result.
import numpy as np
import sympy
import pypolar.jones as jones
import pypolar.mueller as mueller
import pypolar.sym_jones as sym_jones
# Jones: left-circular light through a linear polarizer at 30 degrees
J = jones.op_linear_polarizer(np.pi / 6) @ jones.field_left_circular()
print("Jones output:", J)
# Mueller: unpolarized input through the same polarizer
S = mueller.op_linear_polarizer(np.pi / 6) @ mueller.stokes_unpolarized()
print("Stokes output:", S)
# Symbolic: Malus' law
theta = sympy.symbols("theta", real=True)
I = sympy.simplify(
sym_jones.intensity(sym_jones.op_linear_polarizer(theta) * sym_jones.field_horizontal())[0]
)
print("Symbolic intensity:", I)
Documentation and Examples
Comprehensive user documentation, theory notes, and executable Jupyter examples are available at:
📄 https://pypolar.readthedocs.io
or use immediately in your browser via the JupyterLite button below
Examples
Circular Polarization Visualization
from pypolar import jones
from pypolar import visualization as vis
v = jones.field_left_circular()
print("Jones vector for left circularly polarized light:", v)
ani = vis.draw_jones_animated(v, nframes=32)
ani
will produce something like
Optical Isolator
The following example demonstrates modeling an optical isolator using the Jones formalism.
import numpy as np
import matplotlib.pyplot as plt
from pypolar import jones
from pypolar import visualization as vis
b = jones.op_linear_polarizer(0)
c = jones.op_quarter_wave_plate(np.pi / 4)
d = jones.op_mirror()
e = jones.op_quarter_wave_plate(-np.pi / 4)
fig = plt.figure(figsize=(8, 8))
ax = fig.add_subplot(111, projection="3d")
vis.draw_empty_sphere(ax)
j1 = jones.field_elliptical(np.pi / 6, np.pi / 6)
j2 = b @ j1
j3 = c @ j2
j4 = d @ j3
j5 = e @ j4
vis.draw_jones_poincare(j1, ax, label=" start", color="red", va="center")
vis.draw_jones_poincare(j2, ax, label=" after Polarizer", color="blue", va="center")
vis.draw_jones_poincare(j3, ax, label=" after QWP", color="blue", va="center")
vis.draw_jones_poincare(j4, ax, label=" after mirror", color="blue", va="center")
vis.draw_jones_poincare(j5, ax, label=" final", color="red", va="center")
vis.join_jones_poincare(j1, j2, ax, color="blue", lw=2, linestyle=":")
vis.join_jones_poincare(j2, j3, ax, color="blue", lw=2, linestyle=":")
vis.join_jones_poincare(j3, j4, ax, color="blue", lw=2, linestyle=":")
vis.join_jones_poincare(j4, j5, ax, color="blue", lw=2, linestyle=":")
plt.show()
Symbolic Jones: Half-Wave Plate Rotation
This symbolic example verifies a useful identity: a half-wave plate with fast axis angle theta rotates linear polarization from alpha to 2*theta - alpha (up to a global phase factor, which does not affect the physical polarization state). It also derives the analyzer transmission in closed form.
import sympy
import pypolar.sym_jones as sym_jones
theta, alpha = sympy.symbols("theta alpha", real=True)
J_in = sym_jones.field_linear(alpha)
# Pass through a half-wave plate with fast axis at theta
J_out = sympy.simplify(sym_jones.op_half_wave_plate(theta) * J_in)
# Identity check using half wave plate
J_expected = sympy.I * sym_jones.field_linear(2 * theta - alpha)
print("Identity check:", sympy.simplify(J_out - J_expected))
# Pass through a vertical analyzer and get intensity
J = sym_jones.op_linear_polarizer(sympy.pi / 2) * J_out
I = sym_jones.intensity(J)[0].simplify().trigsimp()
print("I(theta, alpha) =", I)
produces:
Identity check: Matrix([[0], [0]])
I(theta, alpha) = sin(alpha - 2*theta)**2
Mueller Matrix Example
import numpy as np
import pypolar.mueller as mueller
A = mueller.stokes_right_circular()
B = mueller.op_linear_polarizer(np.pi/4)
C = mueller.op_quarter_wave_plate(0)
D = mueller.op_mirror()
E = mueller.op_quarter_wave_plate(0)
F = mueller.op_linear_polarizer(-np.pi/4)
F @ E @ D @ C @ B @ A
produces:
array([0., 0., 0., 0.])
Citation
If you use pypolar in academic, instructional, or applied technical work, please cite:
Prahl, S. (2026). pypolar: A Python module for polarization using Jones and Mueller calculus (Version 1.1.0) [Computer software]. Zenodo. https://doi.org/10.5281/zenodo.8358111
BibTeX
@software{pypolar_prahl_2026,
author = {Scott Prahl},
title = {pypolar: A Python module for polarization using Jones and Mueller calculus},
year = {2026},
version = {1.1.0},
doi = {10.5281/zenodo.8358111},
url = {https://github.com/scottprahl/pypolar},
publisher = {Zenodo}
}
License
pypolar is distributed under the terms of the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pypolar-1.2.0.tar.gz.
File metadata
- Download URL: pypolar-1.2.0.tar.gz
- Upload date:
- Size: 63.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f599ce08e18692719a539a966fe01576d41119d4c5cd75a71af3175e8d7171c1
|
|
| MD5 |
de567bbf4d9ea0adcca9c5a37b74e48a
|
|
| BLAKE2b-256 |
af4af3e64d5ea33f925bce351f36d7e37718df335e49812b9d7588545e455f5f
|
Provenance
The following attestation bundles were made for pypolar-1.2.0.tar.gz:
Publisher:
pypi.yaml on scottprahl/pypolar
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pypolar-1.2.0.tar.gz -
Subject digest:
f599ce08e18692719a539a966fe01576d41119d4c5cd75a71af3175e8d7171c1 - Sigstore transparency entry: 952249503
- Sigstore integration time:
-
Permalink:
scottprahl/pypolar@cb5f1a36eac81c023ee70b7d17516f824ece787c -
Branch / Tag:
refs/tags/1.2.0 - Owner: https://github.com/scottprahl
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yaml@cb5f1a36eac81c023ee70b7d17516f824ece787c -
Trigger Event:
release
-
Statement type:
File details
Details for the file pypolar-1.2.0-py3-none-any.whl.
File metadata
- Download URL: pypolar-1.2.0-py3-none-any.whl
- Upload date:
- Size: 44.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
afc80c727dec23f6e749353226087de6a19dcbf1e945a6b2b73fe706492e42e8
|
|
| MD5 |
685b4c9534813c94d96223d40134545d
|
|
| BLAKE2b-256 |
298751a1c3a56968a6b64585731097950b9bc42c0869342d4a9577bb166e490f
|
Provenance
The following attestation bundles were made for pypolar-1.2.0-py3-none-any.whl:
Publisher:
pypi.yaml on scottprahl/pypolar
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pypolar-1.2.0-py3-none-any.whl -
Subject digest:
afc80c727dec23f6e749353226087de6a19dcbf1e945a6b2b73fe706492e42e8 - Sigstore transparency entry: 952249516
- Sigstore integration time:
-
Permalink:
scottprahl/pypolar@cb5f1a36eac81c023ee70b7d17516f824ece787c -
Branch / Tag:
refs/tags/1.2.0 - Owner: https://github.com/scottprahl
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yaml@cb5f1a36eac81c023ee70b7d17516f824ece787c -
Trigger Event:
release
-
Statement type: