corset.core#
Core classes for representing and simulating Gaussian beams and optical setups.
Setups are represented as OpticalSetup instances which propagate an initial Beam
through a sequence of Lens elements. This yields a piecewise defined beam radius made
from Gaussian beam segments between the elements. The individual beams are represented using
a complex beam parameter combined with an axial offset and wavelength. The beams are propagated
using the ray transfer matrix method for Gaussian beams, see here.
- class corset.core.Beam(beam_parameter, z_offset, wavelength, gauss_cov=None) None#
Paraxial Gaussian beam representation.
Implements
_repr_png_()to show a plot of the beam radius in IPython environments produced byBeam.plot().- classmethod fit(positions, radii, wavelength, p0=None) Beam#
Fit a Gaussian beam radius to measured data.
This uses
scipy.optimize.curve_fit()to estimate the focus position and waist given arrays of axial positions and measured radii.- Parameters:
positions (
ndarray) – Axial positions where radii were measured.radii (
ndarray) – Measured beam radii corresponding to the positions.wavelength (
float) – Wavelength used to relate waist and Rayleigh range.p0 (
tuple[float,float] |None, default:None) – Initial guess for (focus, waist). If omitted a simple heuristic is used.
- Return type:
- Returns:
Beam instance fitted to the data.
- classmethod from_gauss(focus, waist, wavelength, cov=None) Beam#
Create a Beam instance from focus position and waist.
- 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:
- 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.
- plot(**kwargs) OpticalSetupPlot#
Plot the beam as part of an optical setup with no other elements.
- Parameters:
**kwargs – Keyword arguments forwarded to
OpticalSetup.plot().- Return type:
- Returns:
OpticalSetupPlot instance for further customization.
- radius_dev(z) float | ndarray#
Compute the beam radius (standard) deviation at axial position(s).
- Parameters:
z (
float|ndarray) – Axial position(s) where the beam radius deviation is evaluated.- Return type:
- Returns:
Beam radius deviation at the specified axial position(s).
- Raises:
ValueError – If the covariance matrix is not defined for this beam.
- class corset.core.OpticalSetup(initial_beam, elements, validate=True) None#
Optical setup described by an initial beam and a sequence of elements.
Implements
_repr_png_()to show a plot of the optical setup in IPython environments produced byOpticalSetup.plot().- Parameters:
- classmethod fit(positions, radii, wavelength, elements, p0=None) OpticalSetup#
Fit an optical setup to measured data.
- Parameters:
positions (
ndarray) – Axial positions where radii were measured.radii (
ndarray) – Measured beam radii corresponding to the positions.wavelength (
float) – Wavelength used to relate waist and Rayleigh range.elements (
Sequence[tuple[float|tuple[float,float],ThinLens|ThickLens]]) – Optical elements as (position, element) tuples sorted by position. positions can be specified as float to describe a fixed position or as (expected, deviation) tuple to fit the element position between expected - deviation and expected + deviation.p0 (
tuple[float,float] |None, default:None) – Initial guess for (focus, waist). If omitted a simple heuristic is used.
- Return type:
- Returns:
OpticalSetup instance fitted to the data.
- Raises:
ValueError – If the initial guess for element positions are not in ascending order.
ValueError – If the fitted element positions are invalid, i.e. not in ascending order.
ValueError – If no data point is before the first element when using beam parameter initial guess heuristic.
- 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:
- 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.
- plot(*, points=None, limits=None, beam_kwargs=None, confidence_interval=None, rayleigh_range_cap=None, free_lenses=[], ax=None, show_legend=None, legend_loc=None) OpticalSetupPlot#
Plot the optical setup, see
corset.plot.plot_setup()- Return type:
- Parameters:
- property beam_parameters: list[complex]#
Compute the ray vectors between elements including before the first element and after the last.
- property beams: list[Beam]#
Compute the Beam instances between elements including before the first element and after the last.
- elements: list[tuple[float, ThinLens | ThickLens]]#
Optical elements as (position, element) tuples sorted by position
- property gauss_covariances: list[ndarray | None]#
Compute the covariance matrices between elements including before the first element and after the last.
- validate: dataclasses.InitVar[bool] = True#
Validate that elements are sorted by position
- class corset.core.ThickLens(in_roc, out_roc, thickness, refractive_index, left_margin=0.0, right_margin=0.0, name=None) None#
Thick lens element including additional information.
The signs of the radius of curvature follow the standard optics convention where positive radii correspond to surfaces that are convex when viewed from the input side of the lens. This means that on the entry surface, a positive radius of curvature is a convex surface while on the exit surface, a negative radius of curvature is convex. Use
ThickLens.FLATto represent a flat surface. This is an alias forfloat('inf').- Parameters:
- 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:
- 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.
- property focal_length: float#
Approximate focal length of the thick lens calculated using the lensmaker’s equation.
- class corset.core.ThinLens(focal_length, left_margin=0.0, right_margin=0.0, name=None) None#
Thin lens element including additional information.
- 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:
- 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.
- corset.core.Lens = corset.core.ThinLens | corset.core.ThickLens#
Lens type union