materials.material_utils
Utility functions for working with materials.
Functions
|
Downsample a glass dictionary using K-Means clustering in the (n_d, V_d) space. |
|
Find the glass in catalog whose (nd, vd) is closest to nd_vd. |
|
Retrieve the refractive index (n_d) and Abbe number (V_d) for a given glass. |
|
Return the num_neighbours closest glasses to the given glass in (n_d, V_d) space. |
|
Retrieves a list of glass names whose tabulated transmission window fully covers the specified wavelength interval [lambda1, lambda2]. |
|
Plot a (n_d, V_d) scatter map of selected optical glasses, highlighting specific ones. |
|
Plot the refractive index (n) and extinction coefficient (k) of a material versus wavelength. |
- downsample_glass_map(glass_dict: dict, num_glasses_to_keep: int) dict[source]
Downsample a glass dictionary using K-Means clustering in the (n_d, V_d) space.
- The dictionary must be in the form:
glass_dict = {‘S-BSM22’: (1.62, 53.16), ‘LF5G19’: (1.59, 39.89), …}
- Parameters:
glass_dict (dict) – Dictionary with glass names as keys and (n_d, V_d) tuples as values.
num_glasses_to_keep (int) – Number of representative glasses to retain after clustering.
- Returns:
Downsampled dictionary with selected representative glasses.
- Return type:
dict
- Raises:
ValueError – If num_glasses_to_keep is greater than the number of available glasses.
- find_closest_glass(nd_vd: tuple, catalog: list[str], plot_map: bool = False) str[source]
Find the glass in catalog whose (nd, vd) is closest to nd_vd.
- Parameters:
nd_vd (tuple) – Target (nd, vd).
catalog (list[str]) – List of glass names.
- Returns:
Name of the closest glass.
- Return type:
str
- get_nd_vd(glass: str) tuple[float, float][source]
Retrieve the refractive index (n_d) and Abbe number (V_d) for a given glass.
This function loads the material data associated with the specified glass name, reads its YAML specification file, and extracts the n_d and V_d values from the “SPECS” section. If either value is missing, defaults to (0, 0).
- Parameters:
glass (str) – Name of the glass material.
- Returns:
A tuple (n_d, V_d) representing the refractive index and Abbe number, in the form: glass_dict = {‘S-BSM22’: (1.62, 53.16), ‘LF5G19’: (1.59, 39.89), …}
- Return type:
tuple[float, float]
- get_neighbour_glasses(glass: str, glass_selection: list[str] = None, glass_dict: dict[str, tuple[float, float]] = None, num_neighbours: int = 3, plot: bool = False) list[str][source]
Return the num_neighbours closest glasses to the given glass in (n_d, V_d) space.
- Parameters:
glass (str) – Name of the reference glass.
glass_selection (list[str]) – List of glass names to search among.
glass_dict (dict[str, tuple[float, float]]) – dict of glass names associated with their (nv,vd) pairs.
num_neighbours (int) – Number of closest glasses to return.
plot (bool) – If True, plot the selected glass map and highlight neighbors.
- Returns:
- List of num_neighbours closest glasses
to glass in (n_d, V_d) space.
- Return type:
list[str]
- glasses_selection(lambda_min: float, lambda_max: float, catalogs: list[str] | None = None) list[str][source]
Retrieves a list of glass names whose tabulated transmission window fully covers the specified wavelength interval [lambda1, lambda2]. Optionally filters by catalog names.
- Parameters:
lambda_min (float) – The lower wavelength bound in microns.
lambda_max (float) – The upper wavelength bound in microns.
catalogs (list[str], optional) – List of catalog names. Catalog names are case-insensitive. Defaults to None.
- Returns:
- List of unique glass names transmissive within
the wavelength interval and matching catalogs $ if specified.
- Return type:
list[str]
- plot_glass_map(glass_selection: list[str], highlights: list[str], title: str = None) None[source]
Plot a (n_d, V_d) scatter map of selected optical glasses, highlighting specific ones.
This visualization is useful to understand the distribution of glasses in the (index, Abbe number) space and to inspect how selected or substituted glasses relate to the rest of the catalogue.
- Parameters:
glass_selection (list[str]) – List of glass names to plot.
highlights (list[str]) – List of glass names to highlight
red (in)
title (str, optional) – Custom title for the plot.
provided (If not)
used. (a default title is)
Notes
Glasses with invalid (0, 0) values for (n_d, V_d) are skipped and reported.
The V_d axis is reversed to match optical engineering conventions.
- plot_nk(material: Material, wavelength_range: tuple[float, float] | None = None, ax: Axes | tuple[Axes, Axes] | None = None, n_sample: int = 800, share_yscale: bool = False) tuple[Figure, tuple[Axes, Axes]][source]
Plot the refractive index (n) and extinction coefficient (k) of a material versus wavelength.
- Parameters:
material (Material) – The material object containing optical data.
wavelength_range (tuple) – The range of wavelengths to plot (min_wl, max_wl)
None (in micrometers. If)
not (the full range is used. If wavelength_range is)
range (contained within the material's)
indicate (red shading is applied to)
region. (the out-of-bounds)
ax (matplotlib.axes.Axes, optional) – The axes to plot on. If None, a new
created. (figure and axes are)
n_sample (int) – The number of wavelength samples to compute.
share_yscale (bool) – Whether to share the y-axis scale between n and k plots.
- Returns:
A tuple containing the figure and a list of two axes objects
Example: >>> mat = Material(“BK7”, reference=”SCHOTT”) >>> plot_nk(mat, wavelength_range=(0.4, 0.7))