Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

prtLab Python

prtLab is a polarization ray-tracing toolkit for optical systems containing isotropic and uniaxial materials. This directory contains the installable Python implementation. The MATLAB implementation in the repository root remains the reference and the python is a port of that implementation that preserves numerical parity.

Installation

From the pyprtLab directory, install the package into an activated Python environment:

python -m pip install .

To work on the package itself, use an editable installation with the development tools:

python -m pip install -e ".[dev]"
pytest

The package name and import name differ only in capitalization. Import it as:

import prtlab

Units

Optical systems default to wavelength in microns and geometry in millimeters. Geometry units apply to radii, thicknesses, ray positions, solid vertices, and optical path length. prtLab performs the wavelength conversion internally when calculating propagation phase.

system = prtlab.create_optical_system(
    0.633, wavelength_units="um", geometry_units="mm"
)

Quick Start

This traces the quarter-wave plate used in Chipman Example 20.1 and coherently recombines its ordinary and extraordinary branches:

from prtlab import (
    coherent_final_jones,
    jones_retardance_waves,
    polarization_ray_trace,
    quarter_wave_plate_system,
)

system = quarter_wave_plate_system()
result = polarization_ray_trace(
    system,
    [0, 0, 1],
    [0, 0, 0],
    [0, 1],
    {"encodePropagationPhaseInP": True},
)
jones = coherent_final_jones(result)
print("Retardance [waves]:", jones_retardance_waves(jones))

Examples and Notebooks

The examples are the best entry point for learning the current API. Python scripts are stored in examples, and direct translations of the MATLAB notebooks are stored in docs/source:

For interactive notebook use, register the project environment once:

python -m ipykernel install --user \
    --name prtlab-python --display-name "prtLab Python"

Then select prtLab Python from Jupyter's kernel menu.

Solid Scene Example

import matplotlib.pyplot as plt
import numpy as np

from prtlab import (
    create_fresnel_rhomb_solid,
    plot_prt_system_3d,
    polarization_ray_trace_solid,
)

rhomb = create_fresnel_rhomb_solid(
    1.495,
    length=14,
    height=8,
    width=8,
    shear=11.02085,
    wavelength=0.589,
)
result = polarization_ray_trace_solid(
    rhomb,
    [0, np.sin(np.deg2rad(0.1)), np.cos(np.deg2rad(0.1))],
    [0, 5, -2],
    [1, 1] / np.sqrt(2),
    {"maxInteractions": 8, "minAmplitude": 1e-4},
)

plot_prt_system_3d(
    rhomb,
    result,
    {"PostExtend": 4, "ShowLegend": True},
)
plt.show()

The 3D renderer colors ordinary, extraordinary, and reflected branches separately. Red glyphs show the real time-domain locus of each complex electric field.

Validation

Run the Python tests and notebook checks with:

pytest
python tools/validate_notebooks.py
python tools/validate_notebooks.py --execute
python tools/smoke_test_wheel.py

See PORTING_STATUS.md for current MATLAB-to-Python coverage.

MATLAB Synchronization

Every MATLAB function in prtLab/ is classified in tools/matlab_port_manifest.json as parity-tested, internal, deferred, or legacy. Validate the inventory and show deferred APIs with:

python tools/audit_api_parity.py --list-deferred

After changing MATLAB code, report files changed since the last reviewed Python synchronization point with:

python tools/check_matlab_sync.py

After those changes have been reviewed, ported, and tested, record the current commit with:

python tools/check_matlab_sync.py --mark-current

The marker is a review checkpoint, not an automatic claim of numerical parity.

License

prtLab is distributed under the BSD 3-Clause License. See LICENSE.

Download files

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

Source Distribution

prtlab-0.1.0a3.tar.gz (52.5 kB view details)

Uploaded Source

Built Distribution

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

prtlab-0.1.0a3-py3-none-any.whl (49.6 kB view details)

Uploaded Python 3

File details

Details for the file prtlab-0.1.0a3.tar.gz.

File metadata

  • Download URL: prtlab-0.1.0a3.tar.gz
  • Upload date:
  • Size: 52.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for prtlab-0.1.0a3.tar.gz
Algorithm Hash digest
SHA256 3c0201755f8473f0854d1858f723cceacf8d78f9a1a67e65a2dae5eb99cc606d
MD5 1f4232d73725744dbce1f2832ecc3762
BLAKE2b-256 a3c0ec072e519ff833c59d21c3be3854a72211d3ef03b36e92e6c545d594a49f

See more details on using hashes here.

Provenance

The following attestation bundles were made for prtlab-0.1.0a3.tar.gz:

Publisher: publish-pypi.yml on jeremynesbitt/prtLab

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file prtlab-0.1.0a3-py3-none-any.whl.

File metadata

  • Download URL: prtlab-0.1.0a3-py3-none-any.whl
  • Upload date:
  • Size: 49.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for prtlab-0.1.0a3-py3-none-any.whl
Algorithm Hash digest
SHA256 f9cb1f3106b5c891b2cc0c4cbefc9092fbc618df6d2fb2b3e41016f4a0cee929
MD5 d3427305c33176b6c4a9642697e05bbe
BLAKE2b-256 ae0828855eb4bd3ccf623adb250a9ec7d0ae083906c4af79aa705ffb40bdd23a

See more details on using hashes here.

Provenance

The following attestation bundles were made for prtlab-0.1.0a3-py3-none-any.whl:

Publisher: publish-pypi.yml on jeremynesbitt/prtLab

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.0a3 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page