Skip to main content

A package for refractive index values.

Project description

PyOptik logo

Meta

Python

Documentation Status

Testing

Unittest Status

Unittest coverage

PyPi

PyPi version

PyPi version

Anaconda

Anaconda version

Anaconda downloads

PyOptik: Optical Material Properties Made Simple

PyOptik is a powerful Python library that provides seamless access to optical material properties from the comprehensive RefractiveIndex.INFO database. Whether you’re simulating light-matter interactions, designing optical systems, or conducting photonics research, PyOptik delivers the refractive index and extinction coefficient data you need with a clean, intuitive API.

Quick Start: Get material properties in just 3 lines of code!

from TypedUnit import ureg
from PyOptik import MaterialBank

bk7 = MaterialBank.BK7
n = bk7.compute_refractive_index(550 * ureg.nanometer)  # n ≈ 1.519

Key Features

Comprehensive Material Database

Access thousands of materials from RefractiveIndex.INFO with automatic data management

Multiple Data Formats

Support for both Sellmeier equation materials and tabulated wavelength data

High-Performance Computing

Optimized calculations for group index, group velocity, and dispersion properties

Simulation Ready

Perfect for optical design, photonics simulations, and electromagnetic modeling

Developer Friendly

Clean API that integrates seamlessly with NumPy, Matplotlib, and scientific Python stack

Advanced Analysis

Built-in plotting and visualization tools powered by MPSPlots

Installation

Quick Install

pip install PyOptik

Conda Install

conda install -c martinpdes pyoptik

Development Install

git clone https://github.com/MartinPdeS/PyOptik.git
cd PyOptik
pip install -e .

Building Your Material Library

PyOptik downloads material data from RefractiveIndex.INFO organized into categories. Choose what you need or download everything at once.

Available Categories:

classics - Essential optical materials (BK7, fused silica, etc.) glasses - Various optical glasses metals - Metallic materials (gold, silver, aluminum, etc.) organics - Organic and polymer materials others - Specialized and exotic materials all - Everything (recommended for comprehensive access)

Quick Setup - Download Essentials:

from PyOptik import MaterialBank

# Get the most commonly used materials
MaterialBank.build_library('classics')

# See what's available
MaterialBank.print_materials()

Complete Setup - Download Everything:

# Download all materials (recommended)
MaterialBank.build_library('all', remove_previous=True)

Custom Selection:

# Download specific categories
MaterialBank.build_library('glasses')
MaterialBank.build_library('metals')

# Or chain them
for category in ['classics', 'glasses', 'metals']:
    MaterialBank.build_library(category)

Quick Start Guide

Basic Usage - Refractive Index

from TypedUnit import ureg
from PyOptik import MaterialBank
import numpy as np

# Access BK7 glass properties
bk7 = MaterialBank.BK7

# Single wavelength (550 nm)
n = bk7.compute_refractive_index(550 * ureg.nanometer)
print(f"BK7 refractive index at 550nm: {n:.4f}")

# Multiple wavelengths
wavelengths = np.linspace(400, 800, 100) * ureg.nanometer
n_values = bk7.compute_refractive_index(wavelengths)

Advanced Properties - Group Index & Velocity

# Group index (important for pulse propagation)
n_g = bk7.compute_group_index(550 * ureg.nanometer)

# Group velocity (speed of pulse envelope)
v_g = bk7.compute_group_velocity(550 * ureg.nanometer)

print(f"Group index: {n_g:.4f}")
print(f"Group velocity: {v_g:.2e} m/s")

Visualization

# Quick plot of material dispersion
bk7.plot()

# Custom wavelength range
wavelengths = np.linspace(300, 2000, 500) * ureg.nanometer
bk7.plot(wavelengths)

Detailed Example - Material Analysis

Here’s a comprehensive example showing PyOptik’s capabilities:

import numpy as np
import matplotlib.pyplot as plt
from PyOptik import MaterialBank

# Define wavelength range (UV to Near-IR)
wavelengths = np.linspace(200, 2500, 1000) * ureg.nanometer

# Compare different materials
materials = {
    'BK7 Glass': MaterialBank.BK7,
    'Fused Silica': MaterialBank.fused_silica,
    'Sapphire': MaterialBank.Al2O3
}

plt.figure(figsize=(12, 8))

for name, material in materials.items():
    # Calculate refractive index across spectrum
    n_values = material.compute_refractive_index(wavelengths)

    # Plot dispersion curve
    plt.subplot(2, 2, 1)
    plt.plot(wavelengths*1e9, n_values, label=name, linewidth=2)

    # Group velocity dispersion
    group_indices = material.compute_group_index(wavelengths)
    plt.subplot(2, 2, 2)
    plt.plot(wavelengths*1e9, group_indices, label=name, linewidth=2)

plt.subplot(2, 2, 1)
plt.xlabel('Wavelength (nm)')
plt.ylabel('Refractive Index')
plt.title('Material Dispersion Comparison')
plt.legend()
plt.grid(True, alpha=0.3)

plt.subplot(2, 2, 2)
plt.xlabel('Wavelength (nm)')
plt.ylabel('Group Index')
plt.title('Group Index Comparison')
plt.legend()
plt.grid(True, alpha=0.3)

plt.tight_layout()
plt.show()

Output: PyOptik example: BK7

This example demonstrates PyOptik’s power for comparative material analysis and optical design.

Advanced Usage - Custom Materials

Adding Materials from RefractiveIndex.INFO

Easily extend your library with materials from the web:

from PyOptik import MaterialBank, MaterialType

# Add water at 19°C from RefractiveIndex.INFO
MaterialBank.add_material_to_bank(
    filename='water_19C',
    material_type=MaterialType.SELLMEIER,
    url='https://refractiveindex.info/database/data-nk/main/H2O/Daimon-19.0C.yml'
)

# Now you can use it
water = MaterialBank.water_19C
n_water = water.compute_refractive_index(589e-9)  # Sodium D-line

Managing Your Library

# View all available materials
MaterialBank.print_materials()

# Remove unwanted materials
MaterialBank.remove_item(filename='water_19C')

# Check what's available after removal
MaterialBank.print_available()

Material Types

PyOptik supports two material data formats:

Sellmeier Materials: Mathematical dispersion formulas (compact, smooth) Tabulated Materials: Discrete wavelength-index pairs (experimental data)

Development & Testing

Running Tests

# Clone and setup
git clone https://github.com/MartinPdeS/PyOptik.git
cd PyOptik
pip install -e ".[testing]"

# Run test suite
pytest

# Run with coverage
pytest --cov=PyOptik --cov-report=html

Code Quality

# Linting
flake8 PyOptik/

# Type checking (if using mypy)
mypy PyOptik/

Contributing

We welcome contributions! PyOptik thrives on community input:

Bug Reports: Found an issue? Open an issue on GitHub Feature Requests: Have ideas? We’d love to hear them Documentation: Help improve our docs and examples Code: Submit pull requests for fixes and enhancements

Development Workflow:

  1. Fork the repository

  2. Create a feature branch: git checkout -b feature-name

  3. Make your changes and add tests

  4. Run the test suite: pytest

  5. Submit a pull request

Contact & Support

Author: Martin Poinsinet de Sivry-Houle

Email: martin.poinsinet.de.sivry@gmail.com

GitHub: PyOptik Repository

Documentation: Full Documentation

PyOptik is actively developed and maintained. We’re always looking for collaborators interested in optical simulation and materials science!

Project details


Release history Release notifications | RSS feed

This version

2.0.6

Download files

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

Source Distribution

pyoptik-2.0.6.tar.gz (1.4 MB view details)

Uploaded Source

Built Distribution

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

pyoptik-2.0.6-py3-none-any.whl (86.8 kB view details)

Uploaded Python 3

File details

Details for the file pyoptik-2.0.6.tar.gz.

File metadata

  • Download URL: pyoptik-2.0.6.tar.gz
  • Upload date:
  • Size: 1.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for pyoptik-2.0.6.tar.gz
Algorithm Hash digest
SHA256 81d3faa6acbd64d4d489e78e2de1420a3e2daac47670760e3ee378387a6927ce
MD5 5699bb3561e2f62cf5bbac3e986c7fc7
BLAKE2b-256 7e03117a1edc3280f93d19561e9feb984e8e7ead8fec6ab822a58a538ffe009c

See more details on using hashes here.

File details

Details for the file pyoptik-2.0.6-py3-none-any.whl.

File metadata

  • Download URL: pyoptik-2.0.6-py3-none-any.whl
  • Upload date:
  • Size: 86.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for pyoptik-2.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 c1fc04a9e7ada9583a477deb2cf5d5aaae5db537c614998bc2b90c6b4c9fda7d
MD5 689015629906a472eddefa9480e8bc11
BLAKE2b-256 30ee0ef2c90efef7bc4104acee6fc7e27f48cce8fd0bd1522ca0e9c01e222824

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