prysm.otf

A base optical transfer function interface.

class prysm.otf.OTF(mtf, ptf)

Bases: object

Optical Transfer Function.

static from_psf(psf, unwrap=True)

Create an OTF instance from a PSF.

Parameters
  • psf (PSF) – Point Spread Function

  • unwrap (bool, optional) – if True, unwrap phase

Returns

new OTF instance with mtf and PSF attributes holding MTF and PSF instances

Return type

OTF

class prysm.otf.MTF(data, x, y, xy_unit=None, z_unit=None, labels=None)

Bases: prysm._richdata.RichData

Modulation Transfer Function.

static from_psf(psf)

Generate an MTF from a PSF.

Parameters

psf (PSF) – PSF to compute an MTF from

Returns

A new MTF instance

Return type

MTF

static from_pupil(pupil, efl, Q=2)

Generate an MTF from a pupil, given a focal length (propagation distance).

Parameters
  • pupil (Pupil) – A pupil to propagate to a PSF, and convert to an MTF

  • efl (float) – Effective focal length or propagation distance of the wavefunction

  • Q (float) – ratio of pupil sample count to PSF sample count. Q > 2 satisfies nyquist

Returns

A new MTF instance

Return type

MTF

static from_ftdata(ft, x, y)

Generate an MTF from the Fourier transform of a PSF.

Parameters
  • ft (numpy.ndarray) – 2D ndarray of Fourier transform data

  • x (numpy.ndarray) – 1D ndarray of x (axis 1) coordinates

  • y (numpy.ndarray) – 1D ndarray of y (axis 0) coordinates

Returns

a new MTF instance

Return type

MTF

astype(other_type)

Change this instance of one type into another.

Useful to access methods of the other class.

Parameters

other_type (object) – the name of the other type to “cast” to, e.g. Interferogram. Not a string.

Returns

type-converted to the other type.

Return type

self

center_x

Center “pixel” in x.

center_y

Center “pixel” in y.

change_xy_unit(to, inplace=True)

Change the x/y unit to a new one, scaling the data in the process.

Parameters
  • to (astropy.unit or str) – if not an astropy unit, a string that is a valid attribute of astropy.units.

  • inplace (bool, optional) – if True, returns self. Otherwise returns the modified data.

Returns

  • RichData – self, if inplace=True

  • numpy.ndarray, numpy.ndarray – x, y from self, if inplace=False

change_z_unit(to, inplace=True)

Change the z unit to a new one, scaling the data in the process.

Parameters
  • to (astropy.unit or str) – if not an astropy unit, a string that is a valid attribute of astropy.units.

  • inplace (bool, optional) – if True, returns self. Otherwise returns the modified data.

Returns

  • RichData – self, if inplace=True

  • numpy.ndarray – data from self, if inplace=False

copy()

Return a (deep) copy of this instance.

exact_polar(rho, phi=None)

Retrieve data at the specified radial coordinates pairs.

Parameters
  • rho (iterable) – radial coordinate(s) to sample

  • phi (iterable) – azimuthal coordinate(s) to sample

Returns

data at the given points

Return type

numpy.ndarray

exact_x(x)

Return data at an exact x coordinate along the y=0 axis.

Parameters

x (number or numpy.ndarray) – x coordinate(s) to return

Returns

ndarray of values

Return type

numpy.ndarray

exact_xy(x, y=None)

Retrieve data at the specified X-Y frequency pairs.

Parameters
  • x (iterable) – X coordinate(s) to retrieve

  • y (iterable) – Y coordinate(s) to retrieve

Returns

data at the given points

Return type

numpy.ndarray

exact_y(y)

Return data at an exact y coordinate along the x=0 axis.

Parameters

y (number or numpy.ndarray) – y coordinate(s) to return

Returns

ndarray of values

Return type

numpy.ndarray

plot2d(xlim=None, ylim=None, clim=None, cmap=None, log=False, power=1, interpolation=None, show_colorbar=True, show_axlabels=True, fig=None, ax=None)

Plot the data in 2D.

Parameters
  • xlim (float or iterable, optional) – x axis limits. If not iterable, symmetric version of the single value

  • ylim (float or iterable, optional) – y axis limits. If None and xlim is not None, copied from xlim. If not iterable, symmetric version of the single value.

  • clim (iterable, optional) – clim passed directly to matplotlib. If None, looked up on self._default_clim.

  • cmap (str, optional) – colormap to use, passed directly to matplotlib if not None. If None, looks up the default cmap for self._data_type on config

  • log (bool, optional) – if True, plot on a log color scale

  • power (float, optional) – if not 1, plot on a power stretched color scale

  • interpolation (str, optional) – interpolation method to use, passed directly to matplotlib

  • show_colorbar (bool, optional) – if True, draws the colorbar

  • show_axlabels (bool, optional) – if True, draws the axis labels

  • fig (matplotlib.figure.Figure) – Figure containing the plot

  • ax (matplotlib.axes.Axis) – Axis containing the plot

Returns

  • fig (matplotlib.figure.Figure) – Figure containing the plot

  • ax (matplotlib.axes.Axis) – Axis containing the plot

sample_spacing

center-to-center sample spacing.

samples_x

Number of samples in the x dimension.

samples_y

Number of samples in the y dimension.

shape

Proxy to phase or data shape.

size

Proxy to phase or data size.

slices(twosided=None)

Create a Slices instance from this instance.

Parameters

twosided (bool, optional) – if None, copied from self._default_twosided

Returns

a Slices object

Return type

Slices

class prysm.otf.PTF(data, x, y, xy_unit=None, z_unit=None, labels=None)

Bases: prysm._richdata.RichData

Phase Transfer Function.

static from_psf(psf, unwrap=True)

Generate a PTF from a PSF.

Parameters
  • psf (PSF) – PSF to compute an MTF from

  • unwrap (bool, optional) – whether to unwrap the phase

Returns

A new PTF instance

Return type

PTF

static from_pupil(pupil, efl, Q=2, unwrap=True)

Generate a PTF from a pupil, given a focal length (propagation distance).

Parameters
  • pupil (Pupil) – A pupil to propagate to a PSF, and convert to an MTF

  • efl (float) – Effective focal length or propagation distance of the wavefunction

  • Q (float, optional) – ratio of pupil sample count to PSF sample count. Q > 2 satisfies nyquist

  • unwrap (bool, optional) – whether to unwrap the phase

Returns

A new PTF instance

Return type

PTF

static from_ftdata(ft, x, y, unwrap=True)

Generate a PTF from the Fourier transform of a PSF.

Parameters
  • ft (numpy.ndarray) – 2D ndarray of Fourier transform data

  • x (numpy.ndarray) – 1D ndarray of x (axis 1) coordinates

  • y (numpy.ndarray) – 1D ndarray of y (axis 0) coordinates

  • unwrap (bool, optional) – if True, unwrap phase

Returns

a new PTF instance

Return type

PTF

astype(other_type)

Change this instance of one type into another.

Useful to access methods of the other class.

Parameters

other_type (object) – the name of the other type to “cast” to, e.g. Interferogram. Not a string.

Returns

type-converted to the other type.

Return type

self

center_x

Center “pixel” in x.

center_y

Center “pixel” in y.

change_xy_unit(to, inplace=True)

Change the x/y unit to a new one, scaling the data in the process.

Parameters
  • to (astropy.unit or str) – if not an astropy unit, a string that is a valid attribute of astropy.units.

  • inplace (bool, optional) – if True, returns self. Otherwise returns the modified data.

Returns

  • RichData – self, if inplace=True

  • numpy.ndarray, numpy.ndarray – x, y from self, if inplace=False

change_z_unit(to, inplace=True)

Change the z unit to a new one, scaling the data in the process.

Parameters
  • to (astropy.unit or str) – if not an astropy unit, a string that is a valid attribute of astropy.units.

  • inplace (bool, optional) – if True, returns self. Otherwise returns the modified data.

Returns

  • RichData – self, if inplace=True

  • numpy.ndarray – data from self, if inplace=False

copy()

Return a (deep) copy of this instance.

exact_polar(rho, phi=None)

Retrieve data at the specified radial coordinates pairs.

Parameters
  • rho (iterable) – radial coordinate(s) to sample

  • phi (iterable) – azimuthal coordinate(s) to sample

Returns

data at the given points

Return type

numpy.ndarray

exact_x(x)

Return data at an exact x coordinate along the y=0 axis.

Parameters

x (number or numpy.ndarray) – x coordinate(s) to return

Returns

ndarray of values

Return type

numpy.ndarray

exact_xy(x, y=None)

Retrieve data at the specified X-Y frequency pairs.

Parameters
  • x (iterable) – X coordinate(s) to retrieve

  • y (iterable) – Y coordinate(s) to retrieve

Returns

data at the given points

Return type

numpy.ndarray

exact_y(y)

Return data at an exact y coordinate along the x=0 axis.

Parameters

y (number or numpy.ndarray) – y coordinate(s) to return

Returns

ndarray of values

Return type

numpy.ndarray

plot2d(xlim=None, ylim=None, clim=None, cmap=None, log=False, power=1, interpolation=None, show_colorbar=True, show_axlabels=True, fig=None, ax=None)

Plot the data in 2D.

Parameters
  • xlim (float or iterable, optional) – x axis limits. If not iterable, symmetric version of the single value

  • ylim (float or iterable, optional) – y axis limits. If None and xlim is not None, copied from xlim. If not iterable, symmetric version of the single value.

  • clim (iterable, optional) – clim passed directly to matplotlib. If None, looked up on self._default_clim.

  • cmap (str, optional) – colormap to use, passed directly to matplotlib if not None. If None, looks up the default cmap for self._data_type on config

  • log (bool, optional) – if True, plot on a log color scale

  • power (float, optional) – if not 1, plot on a power stretched color scale

  • interpolation (str, optional) – interpolation method to use, passed directly to matplotlib

  • show_colorbar (bool, optional) – if True, draws the colorbar

  • show_axlabels (bool, optional) – if True, draws the axis labels

  • fig (matplotlib.figure.Figure) – Figure containing the plot

  • ax (matplotlib.axes.Axis) – Axis containing the plot

Returns

  • fig (matplotlib.figure.Figure) – Figure containing the plot

  • ax (matplotlib.axes.Axis) – Axis containing the plot

sample_spacing

center-to-center sample spacing.

samples_x

Number of samples in the x dimension.

samples_y

Number of samples in the y dimension.

shape

Proxy to phase or data shape.

size

Proxy to phase or data size.

slices(twosided=None)

Create a Slices instance from this instance.

Parameters

twosided (bool, optional) – if None, copied from self._default_twosided

Returns

a Slices object

Return type

Slices

prysm.otf.diffraction_limited_mtf(fno, wavelength, frequencies=None, samples=128)

Give the diffraction limited MTF for a circular pupil and the given parameters.

Parameters
  • fno (float) – f/# of the lens.

  • wavelength (float) – wavelength of light, in microns.

  • frequencies (numpy.ndarray) – spatial frequencies of interest, in cy/mm if frequencies are given, samples is ignored.

  • samples (int) – number of points in the output array, if frequencies not given.

Returns

  • if frequencies not given

    frequenciesnumpy.ndarray

    array of ordinate data

    mtfnumpy.ndarray

    array of coordinate data

  • else

    mtfnumpy.ndarray

    array of MTF data

Notes

If frequencies are given, just returns the MTF. If frequencies are not given, returns both the frequencies and the MTF.

prysm.otf.longexposure_otf(nu, Cn, z, f, lambdabar, h_z_by_r=2.91)

Compute the long exposure OTF for given parameters.

Parameters
  • nu (numpy.ndarray) – spatial frequencies, cy/mm

  • Cn (float) – atmospheric structure constant of refractive index, ranges ~ 10^-13 - 10^-17

  • z (float) – propagation distance through atmosphere, m

  • f (float) – effective focal length of the optical system, mm

  • lambdabar (float) – mean wavelength, microns

  • h_z_by_r (float, optional) – constant for h[z/r] – see Eq. 8.5-37 & 8.5-38 in Statistical Optics, J. Goodman, 2nd ed.

Returns

the OTF

Return type

numpy.ndarray

prysm.otf.komogorov(r, r0)

Calculate the phase structure function D_phi in the komogorov approximation.

Parameters
  • r (numpy.ndarray) – r, radial frequency parameter (object space)

  • r0 (float) – Fried parameter

Returns

Return type

numpy.ndarray

prysm.otf.estimate_Cn(P=1013, T=273.15, Ct=0.0001)

Use Weng et al to estimate Cn from meteorological data.

Parameters
  • P (float) – atmospheric pressure in hPa

  • T (float) – temperature in Kelvin

  • Ct (float) – atmospheric struction constant of temperature, typically 10^-5 - 10^-2 near the surface

Returns

Cn

Return type

float