Skip to main content

Polarization

By Daniel Côté dccote@cervo.ulaval.ca

Polarization is a simple module to manage optical polarization with Jones and Stokes vectors. You create a JonesVector or use on of the pre-defined ones, then you apply your JonesMatrix or you use one of the many pre-defined ones. You can visualize the field with JonesVector.show()

You need matplotlib, which is a fairly standard Python module and numpy. If you do not have it, installing Anaconda is your best option. Python 3.6 or later is required. There are several ways to install the module:

  1. Simplest pip install --upgrade polarization

    1. If you need to install pip, download getpip.py and run it with python getpip.py
  2. If you download the source of the module, then you can type: python setup.py install

  3. From GitHub, you can get the latest version (including bugs, which are 153% free!) and then type python setup.py install

  4. If you are completely lost, copying the folder polarization (the one that includes __init__.py) from the source file into the same directory as your own script will work.

  • To see the example code, type python -m polarization. The example code is below and will get printed to your console after it has executed.

You can visualize the field with v.show() or v.show("movie.mp4") to save it.

Example of arbitrary polarization (it is a movie, but GitHub does not allow them: movie available here)

image-20210217084547641 image-20210217093640475
from polarization import *

# Define the vector with Ex and Ey
print("\n\nDefine horizontal polarization with JonesVector(Ex=1, Ey=0)")
print("===========================================================")
v = JonesVector(Ex=1, Ey=0) # horizontal
print("Components are {0}".format(v))
print("Orientation is {0:.2f} rad or {1:.1f}°".format(v.orientation,v.orientation*degPerRad))
v.show()
#v.show("horizontal.mp4") #to save movie

print("\n\nDefine other polarizations with JonesVector(Ex, Ey),\ncan be normalized with .normalize()")
print("====================================================")
v = JonesVector(Ex=1, Ey=1).normalize() # +45°
print("Components are {0}".format(v))
print("Orientation is {0:.2f} rad or {1:.1f}°".format(v.orientation,v.orientation*degPerRad))
v.show()
#v.show("plus45.mp4") #to save movie

print("\n\nMany predefined vectors exist")
print("=============================")
# Many predefined vectors:
# JonesVector.vertical()
# JonesVector.horizontal()
# JonesVector.plus45()
# JonesVector.minus45()
# JonesVector.rightCircular()
# JonesVector.leftCircular()

print("\nJonesVector.rightCircular()")
print("-----------------------------")
v = JonesVector.rightCircular() 
print("Components are {0}".format(v))
print("Orientation is {0:.2f} rad or {1:.1f}°".format(v.orientation,v.orientation*degPerRad))
v.show()

print("\nJonesVector.leftCircular()")
print("-----------------------------")
v = JonesVector.leftCircular() # Many predefined vectors
print("Components are {0}".format(v))
print("Orientation is {0:.2f} rad or {1:.1f}°".format(v.orientation,v.orientation*degPerRad))
v.show()

# Arbitrary polarization
print("\n\nArbitrary polarization JonesVector(Ex=1*exp(1j*0.3), Ey=0.5).normalize()")
print("========================================================================")
v = JonesVector(Ex=1*exp(1j*0.3), Ey=0.5).normalize()
print("Components are {0}".format(v))
print("Orientation is {0:.2f} rad or {1:.1f}°".format(v.orientation,v.orientation*degPerRad))
v.show()

# Many properties are defined:
print("\n\nMany properties to access polarization state")
print("============================================")
print("For vector {0}".format(v))
print("v.orientation (0=horizontal) = {0}".format(v.orientation))
print("v.isLinearlyPolarized        = {0}".format(v.isLinearlyPolarized))
print("v.isEllipticallyPolarized    = {0}".format(v.isEllipticallyPolarized))
print("v.isCircularlyPolarized      = {0}".format(v.isCircularlyPolarized))
print("v.isRightCircularlyPolarized = {0}".format(v.isRightCircularlyPolarized))
print("v.isLeftCircularlyPolarized  = {0}".format(v.isLeftCircularlyPolarized))

# Vectors can be transformed by JonesMatrices
# Any matrix can be created with JonesMatrix(A,B,C,D)
# but there are many predefined matrices:
#
# HorizontalPolarizer(): polarizer at theta=0°
# VerticalPolarizer(): polarizer at theta=90° 
# Plus45Polarizer(): polarizer at theta=45°
# Minus45Polarizer(): polarizer at theta=-45°
# HWP(theta=pi/4) : halfwave plate at 45°
# QWP(theta=pi/4) : quarterwave plate at 45° 
# RightCircularPolarizer(): right circular polarizer
# LeftCircularPolarizer(): left circular polarizer
# PhaseRetarder(): arbitrary retarder

print("\n\nTransform the JonesVector with JonesMatrices")
print("============================================")
print("horizontal vector going through quarter waveplate")

vIn = JonesVector.horizontal()
v = QWP(theta=pi/4)*vIn

print("Input components are {0}".format(vIn))
print("Output components are {0}".format(v))
print("Orientation is {0:.2f} rad or {1:.1f}°".format(v.orientation,v.orientation*degPerRad))
print("isCircular {0}".format(v.isCircularlyPolarized))
v.show()

print("\n\nApply several JonesMatrices sequentially")
print("============================================")

vIn = JonesVector.horizontal()
v = HWP(theta=pi/2)*QWP(theta=pi/3)*vIn

print("Input components are {0}".format(vIn))
print("Output components are {0}".format(v))
print("Orientation is {0:.2f} rad or {1:.1f}°".format(v.orientation,v.orientation*degPerRad))
print("v.isLinearlyPolarized        = {0}".format(v.isLinearlyPolarized))
print("v.isEllipticallyPolarized    = {0}".format(v.isEllipticallyPolarized))
print("v.isCircularlyPolarized      = {0}".format(v.isCircularlyPolarized))
print("v.isRightCircularlyPolarized = {0}".format(v.isRightCircularlyPolarized))
print("v.isLeftCircularlyPolarized  = {0}".format(v.isLeftCircularlyPolarized))
v.show()

print("Malus law example")
print("=================")
x = []
y = []
vIn = JonesVector.horizontal()
for theta in range(0,190,10):
    pol = LinearPolarizer(theta=theta*radPerDeg)
    vOut = pol*vIn

    x.append(theta)
    y.append(vOut.intensity)

plt.title("\n\nMalus Law: horizontal beam intensity after linear polarizer")
plt.xlabel(r"Polarizer orientation $\theta$ from horizontal [°]")
plt.ylabel(r"Intensity [arb. unit]")
plt.plot(x,y,'ko')
plt.show()

Metadata

Release files for polarization 1.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for polarization 1.0.4
File Size Uploaded Provenance Actions
polarization-1.0.4.tar.gz 14.9 kB Without provenance Details for polarization-1.0.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for polarization 1.0.4
File Interpreter ABI Platform Actions
polarization-1.0.4-py3-none-any.whl Python 3 none any Details for polarization-1.0.4-py3-none-any.whl

Total release size: 31.5 kB

Release files / polarization-1.0.4.tar.gz

Download URL polarization-1.0.4.tar.gz
Size 14.9 kB
Tags Source
SHA-256 checksum
How to use checksums
27319f2887505b9170036658d2d634801ccdcc861fb8056af6464e8110520d06
BLAKE2b-256 checksum
How to use checksums
0645db28f6bd0546b6ed8b636464e5d93d1030f664909c5d479d72fd157684d5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0.post20210125 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.7.9

Release files / polarization-1.0.4-py3-none-any.whl

Download URL polarization-1.0.4-py3-none-any.whl
Size 16.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
edf4b45d7dbb19452c30f6aec2857671acf9d5d78a03b0136c00345490893c80
BLAKE2b-256 checksum
How to use checksums
7f18f9ccada49625df89996570aae98a6189efd67bc9b7466b090df1e87b8d4d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0.post20210125 requests-toolbelt/0.9.1 tqdm/4.55.1 CPython/3.7.9

Security for polarization 1.0.4

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.

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