Skip to main content

A transfer matrix algorithm and related tools

Project description

Pistachio

Author: Garrek Stemo
Affiliation: Nara Institute of Science and Technology
Date Created: July 5, 2019
Updated: July 26, 2021

Pistachio implements the 2x2 transfer matrix method in Yeh, P. Optical Waves in Layered Media. (Wiley, 2005). As of July 2021, it has been almost completely refactored from a command-line application. Classes have been restructured and the whole program has been made into a Python package so that it can be installed and classes and methods can be called from other programs.

Unit tests have been implemented to ensure the reproducibility of the code. Unit tests and integration tests are still in active development with the goal of creating a program that stands up to scientific rigor and reproducibility with a test-driven approach that is lacking in the scientific programming community.

Pistachio uses the new type hinting features introduced in Python 3.9, which helps greatly with writing clean, reproducible code. Type hinting also aids readability when distributing sometimes complex code among the scientific community.

Transfer Matrix Method

Introduction

The transfer matrix module computes transmission and reflection for a multi-layered optical structure using the 2x2 transfer matrix method. The user may create a config file in the yaml format, which may include refractive index data for each layer in separate files. The program uses the multiprocess library for Python to parallelize transfer matrix calculations to distribute calculations for multiple incident angles to processing cores.

Config files

Config files are stored in the yaml format with configurations for each material layer. At the top, the number of points, minimum, and maximum wavelengths are specified, which are used to generate a list of wavelengths between the minimum and maximum for the simulation. Incident wave properties include the starting and ending incident angle (for angle-tuned calculations), right-traveling wave amplitude, and left-traveling wave amplitude. If theta_i (initial angle) and theta_f are different, then transfer matrix calculations are carried out for each angle in that range, with the number of angles determined by num_angles.

Each layer requires a material name, thickness, and a file containing the refractive index for each wavelength. All values are assumed to be in SI units (i.e. meters instead of nanometers).

Example transfer matrix config file

num_points: 1000
min_wavelength: 1.0e-6
max_wavelength: 1.0e-5
wave:
	polarization: "s-wave"
	theta_i: 0.0
	theta_f: 30.0
	num_angles: 31
	A0: 1
	B0: 0

layers:
		layer0:
	    material: CaF2
	    thickness: 0
	    refractive_filename: "layer0.csv"
    layer1:
	    material: Au
	    thickness: 10
	    refractive_filename: "layer1.csv"
    layer2:
	    material: Air
	    thickness: 1000
	    wavelength: 1.e-6
	    refractive_index: 1.0003
	    extinction_coeff: 0.0
		layer3
	    material: Au
	    thickness: 10
	    refractive_filename: "layer1.csv"
		layer4:
			material: CaF2
			thickness: 0
			refractive_filename: "layer0.csv"

The refractive_filename specifies the path where refractive index data is stored, which must be saved as a .csv file with wavelength, refractive index, and extinction coefficient columns.

Running a transfer matrix simulation

Pistachio may be run from the command line. For example, if you want to run simulation with a p-wave field, you would navigate to the pistachio directory and enter

python transfer_matrix.py -p config_files/file_name.yaml results

The results directory is any directory where you wish to write the results. When in doubt, run python transfer_matrix.py -h to see the types and order of inputs.

Classes and methods may also be called in other programs or in Jupyter Lab, which is now much more convenient and probably the preferred way.

How to install Pistachio

Make sure you have Python 3, numpy, scipy, and other dependencies in the headers installed. The easiest way to do this is to install a package manager, like Anaconda.

Then go to the command line. Navigate to the directory where you want to put Pistachio, like ~/projects/, using the cd command. Then enter

git clone https://github.com/garrekds/pistachio .

This is a Python package now, so you can use pip install . to install it once you download the source code. Pistachio has now been published on PyPi.org, so you can also install from there using pip.

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

pistachio-tm-0.10.3.tar.gz (13.3 kB view details)

Uploaded Source

Built Distribution

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

pistachio_tm-0.10.3-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file pistachio-tm-0.10.3.tar.gz.

File metadata

  • Download URL: pistachio-tm-0.10.3.tar.gz
  • Upload date:
  • Size: 13.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.5

File hashes

Hashes for pistachio-tm-0.10.3.tar.gz
Algorithm Hash digest
SHA256 f608532abec782b8b011ea710ce003790b8b1b05bd08f6ad1b35ca4e89daa067
MD5 dc275b875729f91fb161e2b4c63f989c
BLAKE2b-256 1106b7b3d67afdc9a15816b021fa66cfc3d3085926fe55a9678cc68a66ccacad

See more details on using hashes here.

File details

Details for the file pistachio_tm-0.10.3-py3-none-any.whl.

File metadata

  • Download URL: pistachio_tm-0.10.3-py3-none-any.whl
  • Upload date:
  • Size: 12.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.5

File hashes

Hashes for pistachio_tm-0.10.3-py3-none-any.whl
Algorithm Hash digest
SHA256 529717c69efc4561030a73f81344f3360f05be4c80304c92eb658ffc691e6a59
MD5 8cff7e8cf5bfca1c7e6c3f91333e0dba
BLAKE2b-256 d8ec4ccfea01b510b417c4f2e95fb410f28e51d61deffe268a6c404c4f56ddc8

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