corset.plot#

Plotting functions for optical setups and mode matching solutions and analyses.

class corset.plot.ModeMatchingPlot(ax, setup, desired_beam, ranges, apertures, passages) None#

Plot of a mode matching solution with references to the plot elements.

Parameters:
apertures: list[Line2D]#

List of aperture lines in the plot

ax: Axes#

Axes containing the plot

desired_beam: OpticalSetupPlot#

Plot of the desired beam profile

passages: list[Rectangle]#

List of passage rectangles in the plot

ranges: list[Rectangle]#

List of ranges in the plot

setup: OpticalSetupPlot#

Plot of the actual optical setup

class corset.plot.OpticalSetupPlot(ax, zs, rs, beam, lenses) None#

Plot of an optical setup with references to the plot elements.

Parameters:
ax: Axes#

Axes containing the plot

beam: FillBetweenPolyCollection#

Fill between collection for the beam

lenses: list[tuple[LineCollection, Annotation]]#

List of lens plot elements

property r_max: float#

Maximum beam radius in the plot.

rs: ndarray#

Radii of the beam profile

zs: ndarray#

Z-coordinates of the beam profile

class corset.plot.ReachabilityPlot(ax, lines, contour, colorbar) None#

Plot of a reachability analysis with references to the plot elements.

Parameters:
ax: Axes#

Axes containing the plot

colorbar: Colorbar | None#

Colorbar for the contour plot

contour: Any#

Contour plot of the mode overlap

lines: list[list[Line2D]]#

Lines representing parameter variations

class corset.plot.SensitivityPlot(ax, contours, colorbar, handles) None#

Plot of a sensitivity analysis with references to the plot elements.

Parameters:
  • ax (Axes)

  • contours (list[Any])

  • colorbar (Colorbar | None)

  • handles (list)

ax: Axes#

Axes containing the plot

colorbar: Colorbar | None#

Colorbar for the contour plots

contours: list[Any]#

Contour plots of the sensitivity

handles: list#

Handles for the plot elements

corset.plot.fig_to_png(fig) bytes#

Convert a Matplotlib figure to a PNG as bytes.

Parameters:

fig (Figure) – The figure to convert.

Return type:

bytes

Returns:

The PNG representation of the figure as bytes.

corset.plot.plot_mode_match_solution_all(self, *, plot_kwargs={}, reachability_kwargs={}, sensitivity_kwargs={}) tuple[Figure, tuple[ModeMatchingPlot, ReachabilityPlot, SensitivityPlot]]#

Plot the mode matching solution setup, reachability analysis, and sensitivity analysis in a single figure.

Parameters:
  • self (ModeMatchingSolution) – The mode matching solution instance.

  • plot_kwargs (dict, default: {}) – Additional keyword arguments for the mode matching plot.

  • reachability_kwargs (dict, default: {}) – Additional keyword arguments for the reachability plot.

  • sensitivity_kwargs (dict, default: {}) – Additional keyword arguments for the sensitivity plot.

Return type:

tuple[Figure, tuple[ModeMatchingPlot, ReachabilityPlot, SensitivityPlot]]

Returns:

A tuple containing the figure and an inner tuple with the three plot objects.

corset.plot.plot_mode_match_solution_setup(self, *, ax=None) ModeMatchingPlot#

Plot the mode matching solution setup including the desired beam and constraints.

Parameters:
  • self (ModeMatchingSolution) – The mode matching solution instance.

  • ax (Axes | None, default: None) – The axes to plot on. If None, the current axes are used.

Return type:

ModeMatchingPlot

Returns:

An ModeMatchingPlot containing references to the plot elements.

corset.plot.plot_optical_setup(self, *, ax=None, points=None, limits=None, beam_kwargs={'alpha': 0.5, 'color': 'C0'}, free_lenses=[]) OpticalSetupPlot#

Plot the the beam profile and optical elements of the setup.

Parameters:
  • self (OpticalSetup) – The optical setup instance.

  • ax (Axes | None, default: None) – The axes to plot on. If None, the current axes are used.

  • points (int | ndarray | None, default: None) – Number of points or specific z-coordinates to evaluate the beam profile. If None, 500 points are used.

  • limits (tuple[float, float] | None, default: None) – Z-coordinate limits for the plot. If None, limits are determined from the beam and elements.

  • beam_kwargs (dict, default: {'color': 'C0', 'alpha': 0.5}) – Additional keyword arguments passed to the beam plot.

  • free_lenses (list[int], default: []) – Indices of lenses to treat as free elements in the plot.

Return type:

OpticalSetupPlot

Returns:

An OpticalSetupPlot containing references to the plot elements.

corset.plot.plot_reachability(self, *, displacement=0.005, num_samples=7, grid_step=2, dimensions=None, focus_range=None, waist_range=None, ax=None) ReachabilityPlot#

Plot a reachability analysis of the mode matching solution.

Parameters:
  • self (ModeMatchingSolution) – The mode matching solution instance.

  • displacement (float | list[float], default: 0.005) – Maximum displacement from the optimal position(s) in meters.

  • num_samples (int | list[int], default: 7) – Number of samples to take along each dimension.

  • grid_step (int | list[int], default: 2) – Step size to skip certain lines for increased smoothness while retaining clarity.

  • dimensions (list[int] | None, default: None) – Indices of the dimensions to analyze. If None, all dimensions are used.

  • focus_range (tuple[float, float] | None, default: None) – Range of focus values to display on the x-axis. If None, determined automatically.

  • waist_range (tuple[float, float] | None, default: None) – Range of waist values to display on the y-axis. If None, determined automatically.

  • ax (Axes | None, default: None) – The axes to plot on. If None, the current axes are used.

Return type:

ReachabilityPlot

Returns:

A ReachabilityPlot containing references to the plot elements.

corset.plot.plot_sensitivity(self, *, dimensions=None, worst_overlap=0.98, x_range=None, y_range=None, z_range=None, z_n=3, force_contours=False, ax=None) SensitivityPlot#

Plot a sensitivity analysis of the mode matching solution.

Parameters:
  • self (ModeMatchingSolution) – The mode matching solution instance.

  • dimensions (tuple[int, int] | tuple[int, int, int] | None, default: None) – Indices of the dimensions to analyze. If None, the two least coupled dimensions are used as the x and y dimensions, and the remaining most sensitive dimension is used as the auxiliary z dimension if applicable.

  • worst_overlap (float, default: 0.98) – Worst-case mode overlap contour line that should still be fully visible in the plot.

  • x_range (tuple[float, float] | None, default: None) – Range of x-axis values to display. If None, determined automatically from worst_overlap.

  • y_range (tuple[float, float] | None, default: None) – Range of y-axis values to display. If None, determined automatically from worst_overlap.

  • z_range (tuple[float, float] | None, default: None) – Range of z-axis values to display. If None, determined automatically from worst_overlap.

  • z_n (int, default: 3) – Number of z-slices to plot if 3 dimensions are used.

  • force_contours (bool, default: False) – If True, always use contour lines instead of filled contours for plots with two degrees of freedom.

  • ax (Axes | None, default: None) – The axes to plot on. If None, the current axes are used.

Return type:

SensitivityPlot

Returns:

A SensitivityPlot containing references to the plot elements.

corset.plot.RELATIVE_MARGIN = 0.1#

Relative margin size for plotting optical setups

corset.plot.micro_formatter = <matplotlib.ticker.FuncFormatter object>#

Formatter for micrometer axes

corset.plot.milli_formatter = <matplotlib.ticker.FuncFormatter object>#

Formatter for millimeter axes