Skip to content

Repository files navigation

PyOptik logo

MetaPythonDocumentation Status
TestingUnittest StatusUnittest coverage
PyPiPyPi versionPyPi version
AnacondaAnaconda versionAnaconda 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!

fromTypedUnitimporturegfromPyOptikimportMaterialBankbk7=MaterialBank.BK7n=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:

fromPyOptikimportMaterialBank# Get the most commonly used materialsMaterialBank.build_library('classics')
# See what's availableMaterialBank.print_materials()

Complete Setup - Download Everything:

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

Custom Selection:

# Download specific categoriesMaterialBank.build_library('glasses')
MaterialBank.build_library('metals')
# Or chain themforcategoryin ['classics', 'glasses', 'metals']:
MaterialBank.build_library(category)

Quick Start Guide

Basic Usage - Refractive Index

fromTypedUnitimporturegfromPyOptikimportMaterialBankimportnumpyasnp# Access BK7 glass propertiesbk7=MaterialBank.BK7# Single wavelength (550 nm)n=bk7.compute_refractive_index(550*ureg.nanometer)
print(f"BK7 refractive index at 550nm: {n:.4f}")
# Multiple wavelengthswavelengths=np.linspace(400, 800, 100) *ureg.nanometern_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 dispersionbk7.plot()
# Custom wavelength rangewavelengths=np.linspace(300, 2000, 500) *ureg.nanometerbk7.plot(wavelengths)

Detailed Example - Material Analysis

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

importnumpyasnpimportmatplotlib.pyplotaspltfromPyOptikimportMaterialBank# Define wavelength range (UV to Near-IR)wavelengths=np.linspace(200, 2500, 1000) *ureg.nanometer# Compare different materialsmaterials= {
'BK7 Glass': MaterialBank.BK7,
'Fused Silica': MaterialBank.fused_silica,
'Sapphire': MaterialBank.Al2O3
}
plt.figure(figsize=(12, 8))
forname, materialinmaterials.items():
# Calculate refractive index across spectrumn_values=material.compute_refractive_index(wavelengths)
# Plot dispersion curveplt.subplot(2, 2, 1)
plt.plot(wavelengths*1e9, n_values, label=name, linewidth=2)
# Group velocity dispersiongroup_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:

fromPyOptikimportMaterialBank, MaterialType# Add water at 19°C from RefractiveIndex.INFOMaterialBank.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 itwater=MaterialBank.water_19Cn_water=water.compute_refractive_index(589e-9) # Sodium D-line

Managing Your Library

# View all available materialsMaterialBank.print_materials()
# Remove unwanted materialsMaterialBank.remove_item(filename='water_19C')
# Check what's available after removalMaterialBank.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!

About

Python package to easily download refractive indexes from RefractiveIndex.INFO

Resources

Stars

6 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages