psf.fft

FFT Point Spread Function (PSF) Module

This module provides functionality for simulating and analyzing the Point Spread Function (PSF) of optical systems using the Fast Fourier Transform (FFT). It includes capabilities for generating PSF from given wavefront aberrations and calculating the Strehl ratio. Visualization is handled by the base class.

Kramer Harrison, 2023

Functions

calculate_grid_size(num_rays)

Calculates the effective pupil sampling and grid size based on the number of rays.

Classes

FFTPSF(optic, field, wavelength[, num_rays, ...])

Factory class for generating either a Vectorial or Scalar FFT PSF.

ScalarFFTPSF(optic, field, wavelength[, ...])

Class representing the scalar Fast Fourier Transform (FFT) PSF.

class FFTPSF(optic, field, wavelength: str | float, num_rays=128, grid_size=None, strategy='chief_ray', remove_tilt=False, **kwargs)[source]

Factory class for generating either a Vectorial or Scalar FFT PSF.

This class inspects the optical system’s polarization state to determine which FFT PSF implementation to instantiate. If polarization is enabled, it returns a VectorialFFTPSF. Otherwise, it returns a ScalarFFTPSF.

Parameters:
  • optic (Optic) – The optical system object.

  • field (tuple) – The field point.

  • wavelength (str | float) – The wavelength of light.

  • num_rays (int, optional) – The number of rays to trace. Defaults to 128.

  • grid_size (int, optional) – The FFT grid size. Defaults to None.

  • strategy (str) – The wavefront calculation strategy. Defaults to “chief_ray”.

  • remove_tilt (bool) – If True, removes tilt from OPD. Defaults to False.

  • **kwargs – Additional keyword arguments.

class ScalarFFTPSF(optic, field, wavelength: str | float, num_rays=128, grid_size=None, strategy='chief_ray', remove_tilt=False, **kwargs)[source]

Class representing the scalar Fast Fourier Transform (FFT) PSF.

This class computes the PSF of an optical system by taking the Fourier Transform of the pupil function. It inherits common visualization and initialization functionalities from BasePSF.

If no grid size is specified, OpticStudio’s FFT PSF sampling behavior is emulated by scaling down the number of rays in the pupil and using a grid size of num_rays * 2.

Parameters:
  • optic (Optic) – The optical system object, containing properties like paraxial data and surface information.

  • field (tuple) – The field point (e.g., (Hx, Hy) in normalized field coordinates) at which to compute the PSF.

  • wavelength (str | float) – The wavelength of light in micrometers. Can be ‘primary’ or a float value.

  • num_rays (int, optional) – The number of rays used to sample the pupil plane along one dimension. The pupil will be a grid of num_rays x num_rays. Defaults to 128.

  • grid_size (int, optional) – The size of the grid used for FFT computation (includes zero-padding). This determines the resolution of the PSF. Defaults to 1024. If not specified, it is calculated based on num_rays.

  • strategy (str) – The calculation strategy to use. Supported options are “chief_ray”, “centroid_sphere”, and “best_fit_sphere”. Defaults to “chief_ray”.

  • remove_tilt (bool) – If True, removes tilt and piston from the OPD data. Defaults to False.

  • **kwargs – Additional keyword arguments passed to the strategy.

pupils

A list of complex-valued pupil functions, one for each wavelength used in the Wavefront parent. Each pupil is a 2D array.

Type:

list[be.ndarray]

psf

The computed Point Spread Function. This is a 2D array representing the intensity distribution in the image plane, normalized such that a diffraction-limited system has a peak of 100.

Type:

be.ndarray

grid_size

The size of the grid used for FFT computation.

Type:

int

num_rays

The number of rays used to sample the pupil. This is the num_rays passed during initialization and used by Wavefront for generating OPD/intensity data.

Type:

int

static fit_and_remove_tilt(data: WavefrontData, remove_piston: bool = False, ridge: float = 1e-12) be.ndarray

Removes piston and tilt from OPD data using weighted least squares.

Parameters:
  • data (WavefrontData) – The wavefront data containing pupil coordinates and OPD.

  • remove_piston (bool, optional) – If True, removes piston term as well as tilt. Defaults to False.

  • ridge (float, optional) – Small diagonal regularization for stability. Defaults to 1e-12.

Returns:

OPD with piston and tilt removed, shape (N,).

Return type:

opd_detrended (be.ndarray)

get_data(field: tuple[float, float], wl: float) WavefrontData

Retrieves precomputed wavefront data for a field and wavelength.

Parameters:
  • field (tuple[float, float]) – The field coordinates, or a FieldPoint.

  • wl (float) – The wavelength in µm, or a WavelengthPoint.

Returns:

A data container with the computed wavefront results.

Return type:

WavefrontData

strehl_ratio()

Computes the Strehl ratio of the PSF.

The Strehl ratio is the ratio of the peak intensity of the aberrated PSF to the peak intensity of the diffraction-limited PSF. Assumes self.psf is normalized such that its peak would be 1.0 (or 100%) for a diffraction-limited system.

Returns:

The Strehl ratio.

Return type:

float

Raises:

RuntimeError – If the PSF has not been computed.

view(fig_to_plot_on: Figure | None = None, projection: str = '2d', log: bool = False, figsize: tuple = (7, 5.5), threshold: float = 0.05, num_points: int = 128) tuple[Figure, Axes]

Visualizes the PSF.

Parameters:
  • projection (str, optional) – The projection type. Can be ‘2d’ or ‘3d’. Defaults to ‘2d’.

  • log (bool, optional) – Whether to use a logarithmic scale for the intensity. Defaults to False.

  • figsize (tuple, optional) – The figure size. Defaults to (7, 5.5).

  • threshold (float, optional) – The threshold for determining the bounds of the PSF for zoomed view. Defaults to 0.05.

  • num_points (int, optional) – The number of points used for interpolating the PSF for smoother visualization. Defaults to 128.

Returns:

A tuple containing the figure and axes objects.

Return type:

tuple

Raises:
  • RunentimeError – If the PSF has not been computed.

  • ValueError – If the projection is not ‘2d’ or ‘3d’.

  • RuntimeError – If the PSF has not been computed by the subclass.

calculate_grid_size(num_rays) tuple[int, int][source]

Calculates the effective pupil sampling and grid size based on the number of rays.

See https://ansyshelp.ansys.com/public/account/secured?returnurl=/Views/Secured/Zemax/v251/en/OpticStudio_User_Guide/OpticStudio_Help/topics/FFT_PSF.html for details on OpticStudio’s FFT PSF sampling behavior.

Parameters:

num_rays (int) – The number of rays used to sample the pupil.

Returns:

The effective pupil sampling size, which is the number of rays

used to sample the pupil in one dimension.

int: The grid size used for FFT computation.

Return type:

int