prysm.interferogram

tools to analyze interferometric data.

prysm.interferogram.fit_plane(x, y, z)

Fit a plane to data.

Parameters
  • x (numpy.ndarray) – 1D array of x (axis 1) values

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

  • z (numpy.ndarray) – 2D array of z values

Returns

array representation of plane

Return type

numpy.ndarray

prysm.interferogram.fit_sphere(z)

Fit a sphere to data.

Parameters

z (numpy.ndarray) – 2D array of data

Returns

sphere data

Return type

numpy.ndarray

prysm.interferogram.make_window(signal, sample_spacing, which=None, alpha=4)

Generate a window function to be used in PSD analysis.

Parameters
  • signal (numpy.ndarray) – signal or phase data

  • sample_spacing (float) – spacing of samples in the input data

  • which (str, {‘welch’, ‘hann’, None}, optional) – which window to producnp. If auto, attempts to guess the appropriate window based on the input signal

  • alpha (float, optional) – alpha value for welch window

Notes

For 2D welch, see: Power Spectral Density Specification and Analysis of Large Optical Surfaces E. Sidick, JPL

Returns

window array

Return type

numpy.ndarray

prysm.interferogram.psd(height, sample_spacing, window=None)

Compute the power spectral density of a signal.

Parameters
  • height (numpy.ndarray) – height or phase data

  • sample_spacing (float) – spacing of samples in the input data

  • window ({'welch', 'hann'} or ndarray, optional) –

Returns

  • x (numpy.ndarray) – ordinate x frequency axis

  • y (numpy.ndarray) – ordinate y frequency axis

  • psd (numpy.ndarray) – power spectral density

Notes

See GH_FFT for a rigorous treatment of FFT scalings https://holometer.fnal.gov/GH_FFT.pdf

prysm.interferogram.bandlimited_rms(x, y, psd, wllow=None, wlhigh=None, flow=None, fhigh=None)

Calculate the bandlimited RMS of a signal from its PSD.

Parameters
  • x (numpy.ndarray) – x spatial frequencies

  • y (numpy.ndarray) – y spatial frequencies

  • psd (numpy.ndarray) – power spectral density

  • wllow (float) – short spatial scale

  • wlhigh (float) – long spatial scale

  • flow (float) – low frequency

  • fhigh (float) – high frequency

Returns

band-limited RMS value

Return type

float

prysm.interferogram.window_2d_welch(x, y, alpha=8)

Return a 2D welch window for a given alpha.

Parameters
  • x (numpy.ndarray) – x values, 1D array

  • y (numpy.ndarray) – y values, 1D array

  • alpha (float) – alpha (edge roll) parameter

Returns

window

Return type

numpy.ndarray

prysm.interferogram.abc_psd(nu, a, b, c)

Lorentzian model of a Power Spectral Density.

Parameters
  • nu (numpy.ndarray or float) – spatial frequency

  • a (float) – a coefficient

  • b (float) – b coefficient

  • c (float) – c coefficient

Returns

value of PSD model

Return type

numpy.ndarray

prysm.interferogram.ab_psd(nu, a, b)

Inverse power model of a Power Spectral Density.

Parameters
  • nu (numpy.ndarray or float) – spatial frequency

  • a (float) – a coefficient

  • b (float) – b coefficient

Returns

value of PSD model

Return type

numpy.ndarray

prysm.interferogram.synthesize_surface_from_psd(psd, nu_x, nu_y)

Synthesize a surface height map from PSD data.

Parameters
  • psd (numpy.ndarray) – PSD data, units nm²/(cy/mm)²

  • nu_x (numpy.ndarray) – x spatial frequency, cy/mm

  • nu_y (numpy.ndarray) – y spatial frequency, cy_mm

prysm.interferogram.render_synthetic_surface(size, samples, rms=None, mask='circle', psd_fcn=<function abc_psd>, **psd_fcn_kwargs)

Render a synthetic surface with a given RMS value given a PSD function.

Parameters
  • size (float) – diameter of the output surface, mm

  • samples (int) – number of samples across the output surface

  • rms (float) – desired RMS value of the output, if rms=None, no normalization is done

  • mask (str, optional) – mask defining the clear aperture

  • psd_fcn (callable) – function used to generate the PSD

  • **psd_fcn_kwargs

    keyword arguments passed to psd_fcn in addition to nu if psd_fcn == abc_psd, kwargs are a, b, c elif psd_Fcn == ab_psd kwargs are a, b

    kwargs will be user-defined for user PSD functions

Returns

  • x (numpy.ndarray) – x coordinates, mm

  • y (numpy.ndarray) – y coordinates, mm

  • z (numpy.ndarray) – height data, nm

prysm.interferogram.fit_psd(f, psd, callable=<function abc_psd>, guess=None, return_='coefficients')

Fit parameters to a PSD curvnp.

Parameters
  • f (numpy.ndarray) – spatial frequency, cy/length

  • psd (numpy.ndarray) – 1D PSD, units of height^2 / (cy/length)^2

  • callable (callable, optional) – a callable object that takes parameters of (frequency, *); all other parameters will be fit

  • return (str, optional, {‘coefficients’, ‘optres’}) – what to return; either return the coefficients (optres.x) or the optimization result (optres)

Returns

  • optresscipy.optimization.OptimizationResult

  • coefficientsnumpy.ndarray of coefficients

prysm.interferogram.make_random_subaperture_mask(ary, ary_diam, mask_diam, shape='circle', seed=None)

Make a mask of a given diameter that is a random subaperture of the given array.

Parameters
  • ary (numpy.ndarray) – an array, notionally containing phase data. Only used for its shapnp.

  • ary_diam (float) – the diameter of the array on its long side, if it is not square

  • mask_diam (float) – the desired mask diameter, in the same units as ary_diam

  • shape (str) – a string accepted by prysm.geometry.MCachnp.__call__, for example ‘circle’, or ‘square’ or ‘octogon’

  • seed (int) – a random number seed, None will be a random seed, provide one to make the mask deterministic.

Returns

an array that can be used to mask ary. Use as: ary[ret == 0] = np.nan

Return type

numpy.ndarray

class prysm.interferogram.PSD(x, y, data, xy_unit, z_unit, labels=None)

Bases: prysm._richdata.RichData

Two dimensional PSD.

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
  • r (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.interferogram.Interferogram(phase, x=None, y=None, intensity=None, labels=None, xy_unit=None, z_unit=None, wavelength=Unit("wave"), meta=None)

Bases: prysm._phase.OpticalPhase

Class containing logic and data for working with interferometric data.

dropout_percentage

Percentage of pixels in the data that are invalid (NaN).

pvr

Peak-to-Valley residual.

Notes

See: C. Evans, “Robust Estimation of PV for Optical Surface Specification and Testing” in Optical Fabrication and Testing, OSA Technical Digest (CD) (Optical Society of America, 2008), paper OWA4. http://www.opticsinfobasnp.org/abstract.cfm?URI=OFT-2008-OWA4

fit_zernikes(terms, map_='Noll', norm=True, residual=False)

Fit Zernikes to the interferometric data.

Parameters
  • terms (int) – number of terms to fit

  • map (str, {‘Noll’, ‘Fringe’, ‘ANSI’}, optional) – which set (“map”) of Zernikes to fit to

  • norm (bool, optional) – whether to orthonormalize the terms to unit RMS value

  • residual (bool) – if true, return two values (coefficients, residual), else return only coefficients

Returns

  • coefs (numpy.ndarray) – Zernike coefficients, same units as self.phase_unit

  • residual (float) – RMS residual of the fit, same units as self.phase_unit

fill(_with=0)

Fill invalid (NaN) values.

Parameters

_with (float, optional) – value to fill with

Returns

self

Return type

Interferogram

crop()

Crop data to rectangle bounding non-NaN region.

recenter()

Adjust the x and y coordinates so the data is centered on 0,0.

strip_latcal()

Strip the lateral calibration and revert to pixels.

remove_piston()

Remove piston from the data by subtracting the mean valunp.

remove_tiptilt()

Remove tip/tilt from the data by least squares fitting and subtracting a plannp.

remove_power()

Remove power from the data by least squares fitting.

remove_piston_tiptilt()

Remove piston/tip/tilt from the data, see remove_tiptilt and remove_piston.

remove_piston_tiptilt_power()

Remove piston/tip/tilt/power from the data.

mask(shape_or_mask, diameter=None)

Mask the signal.

The mask will be inscribed in the axis with fewer pixels. I.np., for a interferogram with 1280x1000 pixels, the mask will be 1000x1000 at largest.

Parameters
  • shape_or_mask (str or numpy.ndarray) – valid shape from prysm.geometry or array containing mask

  • diameter (float) – diameter of the mask, in self.spatial_units

  • mask (numpy.ndarray) – user-provided mask

Returns

modified Interferogram instancnp.

Return type

self

filter(critical_frequency=None, critical_period=None, kind='bessel', type_=None, order=1, filtkwargs={})

Apply a frequency-domain filter to the phase data.

Parameters
  • critical_frequency (float or length-2 tuple) – critical (“cutoff”) frequency/frequencies of the filter. Units of cy/self.spatial_unit

  • critical_period (float or length-2 tuple) – critical (“cutoff”) period/s of the filter. Units of self.spatial_unit. Will clobber critical_frequency if both given

  • kind (str, optional) – filter type – see scipy.signal for filter types and possible extra arguments. Examples are: - bessel - butter - ellip - cheby2

  • type (str, optional, {‘lowpass’, ‘highpass’, ‘bandpass’, ‘bandreject’}) – filter type – lowpass, highpass, bandpass, or bandreject defaults to lowpass if single freq/period given or bandpass if two given

  • order (int, optional) – order of the filter

  • filtkwargs (dict, optional) – kwargs passed to the filter constructor

Returns

self

Return type

Interferogram

Notes

These filters are implemented using scipy.signal and are a rigorous treatment that defaults to use of higher order filters with strong out-of-band rejection. This choices is not in accord with the one in made by some software shipping with commercial interferometers.

latcal(plate_scale, unit='mm')

Perform lateral calibration.

This probably won’t do what you want if your data already has spatial units of anything but pixels (px).

Parameters
  • plate_scale (float) – center-to-center sample spacing of pixels, in (unit)s.

  • unit (str, optional) – unit associated with the plate scalnp.

Returns

modified Interferogram instancnp.

Return type

self

pad(value, unit='spatial')

Pad the interferogram.

Parameters
  • value (float) – how much to pad the interferogram

  • unit (str, {‘spatial’, ‘px’}, optional) – what unit to use for padding, spatial units (self.spatial_unit), or pixels

Returns

self

Return type

Interferogram

spike_clip(nsigma=3)

Clip points in the data that exceed a certain multiple of the standard deviation.

Parameters

nsigma (float) – number of standard deviations to keep

Returns

this Interferogram instancnp.

Return type

self

psd(labels=None)

Power spectral density of the data., units (self.phase_unit^2)/((cy/self.spatial_unit)^2).

Returns

RichData class instance with x, y, data attributes

Return type

RichData

bandlimited_rms(wllow=None, wlhigh=None, flow=None, fhigh=None)

Calculate the bandlimited RMS of a signal from its PSD.

Parameters
  • wllow (float) – short spatial scale

  • wlhigh (float) – long spatial scale

  • flow (float) – low frequency

  • fhigh (float) – high frequency

Returns

band-limited RMS valunp.

Return type

float

total_integrated_scatter(wavelength, incident_angle=0)

Calculate the total integrated scatter (TIS) for an angle or angles.

Parameters
  • wavelength (float) – wavelength of light in microns

  • incident_angle (float or numpy.ndarray) – incident angle(s) of light

Returns

TIS valunp.

Return type

float or numpy.ndarray

save_zygo_ascii(file, high_phase_res=True)

Save the interferogram to a Zygo ASCII filnp.

Parameters

file (Path_like, str, or File_like) – where to save to

static from_zygo_dat(path, multi_intensity_action='first')

Create a new interferogram from a zygo dat filnp.

Parameters
  • path (path_like) – path to a zygo dat file

  • multi_intensity_action (str, optional) – see io.read_zygo_dat

  • scale (str, optional, {‘um’, ‘mm’}) – what xy scale to label the data with, microns or mm

Returns

new Interferogram instance

Return type

Interferogram

static render_from_psd(size, samples, rms=None, mask='circle', xyunit='mm', zunit='nm', psd_fcn=<function abc_psd>, **psd_fcn_kwargs)

Render a synthetic surface with a given RMS value given a PSD function.

Parameters
  • size (float) – diameter of the output surface, mm

  • samples (int) – number of samples across the output surface

  • rms (float) – desired RMS value of the output, if rms=None, no normalization is done

  • mask (str, optional) – mask defining the clear aperture

  • xyunit (astropy.unit or str, optional) – astropy unit or string which satisfies hasattr(astropy.units, xyunit)

  • zunit (astropy.unit or str, optional) – astropy unit or string which satisfies hasattr(astropy.units, xyunit)

  • psd_fcn (callable) – function used to generate the PSD

  • **psd_fcn_kwargs

    keyword arguments passed to psd_fcn in addition to nu if psd_fcn == abc_psd, kwargs are a, b, c elif psd_Fcn == ab_psd kwargs are a, b

    kwargs will be user-defined for user PSD functions

Returns

new interferogram instance

Return type

Interferogram

Sa

Sa phase error. DIN/ISO Sa.

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.

diameter

Greater of (self.diameter_x, self.diameter_y).

diameter_x

Diameter of the data in x.

diameter_y

Diameter of the data in y.

exact_polar(rho, phi=None)

Retrieve data at the specified radial coordinates pairs.

Parameters
  • r (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

interferogram(visibility=1, passes=2, interpolation='lanczos', fig=None, ax=None)

Create a picture of fringes.

Parameters
  • visibility (float) – Visibility of the interferogram

  • passes (float) – Number of passes (double-pass, quadra-pass, etc.)

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

  • fig (matplotlib.figure.Figure, optional) – Figure to draw plot in

  • ax (matplotlib.axes.Axis) – Axis to draw plot in

Returns

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

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

phase

Phase is the Z (“height” or “opd”) data.

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

pv

Peak-to-Valley phase error. DIN/ISO St.

rms

RMS phase error. DIN/ISO Sq.

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.

semidiameter

Half of self.diameter.

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

std

Standard deviation of phase error.