Skip to main content

A python interface to the refractiveindex.info database.

Project description

Python interface to RefractiveIndex database

Tests

The original database
https://github.com/polyanskiy/refractiveindex.info-database

Installation

pip install refractiveindex

Usage

import numpy as np
from refractiveindex import RefractiveIndexMaterial

# Tabulated nk material
SiO = RefractiveIndexMaterial(shelf='main', book='SiO', page='Hass')

SiO.get_refractive_index(600)
# 1.96553846

SiO.get_extinction_coefficient(600)
# 0.001

SiO.get_epsilon(600)
# (3.8633404437869827+0.003931076923076923j)

# Formula-based material
bk7 = RefractiveIndexMaterial(shelf='specs', book='SCHOTT-optical', page='N-BK7')
bk7.get_refractive_index(589.3)
# 1.5168...

# Array input
wavelengths = np.array([400, 500, 600, 700])
SiO.get_refractive_index(wavelengths)
# array([2.15092857, 1.999, 1.96553846, 1.942])

Units

All methods accept an optional unit= parameter. Default is nm. The following calls are all equivalent:

bk7.get_refractive_index(589.3)                 # nm (default)
bk7.get_refractive_index(5893, unit='A')         # Angstrom
bk7.get_refractive_index(5.893e-7, unit='m')     # meters
bk7.get_refractive_index(0.5893, unit='um')      # µm
bk7.get_refractive_index(16978, unit='cm-1')     # wavenumbers
bk7.get_refractive_index(508.8, unit='THz')      # terahertz
bk7.get_refractive_index(2.108, unit='eV')       # electron volts

The same parameter works for get_extinction_coefficient, get_epsilon, and get_wl_range.

Unit String Conversion from µm
meters 'm' $\lambda{[\text{m}]} = \lambda{[\mu\text{m}]} \cdot 10^{-6}$
nanometers 'nm' $\lambda{[\text{nm}]} = \lambda{[\mu\text{m}]} \cdot 10^{3}$
Angstroms 'A' $\lambda{[\text{Å}]} = \lambda{[\mu\text{m}]} \cdot 10^{4}$
wavenumbers 'cm-1' $\tilde{\nu}{[\text{cm}^{-1}]} = 10^4 / \lambda{[\mu\text{m}]}$
terahertz 'THz' $\nu{[\text{THz}]} = \frac{c[\text{m}/\text{s}] \cdot 10^{-6}}{\lambda{[\mu\text{m}]}}$
electron volts 'eV' $E [\text{eV}] = \frac{h[\text{J}\cdot \text{s}]\cdot c[\text{m}/\text{s}] \cdot 10^{6}}{e[\text{C}] \cdot \lambda [\mu \text{m}]}$

Here $c$ is the speed of light, $h$ is the Plank constant, $e$ is the elementary charge.

Valid wavelength range

Every material exposes the wavelength range over which its data are defined:

# Returns (min, max) in the requested unit
bk7.get_wl_range()            # e.g. (300.0, 2500.0)   nm
bk7.get_wl_range(unit='um')   # e.g. (0.3, 2.5)        µm
bk7.get_wl_range(unit='cm-1') # e.g. (4000.0, 33333.3) cm⁻¹

Result is always returned as (min, max).

Out-of-range behavior

No exception is raised for out-of-range wavelengths, but the returned value is not reliable:

Data type Out-of-range result
Tabulated (n, k, nk) nan
Formula (1–9) Silent extrapolation — may be unphysical, or nan with a RuntimeWarning if the formula evaluates a square root of a negative number

Always check get_wl_range() before querying if you are not certain the wavelength is within the measured range:

lo, hi = mat.get_wl_range()
if lo <= wavelength <= hi:
    n = mat.get_refractive_index(wavelength)
else:
    raise ValueError(f"wavelength {wavelength} nm is outside the valid range [{lo}, {hi}] nm")

Notes:

  • Here the time dependence is assumed to be $\mathrm{e}^{-\mathrm{i} \omega t}$, so $\mathrm{Im}(\varepsilon) > 0$ is responsible for the losses.
  • If there is a space in the name, write underscore instead, i.e. not page='Rodriguez-de Marcos' but page='Rodriguez-de_Marcos'.
  • All 9 dispersion formula types used by the refractiveindex.info database are supported: Sellmeier (1), Sellmeier-2 (2), Polynomial (3), RefractiveIndex.INFO (4), Cauchy (5), Gases (6), Herzberger (7), Retro (8), and Exotic (9).
  • The database is automatically downloaded on first use to ~/.refractiveindex.info-database.

How to get material page names

You can find the proper "page" name by hovering your cursor on the link in the Data section

How to get page name

Or you can look up folders in this repository
https://github.com/polyanskiy/refractiveindex.info-database

Similar projects

Possible problems

If the upstream database has changed its structure, upgrade the package

pip install --upgrade refractiveindex

and remove the database folder at ~/.refractiveindex.info-database.

TODO

  1. Include EODG data

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

refractiveindex-1.0.3.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

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

refractiveindex-1.0.3-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file refractiveindex-1.0.3.tar.gz.

File metadata

  • Download URL: refractiveindex-1.0.3.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for refractiveindex-1.0.3.tar.gz
Algorithm Hash digest
SHA256 da1ab15d412eab62b749d06921173e2d2ff42c32b343249326d7fbccd8312827
MD5 af1327c3117a765ec7127ca556ffdd60
BLAKE2b-256 2fe68b6332703ea41bbc585eb2bc731bd0b8c433144f3d72e87b7ad1e2d7a514

See more details on using hashes here.

Provenance

The following attestation bundles were made for refractiveindex-1.0.3.tar.gz:

Publisher: publish.yml on toftul/refractiveindex

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

File details

Details for the file refractiveindex-1.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for refractiveindex-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 76cc72392771140aa5e689763e911a907b8304bfd3f06f3394b097cbbbfe772e
MD5 3e607bb7e65bab92a847c300d4725370
BLAKE2b-256 588408a606874fae61e86aeccfea44dbb06e2a36fd2e05adb97f079bc3b98089

See more details on using hashes here.

Provenance

The following attestation bundles were made for refractiveindex-1.0.3-py3-none-any.whl:

Publisher: publish.yml on toftul/refractiveindex

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

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