corset.database#

Lens database class for managing collections of lenses.

This class can be used to load the lens databases included with Beam Corset. Use LensList.available() to list the available databases and LensList.load() to load a database by name.

The typical naming scheme for these databases is as follows:

[domain]/[manufacturer]_[lens type]_L[applicable wavelength in nm]_M[total margins in mm]

e.g. quantum_control/Thorlabs_BX_L1064_M10 is a database from the Quantum Control made up of Thorlabs bi-convex lenses applicable for 1064 nm light with a total margin (left + right) of 10 mm. There are also combined databases, where the manufacturer and lens type are replaced with Combined.

The lens type shorthands are as follows:

  • BX : Bi-Convex

  • BV : Bi-Concave

  • PX : Plan-Convex

  • XP : Convex-Plan

  • PV : Plan-Concave

  • VP : Concave-Plan

The lenses in these databases adhere to the following conventions:

[first letter of manufacturer][lens type][nominal focal length in mm]

so a Thorlabs bi-convex lens with a nominal focal length of 50 mm is named TBX50. This keeps the name short for plotting and makes it easier to index into lens lists by name.

class corset.database.LensList(lenses) None#

A list of lenses with convenient access methods.

Supports (array) indexing and other list-like operations, indices can also be strings or list of strings to access lenses by name. Implements _repr_html_() to show a pandas.DataFrame representation in IPython environments.

Parameters:

lenses (list[ThinLens | ThickLens])

classmethod available() list[str]#

List available built-in lens databases.

Returns:

Names of available lens databases.

Return type:

list[str]

classmethod load(name) LensList#

Load a lens database from the built-in library.

Parameters:

name (str) – Name of the lens database to load.

Returns:

The loaded lens database.

Return type:

LensList

Raises:

FileNotFoundError – If the lens database name is not found in the library.

classmethod load_csv(path) LensList#

Load a lens list from a CSV file.

Parameters:

path (str | Path) – Path to the CSV file. This is passed directly to pandas.read_csv() so it also accepts other types supported by that function like URL strings or file-like objects.

Returns:

The loaded lens list.

Return type:

LensList

Raises:
  • ValueError – If the CSV file contains invalid data.

  • KeyError – If required fields are missing in the CSV file.

classmethod load_yaml(filename) Self#

Load an object from a YAML file.

If this is called from a subclass the loaded object type must match that subclass.

Parameters:

filename (str | Path) – Path to the YAML file.

Return type:

Self

Returns:

The loaded object.

Raises:
  • ValueError – If the YAML file does not contain a ‘data’ field.

  • TypeError – If the loaded object type does not match the class used to call this method.

concatenate() LensList#

Concatenate multiple lens lists or lists of lenses.

Parameters:

lists (Iterable[ThinLens | ThickLens]) – LensList or list of Lens instances to concatenate.

Returns:

The concatenated lens list.

Return type:

LensList

save_csv(path) None#

Save the lens list to a CSV file.

Parameters:

path (str | Path) – Path to the CSV file. This is passed directly to pandas.DataFrame.to_csv() so it also accepts other types supported by that function like file-like objects.

Return type:

None

save_yaml(filename) None#

Save the object to a YAML file.

Parameters:
  • filename (str | Path) – Path to the YAML file.

  • self (Any)

Return type:

None

property df: DataFrame#

A pandas.DataFrame representation of the lens list.

lenses: list[ThinLens | ThickLens]#

Underlying list of lenses