refidx package

Submodules

refidx.core module

Get refractive index from a database

This module allows you to retrieve the refractive index of a material at a given wavelength from the refractiveindex.info database. It is inspired by the repository by cinek810.

The database contains a large set of refractive indices of various materials, and is updated regularly. The database is stored in a .npz file, which is loaded when the module is imported.

The module provides two classes: Material and DataBase. The Material class represents a material in the database, and provides methods to get the refractive index of the material. The DataBase class represents the database itself and provides methods to search the database and retrieve a Material instance.

The module also provides a few functions to help with the search and retrieval of materials. For example, the find function allows you to search the database by name or formula, and the get function allows you to retrieve a material by its id.

class refidx.core.DataBase[source]

Bases: object

Material database

This class provides access to the refractiveindex.info material database.

get_item(keys)[source]

Get an item from a nested dictionary given a list of keys.

random()[source]

Get a random material from the database.

This method will return a random material from the database. The material is selected by randomly selecting a key from the nested dictionary until a Material instance is found.

class refidx.core.Material(id)[source]

Bases: object

Material class

property comments

Get the comments associated with the material.

Returns:

The comments associated with the material, or None if no comments are available.

Return type:

str or None

property data

Get the data associated with the material.

Returns:

The data associated with the material.

Return type:

dict

get_index(wavelength)[source]

Get the complex refractive index.

Parameters:

wavelength (float or array of floats) – Wavelength(s) in microns.

Returns:

The refractive index(es).

Return type:

complex or array of complex

Raises:

ValueError – If the wavelength is not within the material’s data range.

Notes

The refractive index is interpolated from the data stored in the material database. The interpolation is done using the np.interp function.

The material data is stored in a dictionary with the following keys:

  • “wavelengths”list of floats

    The wavelength range of the material.

  • “index”list of complex

    The refractive index data.

  • “coefficients”list of floats

    The coefficients of the formula used to calculate the refractive index.

  • “type”str

    The type of the material, e.g. “tabulated” or “formula 1”.

The type of the material determines the interpolation method used:

  • “tabulated” : The refractive index is interpolated from the data stored in the material database.

  • “formula 1” : The refractive index is calculated using the formula given by the coefficients in the material database.

property info

Get a dictionary with comments and references associated with the material.

Returns:

A dictionary with comments and references associated with the material.

Return type:

dict

property material_data

Get the material data.

Returns:

The material data.

Return type:

dict

property name

Get the name of the material.

Returns:

The name of the material, e.g. “Ag / Glass / BK7”.

Return type:

str

print_info(html=False, tmp_dir=None, filename='out.html')[source]

Print the material information.

The material information is a dictionary with the keys “comments”, “references”, and “type”. The value associated with the “comments” key is the comments associated with the material, the value associated with the “references” key is a list of references associated with the material, and the value associated with the “type” key is the type of the material, e.g. “tabulated” or “formula 1”.

Parameters:
  • html (bool) – If True, print the material information as HTML. If False, print as a plain text dictionary.

  • tmp_dir (str) – If not None, save the HTML to a file in the given directory. If None, display the HTML using IPython.display.HTML if available, otherwise print the material information as a plain text dictionary.

property references

Get the references associated with the material.

Returns:

A list of references associated with the material.

Return type:

list

property type

Get the type of the material.

Returns:

The type of the material, e.g. “tabulated” or “formula 1”.

Return type:

str

property wavelength_range

Get the wavelength range of the material.

Returns:

The wavelength range of the material, given as [min, max].

Return type:

list

Module contents

Top-level package for refidx.

The main classes and functions are:

  • Material: A class representing a refractive index material.

  • DataBase: A class representing the refractive index database.

  • MaterialDict: A dictionary of materials.

  • find: A function to search the database by name or formula.

  • get: A function to retrieve a material by its id.