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.7

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.7.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.7-py3-none-any.whl (52.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyoptik-2.0.7.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.7.tar.gz
Algorithm Hash digest
SHA256 0614692a69f21e5242bf1b2493fbecd6b1e796b7270e8b4bd28a48296474097e
MD5 c3eb1afdf029a3242dfa871c61017b45
BLAKE2b-256 7bc42a28a698cff027d7c224883f9640a373765e0e99af9e2ecabcf64aaded4d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pyoptik-2.0.7-py3-none-any.whl
  • Upload date:
  • Size: 52.5 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.7-py3-none-any.whl
Algorithm Hash digest
SHA256 434cb7d33f6e7dfc65bee16fe2a6767870712251318930ff018f2e00f2f0b3f5
MD5 42dd535c1414d6ac7c2987dbeaab9d82
BLAKE2b-256 f06ffcdedf9b840d27181f0af56c8cf2b7b779a57b6d86ebcfa30bfb9f719c1a

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