Developer’s Guide

Module contents

Common interface for sources of optical material data

OpticalGlass provides a common API to a number of different optical material data sources. These include

  • interfaces to vendor supplied Excel spreadsheets with glass data.

  • ability to import material files in the Zemax .agf data format.

  • ability to import material data from the RefractiveIndex.INFO database.

These and other sources of data are organized into libraries. Each library contains one or more catalogs, and each catalog contains one or more glasses. The glass catalog of particular vendors (e.g. Hoya, Ohara, Schott) will be found in multiple libraries. The user can control the order in which the libraries are searched, as well as the order of the catalogs available from each library.

The global variable og_glass_libs is an instance of the CentralGlassLibrary class that contains the various libraries and catalogs.

OpticalGlass currently supports glass spreadsheets fromthe following vendors:

  • CDGM

  • Hikari

  • Hoya

  • Ohara

  • Schott

  • Sumita

The spreadsheets from the vendors are in the data directory. They are imported using pandas into DataFrame instances, one per catalog. The data in the catalog DataFrame is used unchanged from the import; only the data headers are modified for consistency across catalogs. The create_glass() function returns a OpticalMedium object, given the glass and catalog names.

An interface to the RefractiveIndex.INFO database is provided by the rindexinfo module.

A set of legacy catalogs, circa 1980, is available via the Robb1983Catalog class. The data used by this class is from the 1983 paper by Paul N. Robb and R. I. Mercado, Calculation of refractive indices using Buchdahl’s chromatic coordinate . The catalogs include:

  • Hoya

  • Ohara

  • Schott

  • Chance

  • Corning-France

The authors fitted a Buchdahl quadratic model to the glass data that has a standard deviation of 0.00002 and a maximum absolute error of 0.0001 in the visible spectral region.

Fitting and modeling glass data using the Buchdahl chromatic coordinate is supported in the buchdahl module.

Submodules

glasslibs

Interfaces for optical material data sources, catalogs, and libraries.

The glasslibs module defines the GlassLibrary and GlassCatalog classes, which provide a common interface for accessing optical glass data from various sources. The GlassLibrary class represents a collection of glass catalogs and other libraries, while the GlassCatalog class represents a specific catalog of optical glasses.

class GlassCatalogBase

Bases: object

Prototype for a glass catalog.

A GlassCatalogBase defines the interface for a glass catalog, which is a collection of optical glasses. Subclasses should mix in the Mapping protocol to provide dictionary-like access to the glasses in the catalog. Immutable mappings are used for vendor catalogs and other imported datasets. MutableMapping can be used for user constructed catalogs or other types of grouping, e.g. plastics or IR materials.

The create_glass method will return a subclass of OpticalMedium for the input glass name. The [] access will return either an OpticalMedium subclass or data directly related to the data source.

The glass_map_data method will return arrays of index and dispersion data for all glasses in the catalog for a specified wavelength range. This is used to facilitate glass map displays.

abstractmethod create_glass(gname: str) OpticalMedium

Create an instance of the glass gname.

abstractmethod glass_map_data(wvl='d', **kwargs)

return index and dispersion data for all glasses in the catalog

Parameters:

wvl (str) – the central wavelength for the data, either ‘d’ or ‘e’

Returns:

index, V-number, partial dispersion, Buchdahl coefficients, and glass names

class GlassLibrary(name: str, lib: dict[str, Any], search_order: list[str], *active_cltns: list[str])

Bases: MutableMapping

A collection of libraries or catalogs.

This class acts like a dictionary of libraries or catalogs. Each entry in the GlassLibrary is accessed using its name as the key. The library maintains a search order for the mapped items that is used when looking for a catalog or glass. A GlassLibrary supports iteration and uses the search order when iterating over its contents. Libraries or catalogs can be excluded from the search by changing their active_state to False. The library can contain any number of nested libraries and catalogs, and the search will be performed recursively through the nested structure.

The find_path_to_glass() method can be used to find all paths to a specific glass in the library, and the find_catalog() method can be used to find all occurrences of a specific catalog in the library.

Parameters:
  • name (str) – the name of the library

  • lib (dict[str, Any]) – a dictionary of libraries or catalogs

  • search_order (list[str]) – the order used when iterating over the contents of the library

  • active_cltns (list[str]) – an optional list of library or catalog names that are active, i.e. included in the search. All items are active by default.

name

the name of the library

Type:

str

active_state

a dictionary of the entries in this library where the value is whether an entry is active or not, Only active entries are included when iterating over the library.

Type:

dict[str, bool]

search_order

the order used when iterating over the contents of the library. The search order can omit entries in the library.

Type:

list[str]

property active_cltns: list[str]

list of the active entries in the library.

find_path_to_glass(gname) list[list[str]]

find all occurances of the path to the glass gname

Parameters:

gname (str) – the glass name to find

Returns:

list of paths to the glass as a list of library/catalog names

Return type:

list[list[str]]

find_catalog(cat_name: str) list[tuple[GlassCatalogBase, list[str]]]

find all occurences of cat_name in the library

Parameters:

cat_name (str) – the glass catalog to find

Returns:

list of tuples consisting of a GlassCatalog and the path to the catalog as a list of library/catalog names

Return type:

list[tuple[GlassCatalogBase, list[str]]]

class GlassCatalog(catalog_name: str, catalog: dict[str, OpticalMedium])

Bases: MutableMapping, GlassCatalogBase

A collection of OpticalMedium

This is the basic implementation of the GlassCatalogBase protocol.

name

the name of the catalog

Type:

str

catalog

a dict of OpticalMedium keyed by glass name

Type:

dict[str, OpticalMedium]

In this implementation, the [] operator and the create_glass() method return the same thing, an OpticalMedium instance for the input glass name.

This collection is mutable, so glasses can be added, removed, or modified using the [] operator.

create_glass(gname: str) OpticalMedium

Create an instance of the glass gname.

glass_map_data(wvl='d', **kwargs)

return index and dispersion data for all glasses in the catalog

Parameters:

wvl (str) – the central wavelength for the data, either ‘d’ or ‘e’

Returns:

index, V-number, partial dispersion, Buchdahl coefficients, and glass names

calc_glass_map_arrays(glasses: list[OpticalMedium], d_str, F_str, C_str, **kwargs)

return index and dispersion data arrays for input spectral range

Parameters:
  • glasses (list) – input list of glass instances

  • nd_str (str) – central wavelength string

  • nf_str (str) – blue end wavelength string

  • nc_str (str) – red end wavelength string

  • partials (tuple) – kwarg if present, 2 wvls, wl4 and wl5, wl4 < wl5

Returns:

index, V-number, partial dispersion, Buchdahl coefficients, and glass names

glassfactory

Factory interface and central library for optical glass catalogs

The glassfactory module is intended to be the primary method by which glass instances are created. The create_glass() is the public factory function for this purpose.

OpticalGlass provides a common API to a number of different optical material data sources. These include

  • interfaces to vendor supplied Excel spreadsheets with glass data.

  • ability to import material files in the Zemax .agf data format.

  • ability to import material data from the RefractiveIndex.INFO database.

These and other sources of data are organized into libraries. Each library contains one or more catalogs, and each catalog contains one or more glasses. The glass catalog of particular vendors (e.g. Hoya, Ohara, Schott) will be found in multiple libraries. The user can control the order in which the libraries are searched, as well as the order of the catalogs available from each library.

The global variable og_glass_libs is an instance of the CentralGlassLibrary class that contains the various libraries and catalogs.

Users may utilize the custom glass collection by using the register_glass() function. Glasses, specified by name and catalog name, can be used in the create_glass function. The collection may be saved and restored via a json file.

create_glass(*name_catalog) OpticalMedium

Factory function returning a catalog glass instance.

The create_glass function searches the libraries and catalogs for the specified glass name and catalog, and returns an instance of the glass if found. If the glass is not found, a GlassNotFoundError is raised. If the catalog is not found, a GlassCatalogNotFoundError is raised.

The input argument list can take several forms:

  • a single string argument will be split based on ‘,’ to separate the glass name, catalog and library. For example, “N-BK7,Schott,xls” would specify the glass “N-BK7” in the “Schott” catalog in the vendor ‘xls’ library.

The output of the split will be processed as follows:
  • 1 string argument: glass_name

  • 2 string arguments: glass_name, catalog_name

  • 3 string arguments: glass_name, catalog_name, library.

If 2 arguments are used and the catalog is “rindexinfo”, the “name” field is taken as a URL or filepath to a material in the RefractiveIndex.INFO database.

Parameters:

*name_catalog – tuple of 1, 2 or 3 input items

Raises:
libraries = ['user', 'xls', 'agf', 'rii', 'robb']

list of library names to be included in the central glass library. The order of the libraries in this list determines the search order when looking for glasses.

class CentralGlassLibrary(search_order: list[str] | None = None)

Bases: GlassLibrary

Instantiates the libraries list to create the central library, og_glass_libs.

og_glass_libs: CentralGlassLibrary = <opticalglass.glassfactory.CentralGlassLibrary object>

The CentralGlassLibrary instance containing the various glass libraries and catalogs

list_custom_glasses()

Lists the glasses registered in the custom glasses dict.

register_glass(medium: OpticalMedium)

Registers a custom optical glass medium in the internal registry.

This function adds a user-defined OpticalMedium instance to the custom glass registry, allowing it to be referenced and used elsewhere in the application. The medium is indexed by a tuple of its name and catalog name. If the catalog name is new, it is also added to the list of known catalog names (both in original and uppercase forms).

Parameters:

medium (OpticalMedium) – The optical medium instance to register. Must be an instance of the OpticalMedium class, and have a valid name and catalog_name.

Raises:

TypeError – If medium is not an instance of OpticalMedium.

Side Effects:
  • Updates the _custom_glass_registry dictionary with the new medium.

Example

>>> custom_medium = OpticalMedium(name="MyGlass", catalog_name="CustomCat", ...)
>>> register_glass(custom_medium)
>>> # Now `custom_medium` can be accessed via name and catalog
>>> glass = create_glass("MyGlass,CustomCat")
class CustomGlassCatalog(catalog_name: str, catalog: dict[str, Any])

Bases: GlassCatalogBase

catalog_name()
create_glass(gname: str) OpticalMedium | None

Create an instance of the glass gname.

glass_map_data(wvl='d', **kwargs)

return index and dispersion data for all glasses in the catalog

Parameters:

wvl (str) – the central wavelength for the data, either ‘d’ or ‘e’

Returns:

index, V-number, partial dispersion, Buchdahl coefficients, and glass names

save_custom_glasses(dirname: str | Path)

Save the custom glasses to the specified directory.

load_custom_glasses(dirname: str | Path)

Load custom glasses from the specified directory.

opticalmedium

Module for simple optical media definitions

glass_encode(n: float, v: float) str

encode index and v-number as a 6 digit code.

Example:

In [1]: glass_encode(1.517, 64.2)
Out[1]: '517.642'

In [2]: glass_encode(1.5168, 64.17)
Out[2]: '517.642'
glass_decode(gc: str) tuple[float, float]

decode a 6 digit code into index and v-number.

Example:

In [1]: gc = glass_decode('517.642'); gc
Out[1]: (1.517, 64.2)
class OpticalMedium(*args, **kwargs)

Bases: Protocol

Protocol for media with optical properties, e.g. refractive index.

abstractmethod name() str
abstractmethod catalog_name() str
abstractmethod calc_rindex(wv_nm: float | NDArray) float | NDArray

returns the interpolated refractive index at wv_nm

Parameters:

wv_nm (float or numpy array) – wavelength in nm for the refractive index query

Returns:

the refractive index at wv_nm

Return type:

float or numpy array

abstractmethod get_wl_range() tuple[float, float]

returns the wavelength range in nm for the medium definition

Returns:

(min_wavelength_nm, max_wavelength_nm)

Return type:

tuple

within_wl_range(wvl: float | str) bool

returns True if wvl is within the wavelength range for the medium definition

abstractmethod meas_rindex(wvl: str) float

returns the measured refractive index at wvl

Parameters:

wvl – a string with a spectral line identifier

Returns:

the refractive index at wvl

Return type:

float

Raises:

KeyError – if wvl is not in the spectra dictionary

rindex(wvl: float | str) float

returns the interpolated refractive index at wvl

Parameters:

wvl – either the wavelength in nm or a string with a spectral line identifier. for the refractive index query

Returns:

the refractive index at wv_nm

Return type:

float

Raises:

KeyError – if wvl is not in the spectra dictionary

transmission_data(thi: float) tuple[NDArray, NDArray]

returns an array of transmission data for the glass

The default implementation returns unit transmittance over the wavelength range given by get_wl_range()

Parameters:

thi – the sample thickness in mm for the transmittance data

Returns:

tuple of Numpy arrays of wavelength and transmittance

class Air(*args, **kwargs)

Bases: OpticalMedium

Optical definition for air (low fidelity definition)

name() str
catalog_name() str
calc_rindex(wv_nm: float | NDArray) float | NDArray

returns the interpolated refractive index at wv_nm

Parameters:

wv_nm (float or numpy array) – wavelength in nm for the refractive index query

Returns:

the refractive index at wv_nm

Return type:

float or numpy array

meas_rindex(wvl: str) float

returns the measured refractive index at wvl

Parameters:

wvl – a string with a spectral line identifier

Returns:

the refractive index at wvl

Return type:

float

Raises:

KeyError – if wvl is not in the spectra dictionary

rindex(wvl: str) float

returns the interpolated refractive index at wvl

Parameters:

wvl – either the wavelength in nm or a string with a spectral line identifier. for the refractive index query

Returns:

the refractive index at wv_nm

Return type:

float

Raises:

KeyError – if wvl is not in the spectra dictionary

get_wl_range() tuple[float, float]

returns the wavelength range in nm for the medium definition

class ConstantIndex(nd, lbl, cat='')

Bases: OpticalMedium

Constant refractive index medium.

name()
catalog_name()
calc_rindex(wv_nm_)

returns the interpolated refractive index at wv_nm

Parameters:

wv_nm (float or numpy array) – wavelength in nm for the refractive index query

Returns:

the refractive index at wv_nm

Return type:

float or numpy array

meas_rindex(wvl)

returns the measured refractive index at wvl

Parameters:

wvl – a string with a spectral line identifier

Returns:

the refractive index at wvl

Return type:

float

Raises:

KeyError – if wvl is not in the spectra dictionary

get_wl_range() tuple[float, float]

returns the wavelength range in nm for the medium definition

class InterpolatedMedium(label, pairs=None, wvls=None, rndx=None, kvals=None, kvals_wvls=None, cat='')

Bases: OpticalMedium

Optical medium defined by a list of wavelength/index pairs

label

required string identifier for the material

wvls

list of wavelengths in nm, used as x axis

rndx

list of refractive indices corresponding to the values in wvls

kvals_wvls

list of wavelengths in nm, used as x axis

kvals

list of absorption coefficents corresponding to the values in kvals_wvls

rindex_interp

the refractive index interpolation function

kvals_interp

the kval interpolation function

sync_to_restore() None

rebuild interpolating function

update() None
glass_code() str
name() str
catalog_name() str

returns the glass catalog name

calc_rindex(wv_nm: float | NDArray) float | NDArray

returns the interpolated refractive index at wv_nm

get_wl_range() tuple[float, float]

returns the wavelength range in nm for the medium definition

meas_rindex(wvl: str) float

returns the measured refractive index at wvl

For InterpolatedMedium the measured index isn’t directly known. The calculated index is used instead. Calling rindex handles the spectral line conversion.

transmission_data(thi=10.0)

returns an array of transmission data for the glass

The default implementation returns unit transmittance over the wavelength range given by get_wl_range()

Parameters:

thi – the sample thickness in mm for the transmittance data

Returns:

tuple of Numpy arrays of wavelength and transmittance

modelglass

Module for optical glass models based on index/v-number

model_from_glasses(gla1, gla2)

Create a model from the slope between two glasses.

class ModelGlass(nd: float, vd: float, mat: str, cat: str = 'user')

Bases: OpticalMedium

Optical medium defined by a glass code, i.e. index - V number pair

sync_to_restore()
glass_code()
name()
catalog_name()
calc_rindex(wv_nm)

returns the interpolated refractive index at wv_nm

Parameters:

wv_nm (float or numpy array) – wavelength in nm for the refractive index query

Returns:

the refractive index at wv_nm

Return type:

float or numpy array

get_wl_range() tuple[float, float]

returns the wavelength range in nm for the medium definition

meas_rindex(wvl)

returns the measured refractive index at wvl

Parameters:

wvl – a string with a spectral line identifier

Returns:

the refractive index at wvl

Return type:

float

Raises:

KeyError – if wvl is not in the spectra dictionary

update(nd, vd)

buchdahl

Buchdahl chromatic coordinate modeling and support

get_wv(wavelength)

Return the wavelength in micrometers.

omega(delta_lambda)

Calculate the Buchdahl chromatic coordinate.

omega2wvl(om)
calc_buchdahl_coords(nd, nF, nC, wlns=('d', 'F', 'C'), ctype=None, **kwargs)

Given central, blue and red refractive indices, calculate the Buchdahl chromatic coefficients.

Parameters:
  • nd – central refractive index

  • nF – “blue” refractive index

  • nC – “red” refractive index

  • wlns – wavelengths for the 3 refractive indices

  • ctype – if “disp_coefs”, return dispersion coefficients, otherwise the quadratic coefficients

fit_buchdahl_coords(indices, degree=2, wlns=['d', 'h', 'g', 'F', 'e', 'C', 'r'])

Given central, 4 blue and 2 red refractive indices, do a least squares fit for the Buchdahl chromatic coefficients.

class Buchdahl(wv0, rind0, coefs, mat='', cat='')

Bases: OpticalMedium

Quadratic Buchdahl refractive index model.

\[N(\omega) = {N_0} + \nu_1\omega + \nu_2\omega^2\]
  • \(\omega\) is the Buchdahl chromatic coordinate for the input wavelength

  • \(\nu_1, \nu_2\) are the linear and quadratic coefficients of the model

  • \({N_0}\) is the refractive index at the central wavelength of the fit

The Buchdahl chromatic coordinate \(\omega\) is defined as:

\[\omega(\lambda) = \frac{\lambda - \lambda_0}{1 + 5/2(\lambda - \lambda_0)}\]
name()
catalog_name()
glass_code()
rindex(wvl)

Returns the refractive index from the quadratic model at wvl.

get_wl_range()

returns the wavelength range in nm for the medium definition

meas_rindex(wvl: str) float

returns the measured refractive index at wvl

Parameters:

wvl – a string with a spectral line identifier

Returns:

the refractive index at wvl

Return type:

float

Raises:

KeyError – if wvl is not in the spectra dictionary

calc_rindex(wv_nm)

returns the interpolated refractive index at wv_nm

Parameters:

wv_nm (float or numpy array) – wavelength in nm for the refractive index query

Returns:

the refractive index at wv_nm

Return type:

float or numpy array

transmission_data(thi: float)

returns an array of transmission data for the glass

The default implementation returns unit transmittance over the wavelength range given by get_wl_range()

Parameters:

thi – the sample thickness in mm for the transmittance data

Returns:

tuple of Numpy arrays of wavelength and transmittance

class Buchdahl1(medium, wlns=('d', 'F', 'C'), **kwargs)

Bases: Buchdahl

Quadratic refractive index model for a real glass, medium.

update(rindx)
class Buchdahl2(nd, vd, model=None, wlns=('d', 'F', 'C'), **kwargs)

Bases: Buchdahl

Quadratic refractive index model for a 6-digit glass specification.

b = -0.064667
m = -1.604048
update(nd, vd)
update_model(nd, vd)

xls_glass

Support for spreadsheet glass catalogs

A common way for optical glass manufacturers to supply detailed technical data for each glass is via spreadsheets. The format of these spreadsheets is similar but different in the details. The GlassCatalogPandas class and related functions provide a means of mapping the spreadsheet contents into a pandas DataFrame. A requirement for the import process is that the spreadsheet data be copied untouched into the catalog DataFrame. Only the spreadsheet row and column headers are changed in creating the catalog DataFrame. Some data categories are relabeled to take advantage of commonalities across catalogs. The GlassCatalogPandas.df attribute has the catalog DataFrame.

The GlassCatalogPandas class implements the GlassCatalogBase interface, as well as providing access to data beyond the refractive index and transmission data provided by the OpticalMedium interface. The catalog-specific subclasses of GlassCatalogPandas provide specific mapping information for the vendor spreadsheet format.

The GlassPandas class implements the OpticalMedium interface for the data of a particular glass in a catalog. The GlassPandas base class manages the generic operations on the individual glass instances. These include refractive index interpolation using either the calc_rindex() or the rindex() methods. The meas_rindex() method, with a spectral line argument, e.g. ‘d’, ‘F’, ‘C’, will return the measured index data from the catalog. The transmission_data() method returns transmission data (10mm sample thickness) for the glass instance.

A factory interface to OpticalMedium creation is the function create_glass() that returns a OpticalMedium instance of the appropriate catalog type, given the glass and catalog names.

get_filepath(fname)

given a (spreadsheet) file name, return a complete Path to the file

The data files included with the opticalglass package are located in a data directory in the package hierarchy.

opticalglass/
    opticalglass/
        data/
            fname
Parameters:

fname (str) – the spreadsheet filename, including extender

Returns:

full path including filename for requested spreadsheet

Return type:

str

get_glass_map_arrays(cat, d_str, F_str, C_str, **kwargs)

return index and dispersion data arrays for input spectral range

Parameters:
  • cat – glass catalog instance, source for returned data

  • d_str (str) – central wavelength string

  • F_str (str) – blue end wavelength string

  • C_str (str) – red end wavelength string

  • partials (tuple) – kwarg if present, 2 wvls, wl4 and wl5, wl4 < wl5

Returns:

index, V-number, partial dispersion, Buchdahl coefficients, and glass names

get_xls_lib(cat_list: list[str] | None = None) GlassLibrary

return a GlassLibrary of the catalogs in cat_list.

Parameters:
  • cat_list – list of catalog names to include in the library. If None,

  • included. (all catalogs in _cat_namesare)

Returns:

GlassLibrary of the catalogs in cat_list.

glass_catalog_factory(cat_name, mod_name=None, cls_name=None)

Function returning a glass catalog instance.

Parameters:
  • catalog – name of supported catalog (CDGM, Hoya, Ohara, Schott)

  • mod_name – the module name of the glass catalog

  • cls_name – the class name of the glass catalog

Raises:

GlassCatalogNotFoundError – if catalog isn’t found

xl_cols() list[str]

Generate Excel column labels, A thru ZZ.

xl2df(file_name: str) DataFrame

Read Excel file_name into a dataframe and apply Excel column names.

build_glass_cat(xl_df, series_mappings, item_mappings, *args, **kwargs) DataFrame

Apply series and item mappings to xl_df, and return catalog df.

class PandasMappingDef(catalog_name: str, file_name: str, series_mappings: list[tuple[str, Optional[Callable], int, str, str]], item_mappings: list[tuple[str, str, int, str]], args: tuple[int, int, int, str], kwargs: dict)

Bases: object

catalog_name: str
file_name: str
series_mappings: list[tuple[str, Callable | None, int, str, str]]
item_mappings: list[tuple[str, str, int, str]]
args: tuple[int, int, int, str]
kwargs: dict
xls_to_df(pmd: PandasMappingDef) DataFrame

Read Excel file_name into a dataframe and apply series and item mappings.

class GlassCatalogPandas(pmd: PandasMappingDef)

Bases: GlassCatalogBase, Mapping

Pandas-based glass catalog

Optical glass manufacturers have settled on Excel spreadsheets as a means of documenting the technical details of their glass products. The formats are broadly similar but different in the details. This class and related functions provide a means of mapping the Excel data into a pandas dataframe that has some categories relabeled to take advantage of commonalities.

The class is adapted to a specific catalog by defining the position and size of the data areas in the original Excel spreadsheet. Pandas is used to read the spreadsheet into a dataframe, xl_df. xl_df has indices and columns that match the Excel worksheet border.

  • the index runs from 1 to xl_df.shape[0]

  • the columns match the pattern ‘A’, ‘B’, ‘C’, … ‘Z’, ‘AA’, ‘AB’, …

This facilitates transferring areas on the spreadsheet to areas in the catalog DataFrame.

Manufacturers spreadsheets have a header area and a data area. First, a set of parameters are defined for the header. Data that are spread over multiple columns form a category, often readily identified in the spreadsheet layout.

num_rows = 2  # number of header rows in the imported spreadsheet
category_row = 1  # row with categories
header_row = 2  # row with data item/header info
data_col = 'B'  # first column of data in the imported spreadsheet
args = num_rows, category_row , header_row, data_col

The location of the different categories in the spreadsheet is defined in the series_mapping list.

series_mappings = [
    ('refractive indices', (lambda h: h.split('n')[-1]),
     category_row, 'C', 'P'),
    ('dispersion coefficients', None, category_row, 'V', 'AA'),
    ('internal transmission mm, 10', None, header_row, 'DC', 'EK'),
    ('chemical properties', None, category_row, 'AW', 'BA'),
    ('thermal properties', None, category_row, 'BB', 'BI'),
    ('mechanical properties', None, category_row, 'BJ', 'BO'),
    ]

There are common items of interest, that correspond to a single column. These are defined in the item_mappings list.

item_mappings = [
    ('refractive indices', 'C', header_row, 'F'),
    ('refractive indices', "C'", header_row, 'G'),
    ('abbe number', 'vd', header_row, 'R'),
    ('abbe number', 've', header_row, 'S'),
    ('specific gravity', 'd', header_row, 'BP'),
    ]
kwargs = dict(
    data_extent = (3, 242, data_col, 'FZ'),
    name_col_offset = 'A',
    )
name

the glass catalog name

pmd

the PandasMappingDef instance defining the mapping of the Excel data to the catalog DataFrame

df

the DataFrame containing the catalog data

glass_list
glass_lookup
abstractmethod create_glass(gname: str) OpticalMedium

Create an instance of the glass gname.

Must be implemented by the subclasses.

catalog_name()
get_glass_names()

returns a list of glass names

get_column_names()

returns a list of column headers

glass_index(gname)

returns the glass index (row) for glass name gname

Parameters:

gname (str) – glass name

Returns:

the 0-based index (row) of the requested glass

Return type:

int

data_index(dname)

returns the data index (column) for data dname

Parameters:

dname (str) – header string for data

Returns:

the 1-based index (column) of the requested data

Return type:

int

Raises:

GlassDataNotFoundError – if dname doesn’t match any header string

get_data_for_glass(gname, dindex=None, num=None)

returns an array of glass data for the glass at gname

Parameters:
  • gname – glass index into spreadsheet

  • dindex – the starting column of the desired data

  • num – number of data items (cells) to retrieve

Returns: list of data items

glass_data(gindex)

returns an array of data for the glass at gindex

glass_coefs(gname)

returns an array of glass coefficients for the glass at gname

catalog_data(dindex)

returns an array of data at column dindex for all glasses

transmission_data(gname)

returns an array of transmission data for the glass at gindex

Parameters:

gname – glass name

Returns:

list of wavelength, transmittance pairs

glass_map_data(wvl='d', **kwargs)

return index and dispersion data for all glasses in the catalog

Parameters:

wvl (str) – the central wavelength for the data, either ‘d’ or ‘e’

Returns:

index, V-number, partial dispersion, Buchdahl coefficients, and glass names

class GlassPandas(gname)

Bases: OpticalMedium

base optical glass, for use with pandas

gname

the glass name

catalog

the GlassCatalog this glass is associated with. Must be provided by the derived class

coefs

list of coefficients for calculating refractive index vs wv

sync_to_restore()

hook routine to restore coefs, if needed

initialize_catalog()

subclass initialization of glass catalog instance, as needed.

glass_code(d_str='d', vd_str='vd')

returns the 6 digit glass code, combining index and V-number

glass_data()

returns the raw spreadsheet data for the glass as a Series

name()

returns the glass name

catalog_name()

returns the glass catalog name

get_wl_range()

returns the wavelength range in nm for the medium definition

meas_rindex(wvl)

returns the measured refractive index at wvl

Parameters:

wvl – a string with a spectral line identifier

Returns:

the refractive index at wvl

Return type:

float

Raises:

KeyError – if wvl is not in the spectra dictionary

calc_rindex(wv_nm: float | NDArray) float | NDArray

returns the interpolated refractive index at wv_nm

Must be provided by the derived class

Parameters:

wv_nm (float or numpy array) – wavelength in nm for the refractive index query

Returns:

the refractive index at wv_nm

Return type:

float or numpy array

transmission_data(meas_thi: str = 'internal transmission mm, 10')

returns an array of transmission data for the glass

Returns: np.arrays of wavelength and transmission for 10mm sample

glass_catalog_stats(glass_list, do_print=False)

Decode all of the glass names in glass_cat_name.

Print out the original glass names and the decoded version side by side.

Parameters:
  • glass_list – list[tuple[DecodedGlassName, str, str, str]] (DecodedGlassName, glass_name, glass_cat_name, glass_lib_name)

  • do_print (bool) – if True, print the glass name and the decoded version

Returns:

all catalog groups group_num (dict): all glasses with multiple variants prefixes (dict): all the non-null prefixes used suffixes (dict): all the non-null suffixes used

Return type:

groups (dict)

get_robb_lib(fname='robb1983_data_final.txt') GlassLibrary
class RobbCatalog(catalog_name: str, catalog: dict[str, Any])

Bases: GlassCatalogBase

glass catalog based on data in Robb, et als 1983 paper on Buchdahl’s chromatic coordinate

The data used by this class is from the 1983 paper by Paul N. Robb and R. I. Mercado, Calculation of refractive indices using Buchdahl’s chromatic coordinate . The copyright date for all 5 catalogs cited was 1980.

name

the catalog name

catalog

dict lookup by glass name, value is decoded glassname and Buchdahl coefficients

catalog_name()
create_glass(gname: str) OpticalMedium | None

Create an instance of the glass gname.

glass_map_data(wvl='d', **kwargs)

return index and dispersion data for all glasses in the catalog

Parameters:

wvl (str) – the central wavelength for the data, either ‘d’ or ‘e’

Returns:

index, V-number, partial dispersion, Buchdahl coefficients, and glass names

get_glass_map_arrays(d_str, F_str, C_str, **kwargs)

return index and dispersion data arrays for input spectral range

Parameters:
  • nd_str (str) – central wavelength string

  • nf_str (str) – blue end wavelength string

  • nc_str (str) – red end wavelength string

Returns:

index, V-number, partial dispersion, Buchdahl coefficients, and glass names

agf_glass

Interface to the the ZemaxGlass AGF file importer

get_glass_map_arrays(cat: AGFCatalog, d_str, F_str, C_str, **kwargs)

return index and dispersion data arrays for input spectral range

Parameters:
  • cat – an agf catalog dictglass catalog instance, source for returned data

  • d_str (str) – central wavelength string

  • F_str (str) – blue end wavelength string

  • C_str (str) – red end wavelength string

  • partials (tuple) – kwarg if present, 2 wvls, wl4 and wl5, wl4 < wl5

Returns:

index, V-number, partial dispersion, Buchdahl coefficients, and glass names

summary_plots(opt_medium, opt_medium_yaml=None)

plot refractive index and thruput data, when available.

class AGFCatalog(catalog_name: str, catalog: dict)

Bases: Mapping, GlassCatalogBase

create_glass(gname: str) AGFMedium

Create an instance of the glass gname.

glass_map_data(wvl='d', **kwargs)

return index and dispersion data for all glasses in the catalog

Parameters:

wvl (str) – the central wavelength for the data, either ‘d’ or ‘e’

Returns:

index, V-number, partial dispersion, Buchdahl coefficients, and glass names

get_agf_lib(agf_path_str: str = '', cat_list: list[str] | str = 'all') GlassLibrary
class AGFMedium(gname, catalog, glass_rec)

Bases: OpticalMedium

wrapper class to ZemaxGlass

name() str
catalog_name() str
glass_code() str
rindex(wvl: float | str) float

Returns the refractive index from the quadratic model at wvl.

calc_rindex(wv_nm: float | NDArray) float | NDArray

returns the interpolated refractive index at wv_nm

Parameters:

wv_nm (float or numpy array) – wavelength in nm for the refractive index query

Returns:

the refractive index at wv_nm

Return type:

float or numpy array

get_wl_range()

returns the wavelength range in nm for the medium definition

meas_rindex(wvl: str) float

returns the measured refractive index at wvl

For InterpolatedMedium the measured index isn’t directly known. The calculated index is used instead. Calling rindex handles the spectral line conversion.

transmission_data() tuple[NDArray, NDArray]

returns an array of transmission data for the glass

Returns: np.arrays of wavelength and transmission for 10mm sample

calc_absorption_coefs() NDArray
summary_plots()

plot refractive index and thruput data, when available.

rindexinfo

Interface to the RefractiveIndex.INFO database

read_rii_file() and read_rii_url() return the native yaml representation used by RefractiveIndex.INFO. The create_material() function returns an object depending on the yaml database specification. If the material is specified by an interpolating polynomial, a RIIMedium instance is returned. If the material is specified by a set of data points, an InterpolatedMedium instance is returned.

create_glass(file_url: str | Path) OpticalMedium

Create a glass from the RefractiveIndex.Info (RII) database.

Parameters:

file_url – Union[str, Path]: a file path or a URL to the RII item

The URL must be rooted in the domain https://refractiveindex.info.

summary_plots(opt_medium, opt_medium_yaml=None)

plot refractive index and thruput data, when available.

get_glassname_from_filestr(filestr: str, include_rii_page=False)

try to construct a name and catalog from the filename/url

If include_rii_page is True, the “Page” or lowest level in the RII hierarchy, typically the lead author of the published results, is appended in brackets to the medium name.

read_rii_file(filename: str | Path)

given a filename of a RII file, return a yaml instance.

read_rii_url(url: str)

given a url to a RII file, return a yaml instance.

create_material(yaml_data: Any, label: str, catalog: str, db: str) OpticalMedium

Create a material object given yaml data and identifiers.

read_coefficients(material_data, material_type)
read_data_arrays(material_data, material_type)
validate_wvls(wv_um, data_range)
eval_formula_1(wv_nm, coeff, data_range=None)

Sellmeier (preferred)

eval_formula_2(wv_nm, coeff, data_range=None)

Sellmeier 2

eval_formula_3(wv_nm, coeff, data_range=None)

Polynomial

eval_formula_4(wv_nm, coeff, data_range=None)

RefractiveIndex.INFO

eval_formula_5(wv_nm, coeff, data_range=None)

Cauchy

eval_formula_6(wv_nm, coeff, data_range=None)

Gases

eval_formula_7(wv_nm, coeff, data_range=None)

Hertzberger

eval_formula_8(wv_nm, coeff, data_range=None)

Retro

eval_formula_9(wv_nm, coeff, data_range=None)

Exotic

class RIICatalog(catalog_name: str, rii_book: dict | None = None, rii_data_path: Path | None = None)

Bases: Mapping, GlassCatalogBase

append_book(rii_book: dict, rii_data_path: Path, incl_book_name: bool = True)

Append the contents of another RII book to this catalog.

gen_all_glasses()

Generate all glasses in the catalog and store in self.catalog.

create_glass(gname: str) OpticalMedium

Create an instance of the glass gname.

glass_map_data(wvl='d', **kwargs)

return index and dispersion data for all glasses in the catalog

Parameters:

wvl (str) – the central wavelength for the data, either ‘d’ or ‘e’

Returns:

index, V-number, partial dispersion, Buchdahl coefficients, and glass names

class RIIMedium(label, coefs, rndx_fct, data_range, kvals_wvls=None, kvals=None, mat='', cat='')

Bases: OpticalMedium

RefractiveIndexInfo wrapper class supporting formula specs

name() str
catalog_name() str
glass_code() str
update() None
rindex(wvl: float | str) float

Returns the refractive index from the quadratic model at wvl.

calc_rindex(wv_nm: float | NDArray) float | NDArray

returns the interpolated refractive index at wv_nm

Parameters:

wv_nm (float or numpy array) – wavelength in nm for the refractive index query

Returns:

the refractive index at wv_nm

Return type:

float or numpy array

get_wl_range() tuple[float, float]

returns the wavelength range in nm for the medium definition

meas_rindex(wvl: str) float

returns the measured refractive index at wvl

For InterpolatedMedium the measured index isn’t directly known. The calculated index is used instead. Calling rindex handles the spectral line conversion.

transmission_data(thi=10.0)

returns an array of transmission data for the glass

The default implementation returns unit transmittance over the wavelength range given by get_wl_range()

Parameters:

thi – the sample thickness in mm for the transmittance data

Returns:

tuple of Numpy arrays of wavelength and transmittance

get_rii_libs(rii_base_path: str | Path | None = None) dict[str, GlassLibrary]

This function populates a dict of GlassLibrary instances, using a RefractiveIndex.INFO database at rii_base_path

If the rii_base_path is None, the environment variable refractiveindexinfodb is checked for a path, and if that is not set, the default path ~/.refractiveindex.info-database is used. The RefractiveIndex.INFO database is downloaded from GitHub if necessary.

rii_download

Support for downloading the RefractiveIndex.INFO database from GitHub.

fork of https://github.com/toftul/refractiveindex/refractiveindex/refractiveindex.py under the following license:

MIT License

Copyright (c) 2023 Ivan Toftul

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. —————————————————————————- Modifications include: - use logging for informative output - minimal comments

download_database(db_path: Path, ssl_certificate_location: str | None = None)

Download the RefractiveIndex.INFO database from GitHub and extract it to db_path.

ensure_database(db_path: Path, auto_download: bool, update_database: bool, ssl_certificate_location: str | None)

Ensure that the RefractiveIndex.INFO database exists at db_path, downloading if necessary and allowed.

GUI Submodules

glassmap

Glass map display, via Matplotlib

class GlassMapFigure(glass_libs, hover_glass_names=True, plot_display_type='Refractive Index', refresh_gui=None, **kwargs)

Bases: Figure

Matplotlib implementation of an optical glass map.

glass_libs

an instance of GlassLibrary

hover_glass_names

if True display glass name list under cursor

plot_display_type

controls the type of data display. Supported types are:

  • “Refractive Index”

  • “Partial Dispersion”

  • “Buchdahl Coefficients”

  • “Buchdahl Dispersion Coefficients”

refresh_gui

an optional function called when a glass is picked

pick_list

list of glasses selected by a mouse click. The on_pick fct accumulates the pick_list. Filled with:

catalog_name, glass_name, nd, vd, PCd

dsc = [(0.2196078431372549, 0.5568627450980392, 0.5568627450980392), (0.5215686274509804, 0.5215686274509804, 0.5215686274509804), (0.44313725490196076, 0.44313725490196076, 0.7764705882352941), (0.4, 0.803921568627451, 0), (1.0, 0.4470588235294118, 0.33725490196078434), (1.0, 0.6470588235294118, 0.0), (0.5450980392156862, 0.5450980392156862, 0.5137254901960784)]
mkr = ['^', 'x', '2', 's', 'v', '+', '*', 'D', 'o']
home_bbox = Bbox([[95.0, 1.45], [20.0, 2.05]])
home_bbox_lrg = Bbox([[105.0, 1.3], [15.0, 2.15]])
connect_events(action_dict=None)

connect to all the events we need

disconnect_events()

disconnect all the stored connection ids

get_display_label()

Return the type of plot being displayed.

refresh(**kwargs)

Call update_data() followed by plot(), return self.

Parameters:

kwargs – keyword arguments are passed to update_data

Returns:

self (class Figure) so scripting envs will auto display results

update_data(**kwargs)

Fill in raw_data array.

The raw_data attribute is a list over catalogs. Each catalog has an item consisting of the catalog name and a tuple of vectors:

n, v, p, coefs0, coefs1, glass_names

update_axis_limits(bbox)

Update the axis limits basde on the data bounding box.

draw_axes()

Draw and label the axes.

plot()

Draw the glass map.

draw_glass_polygons()

Draw the glass polygons on the map.

clear_pick_table()

Reset the pick list.

find_artists_at_location(event)

Returns a list of shapes in zorder at the event location.

on_hover(event)

Display the glasses under the cursor.

on_pick(event)

handle picking glasses under the cursor.

One pick event for each catalog, extract selected glasses and add to pick_list

on_press(event)

handle mouse clicks within the diagram.

The button press event is sent after the pick events; it will be sent in cases with no pick events, e.g. clicking in an empty area of the axes. The two cases are:

  • if there were pick events, needsClear will be False so that items from different artists can be accumulated in the pick_list. The press event signals no further item accumulation. Flip needsClear to True so the next pick or press event will clear the pick_list.

  • if there were no pick events, needsClear will be True. Call clear_pick_table to empty pick_list and reset needsClear to False.

updateVisibility(indx, state)

Update the visibility and redraw.

set(*, agg_filter=<UNSET>, alpha=<UNSET>, animated=<UNSET>, canvas=<UNSET>, clip_box=<UNSET>, clip_on=<UNSET>, clip_path=<UNSET>, constrained_layout=<UNSET>, constrained_layout_pads=<UNSET>, dpi=<UNSET>, edgecolor=<UNSET>, facecolor=<UNSET>, figheight=<UNSET>, figwidth=<UNSET>, frameon=<UNSET>, gid=<UNSET>, in_layout=<UNSET>, label=<UNSET>, layout_engine=<UNSET>, linewidth=<UNSET>, mouseover=<UNSET>, path_effects=<UNSET>, picker=<UNSET>, rasterized=<UNSET>, size_inches=<UNSET>, sketch_params=<UNSET>, snap=<UNSET>, tight_layout=<UNSET>, transform=<UNSET>, url=<UNSET>, visible=<UNSET>, zorder=<UNSET>)

Set multiple properties at once.

a.set(a=A, b=B, c=C)

is equivalent to

a.set_a(A)
a.set_b(B)
a.set_c(C)

In addition to the full property names, aliases are also supported, e.g. set(lw=2) is equivalent to set(linewidth=2), but it is an error to pass both simultaneously.

The order of the individual setter calls matches the order of parameters in set(). However, most properties do not depend on each other so that order is rarely relevant.

Supported properties are

Properties:

agg_filter: a filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array and two offsets from the bottom left corner of the image alpha: float or None animated: bool canvas: FigureCanvas clip_box: ~matplotlib.transforms.BboxBase or None clip_on: bool clip_path: Patch or (Path, Transform) or None constrained_layout: unknown constrained_layout_pads: unknown dpi: float edgecolor: color facecolor: color figheight: float figure: unknown figwidth: float frameon: bool gid: str in_layout: bool label: object layout_engine: {‘constrained’, ‘compressed’, ‘tight’, ‘none’, .LayoutEngine, None} linewidth: number mouseover: bool path_effects: list of .AbstractPathEffect picker: None or bool or float or callable rasterized: bool size_inches: (float, float) or float sketch_params: (scale: float, length: float, randomness: float) snap: bool or None tight_layout: unknown transform: ~matplotlib.transforms.Transform url: str visible: bool zorder: float

glassmapviewer

desktop application for viewing glass catalog data

init_glass_libs(og_glass_libs)
init_UI(gui_parent, fig)
createTestWidgetBox(gui_parent, fig)
createPlotTypeBox(gui_parent, fig)
createPartialsBox(gui_parent, fig)
on_plot_type_toggled(fig, button)
createLibraryGroupBox(gui_parent, fig)
createCatalogGroupBox(gui_parent, fig, lib: str)
create_select_all_lib_cat_checkbox(fig, lib, check_box_list)
create_handle_lib_cat_checkbox(fig, cb_number, lib, cat_name)
class GlassMapViewer(glass_libs, window_size=(1650, 1100))

Bases: QMainWindow

refresh_gui(**kwargs)
staticMetaObject = PySide6.QtCore.QMetaObject("GlassMapViewer" inherits "QMainWindow": )
class PickTable(gui_parent, pick_model)

Bases: QTableView

mousePressEvent(event)

Initiate glass drag and drop operation from here.

staticMetaObject = PySide6.QtCore.QMetaObject("PickTable" inherits "QTableView": )
class PickModel(fig)

Bases: QAbstractTableModel

rowCount(index)
columnCount(index)
headerData(section, orientation, role)
data(index, role)
fill_table(pick_list)
staticMetaObject = PySide6.QtCore.QMetaObject("PickModel" inherits "QAbstractTableModel": )
class LabelDelegate(parent=None)

Bases: QItemDelegate

get_label(option, index)
paint(painter, option, index)
sizeHint(option, index)
staticMetaObject = PySide6.QtCore.QMetaObject("LabelDelegate" inherits "QItemDelegate": )
class PlotCanvas(gui_parent, fig)

Bases: FigureCanvasQTAgg

staticMetaObject = PySide6.QtCore.QMetaObject("PlotCanvas" inherits "FigureCanvasQTAgg": )
main()

glasspolygons

create glass map glass designation polygons

find_glass_designation(nd, vd)

find the designation and rgb color for the input index and V number

Parameters:
  • nd – refractive index, d line

  • vd – V-number, d line

Returns:

designation label, RGBA list

Catalog-specific Submodules

cdgm

Support for the CDGM Glass catalog

decode_dispersion_coefs(glas: Series) tuple[list, str]

Decode CDGM dispersion to Sellmeier or Schott formula.

class CDGMCatalog(catalog_name: str = 'CDGM', fname: str = 'CDGM202409.xlsx', last_data_row: int = 323)

Bases: GlassCatalogPandas

glass_coefs(gname)

returns an array of glass coefficients for the glass at gname

create_glass(gname: str) CDGMGlass

Create an instance of the glass gname.

class CDGMGlass(gname)

Bases: GlassPandas

catalog: CDGMCatalog | None = <opticalglass.cdgm.CDGMCatalog object>
initialize_catalog()

subclass initialization of glass catalog instance, as needed.

calc_rindex(wv_nm)

returns the interpolated refractive index at wv_nm

Must be provided by the derived class

Parameters:

wv_nm (float or numpy array) – wavelength in nm for the refractive index query

Returns:

the refractive index at wv_nm

Return type:

float or numpy array

calc_rindex_schott(wv_nm)
calc_rindex_sellmeier(wv_nm)

hikari

Support for the Hikari Glass catalog

class HikariCatalog(catalog_name: str = 'Hikari', fname: str = 'hikari_general_catalog_data.xlsx', last_data_row: int = 163)

Bases: GlassCatalogPandas

static get_rindx_wvl(header_str)

Returns the wavelength value from the refractive index data header string.

static get_transmission_wvl(header_str)

Returns the wavelength header string.

create_glass(gname: str) HikariGlass

Create an instance of the glass gname.

class HikariGlass(gname)

Bases: GlassPandas

catalog = <opticalglass.hikari.HikariCatalog object>
initialize_catalog()

subclass initialization of glass catalog instance, as needed.

calc_rindex(wv_nm)

returns the interpolated refractive index at wv_nm

Must be provided by the derived class

Parameters:

wv_nm (float or numpy array) – wavelength in nm for the refractive index query

Returns:

the refractive index at wv_nm

Return type:

float or numpy array

hoya

Support for the Hoya Glass catalog

class HoyaCatalog(catalog_name: str = 'Hoya', fname: str = 'HOYA20260401.xlsx', last_data_row: int = 242)

Bases: GlassCatalogPandas

glass_coefs(gname)

returns an array of glass coefficients for the glass at gname

create_glass(gname: str) HoyaGlass

Create an instance of the glass gname.

class HoyaGlass(gname)

Bases: GlassPandas

catalog = <opticalglass.hoya.HoyaCatalog object>
initialize_catalog()

subclass initialization of glass catalog instance, as needed.

calc_rindex(wv_nm)

returns the interpolated refractive index at wv_nm

Must be provided by the derived class

Parameters:

wv_nm (float or numpy array) – wavelength in nm for the refractive index query

Returns:

the refractive index at wv_nm

Return type:

float or numpy array

ohara

Support for the Ohara Glass catalog

class OharaCatalog(catalog_name: str = 'Ohara', fname: str = 'ohara-catalog-20250312-S-6dec.xlsx', last_data_row: int = 136)

Bases: GlassCatalogPandas

static get_rindx_wvl(header_str)

Returns the wavelength value from the refractive index data header string.

create_glass(gname: str) OharaGlass

Create an instance of the glass gname.

class OharaGlass(gname)

Bases: GlassPandas

catalog = <opticalglass.ohara.OharaCatalog object>
initialize_catalog()

subclass initialization of glass catalog instance, as needed.

calc_rindex(wv_nm)

returns the interpolated refractive index at wv_nm

Must be provided by the derived class

Parameters:

wv_nm (float or numpy array) – wavelength in nm for the refractive index query

Returns:

the refractive index at wv_nm

Return type:

float or numpy array

schott

Support for the Schott Glass catalog

class SchottCatalog(catalog_name: str = 'Schott', fname='schott-optical-glass-overview-excel-format-en 202501113.xlsx', last_data_row: int = 126)

Bases: GlassCatalogPandas

static get_rindx_wvl(header_str)

Returns the wavelength value from the refractive index data header string.

static get_transmission_wvl(header_str)

Returns the wavelength value from the transmission data header string.

create_glass(gname: str) SchottGlass

Create an instance of the glass gname.

class SchottGlass(gname)

Bases: GlassPandas

catalog = <opticalglass.schott.SchottCatalog object>
initialize_catalog()

subclass initialization of glass catalog instance, as needed.

calc_rindex(wv_nm)

returns the interpolated refractive index at wv_nm

Must be provided by the derived class

Parameters:

wv_nm (float or numpy array) – wavelength in nm for the refractive index query

Returns:

the refractive index at wv_nm

Return type:

float or numpy array

sumita

Support for the Sumita Glass catalog

class SumitaCatalog(catalog_name: str = 'Sumita', fname: str = 'glassdata_ver14.01.03_en.xlsx', last_data_row: int = 130)

Bases: GlassCatalogPandas

static get_rindx_wvl(header_str)

Returns the wavelength value from the refractive index data header string.

static get_transmission_wvl(header_str)

Returns the wavelength value from the transmission data header string.

create_glass(gname: str) SumitaGlass

Create an instance of the glass gname.

class SumitaGlass(gname)

Bases: GlassPandas

catalog = <opticalglass.sumita.SumitaCatalog object>
initialize_catalog()

subclass initialization of glass catalog instance, as needed.

calc_rindex(wv_nm)

returns the interpolated refractive index at wv_nm

Must be provided by the derived class

Parameters:

wv_nm (float or numpy array) – wavelength in nm for the refractive index query

Returns:

the refractive index at wv_nm

Return type:

float or numpy array

Misc Submodules

spectral_lines

Support for using wavelength values and spectral line designations interchangably.

spectra: dict[str, float] = {"A'": 768.195, 'C': 656.2725, "C'": 643.8469, 'D': 589.2938, 'F': 486.1327, "F'": 479.9914, 'He-Cd': 441.57, 'He-Ne': 632.8, 'Nd': 1060.0, 'd': 587.5618, 'e': 546.074, 'g': 435.8343, 'h': 404.6561, 'i': 365.014, 'r': 706.5188, 's': 852.11, 't': 1013.98}

dict of spectral line labels and wavelengths in nm

  • keys: spectral line labels

  • values: wavelengths in nm

get_wavelength(wvl) float | NDArray

Return wvl in nm, where wvl can be a spectral line

Example:

In [1]: from rayoptics.util.spectral_lines import *

In [2]: wl_e = get_wavelength('e'); wl_e
Out[2]: 546.074

In [3]: wl_HeNe = get_wavelength('He-Ne'); wl_HeNe
Out[3]: 632.8

In [4]: wl_550 = get_wavelength(550); wl_550
Out[4]: 550.0

In [5]: wl_fl = get_wavelength(555.0); wl_fl
Out[5]: 555.0

In [6]: wl_f = get_wavelength('F'); wl_f
Out[6]: 486.1327
Parameters:

wvl – either the wavelength in nm, a string with a spectral line identifier or a pandas Index. Case sensitive - Fraunhofer lines have a proper capitalization. The keys need to match exactly.

Returns:

the wavelength in nm, or a numpy array of floats

Return type:

float

Raises:

KeyError – if wvl is not in the spectra dictionary

util

Utilities including Singleton metaclass

class Counter

Bases: dict

A dict that initializes a missing key’s value to 0.

Example

track_changes = Counter() track_changes[‘something happened’] += 1 track_changes[‘something not found’] += 1

class Singleton

Bases: type

A metaclass implementation for the Singleton pattern.

Example

class JustOne(metaclass=Singleton):

pass

move_to(cltn: list, i: int, item: object) list

Move item to index i in collection cltn.

md_sub_to_mathtex(md_str: str) str

Convert markdown subscript to mathtex format.

rgb2mpl(rgb)

convert 8 bit RGB data to 0 to 1 range for mpl

calc_glass_constants(nd, nF, nC, *partials)

Given central, blue and red refractive indices, calculate Vd and PFd.

Parameters:
  • nd – refractive indices at central, short and long wavelengths

  • nF – refractive indices at central, short and long wavelengths

  • nC – refractive indices at central, short and long wavelengths

  • partials (tuple) – if present, 2 ref indxs, n4 and n5, wl4 < wl5

Returns:

V-number and relative partial dispersion from F to d

If partials is present, the return values include the central wavelength index and the relative partial dispersion between the 2 refractive indices provided from partials.

class DecodedGlassName(prefix: str, group: str, num: str, suffix: str)

Bases: object

prefix: str
group: str
num: str
suffix: str
property name: str
property group_num: str
astuple() tuple[str, str, str, str]
decode_glass_name(glass_name: str) DecodedGlassName

Split glass_name into prefix, group, num, suffix.

Manufacturers glass names follow a common pattern. At the simplest, it is a short character string, typically used to identify a particular glass composition, with a numeric qualifier. The composition group and product serial number are combined to form the basic product id, the group_num:

  • F2

  • SF56

Manufacturers will often use a single character prefix to indicate different categories of glasses, e.g. moldable or “New”:

  • N-BK7

  • P-LASF50

Similarly, a suffix with one or more characters is often used to differentiate between different variations of the same base material.

  • N-SF57

  • N-SF57HT

  • N-SF57HTultra

This function takes an input glass name and returns a tuple of strings. A valid glass_name should always have a non-null group_num; prefixes and suffixes are optional and used differently by different manufacturers.

  • group_num, prefix, suffix

  • group, num = group_num

Parameters:

glass_name (str) – a glass manufacturer’s glass name

Returns: group_num, prefix, suffix, where group_num = group, num

Returned strings are uppercase.

glasserror

Support for Glass catalog exception handling

exception GlassError

Bases: Exception

Exception raised when interrogating glass database

exception GlassCatalogNotFoundError(catalog)

Bases: GlassError

Exception raised when glass catalog name not found

exception GlassNotFoundError(catalog, name)

Bases: GlassError

Exception raised when glass name not found

exception GlassDataNotFoundError(catalog, data)

Bases: GlassError

Exception raised when glass data item not found

exception GlassDBNotSupported(db)

Bases: GlassError

Exception: data-n2 rindexinfo database is requested.