analysis.through_focus_mtf
Through Focus MTF
This module provides a class for performing through-focus MTF analysis, calculating the MTF at various focal planes for a given spatial frequency, wavelength, and fields.
Kramer Harrison, 2025
Classes
|
Performs Modulation Transfer Function (MTF) analysis across a range of focal positions. |
- class ThroughFocusMTF(optic, spatial_frequency: float, delta_focus: float = 0.1, num_steps: int = 5, fields: list[tuple[float, float]] | str = 'all', wavelength: float | str = 'primary', num_rays: int = 128)[source]
Performs Modulation Transfer Function (MTF) analysis across a range of focal positions.
This class calculates the MTF at a specified spatial frequency for both tangential and sagittal orientations at multiple focal planes around the nominal focus of an optical system.
The results include tangential and sagittal MTF values for each analyzed field at each focal step.
- Parameters:
optic – The optiland.optic.Optic object to analyze.
spatial_frequency (float) – The single spatial frequency (in cycles/mm) at which to calculate MTF. The calculation will be performed for both tangential (fx = spatial_frequency, fy = 0) and sagittal (fx = 0, fy = spatial_frequency) orientations.
delta_focus (float, optional) – The increment of focal shift in mm. Defaults to 0.1.
num_steps (int, optional) – The number of focal planes to analyze before and after the nominal focus. Must be an odd integer. Defaults to 5.
fields (list[tuple[float, float]] | str, optional) – Fields for analysis. If “all”, uses all fields from optic.fields. Defaults to “all”.
wavelength (float | str, optional) – The wavelength (in µm) for analysis. If “primary”, uses the primary wavelength from optic.primary_wavelength. Defaults to “primary”.
num_rays (int, optional) – The number of rays across the pupil in 1D for the SampledMTF calculation. Defaults to 64.
- MAX_STEPS = 15
- MIN_STEPS = 1
- view(fig_to_plot_on: Figure | None = None, figsize: tuple[float, float] = (12, 4), *, show: bool = True) tuple[Figure, Axes][source]
Visualizes the through-focus Modulation Transfer Function (MTF) results for each analyzed field.
This method generates a plot of tangential and sagittal MTF values as a function of defocus for each field position. If enough data points are available, spline smoothing is applied to the MTF data to produce smoother curves. Otherwise, raw data points are plotted. The plot displays MTF at the spatial frequency specified during initialization.
- Parameters:
fig_to_plot_on (plt.Figure, optional) – An existing matplotlib Figure to plot on. If provided, the plot will be embedded in this figure. If None (default), a new figure will be created.
figsize (tuple of float, optional) – Size of the figure to create if fig_to_plot_on is None. Default is (12, 4).
show (bool, optional) – If True (default), calls plt.show(). Set False for headless use.
- Returns:
The matplotlib Figure and Axes objects containing the plot.
- Return type:
tuple[Figure, Axes]
Notes
Spline smoothing uses cubic splines if at least 4 data points are available,
linear splines for 2-3 points, and raw data is plotted if fewer points are present. - The legend displays the field coordinates (Hx, Hy) for each curve. - The plot includes grid lines and is formatted for clarity.