prysm.zernike

Zernike functions.

prysm.zernike.piston(rho, phi)

Zernike Piston.

prysm.zernike.tip(rho, phi)

Zernike Tilt-Y.

prysm.zernike.tilt(rho, phi)

Zernike Tilt-X.

prysm.zernike.defocus(rho, phi)

Zernike defocus.

prysm.zernike.primary_astigmatism_00(rho, phi)

Zernike primary astigmatism 0°.

prysm.zernike.primary_astigmatism_45(rho, phi)

Zernike primary astigmatism 45°.

prysm.zernike.primary_coma_y(rho, phi)

Zernike primary coma Y.

prysm.zernike.primary_coma_x(rho, phi)

Zernike primary coma X.

prysm.zernike.primary_spherical(rho, phi)

Zernike primary Spherical.

prysm.zernike.primary_trefoil_y(rho, phi)

Zernike primary trefoil Y.

prysm.zernike.primary_trefoil_x(rho, phi)

Zernike primary trefoil X.

prysm.zernike.zernikes_to_magnitude_angle_nmkey(coefs)

Convert Zernike polynomial set to a magnitude and phase representation.

Parameters

coefs (list of tuples) – a list looking like[(1,2,3),] where (1,2) are the n, m indices and 3 the coefficient

Returns

dict keyed by tuples of (n, |m|) with values of (rho, phi) where rho is the magnitudes, and phi the phase

Return type

dict

prysm.zernike.zernikes_to_magnitude_angle(coefs)

Convert Zernike polynomial set to a magnitude and phase representation.

This function is identical to zernikes_to_magnitude_angle_nmkey, except its keys are strings instead of (n, |m|)

Parameters

coefs (list of tuples) – a list looking like[(1,2,3),] where (1,2) are the n, m indices and 3 the coefficient

Returns

dict keyed by friendly name strings with values of (rho, phi) where rho is the magnitudes, and phi the phase

Return type

dict

prysm.zernike.zernike_norm(n, m)

Norm of a Zernike polynomial with n, m indexing.

prysm.zernike.n_m_to_fringe(n, m)

Convert (n,m) two term index to Fringe index.

prysm.zernike.n_m_to_ansi_j(n, m)

Convert (n,m) two term index to ANSI single term index.

prysm.zernike.ansi_j_to_n_m(idx)

Convert ANSI single term to (n,m) two-term index.

prysm.zernike.noll_to_n_m(idx)

Convert Noll Z to (n, m) two-term index.

prysm.zernike.fringe_to_n_m(idx)

Convert Fringe Z to (n, m) two-term index.

prysm.zernike.zero_separation(n)

Zero separation in normalized r based on radial order n.

prysm.zernike.n_m_to_name(n, m)

Convert an (n,m) index into a human readable name.

Parameters
  • n (int) – radial polynomial order

  • m (int) – azimuthal polynomial order

Returns

a name, e.g. Piston or Primary Spherical

Return type

str

class prysm.zernike.ZCacheMN(gridcache=<prysm.coordinates.GridCache object>)

Bases: object

Cache of Zernike terms evaluated over the unit circle, based on (n, m) indices.

Users should use the call method:

zc = ZcacheMN() n = 2 m = 2 zc(n,m,False) # astigmatism, not normed

The code of this class is complicated by the heavy caching it does. See orthopy for a simpler, but slower implementation.

To understand the code of this class, here are the cliff notes: - Zernikes themselves are cached, as well as all of the pieces of the

computation.

  • Zernike polynomials “are” jacobi polynomials, under two modifications:
    1. the ‘x’ variable is replaced with x = 2r^2 - 1

    2. the order of the jacobi polynomial, n_j, is computed from the Zernike

      order as n_j = (n - m) / 2

    3. the azimuthal component of the Zernike polynomials is simply

      a cosine or sine of (theta * m)

  • A recurrence relation can be used to generate Jacobi polynomials quickly

    and with high numerical stability. This is contained within the get_jacobi method.

  • the grid_bypass method is likely the ‘clearest’ code, since it does

    not deal with any caching mechanisms

get_zernike(n, m, samples, norm)

Get an array of phase values for a given radial order n, azimuthal order m, number of samples, and orthonormalization.

get_term(n, m, samples)

Get a term from the cache.

Parameters
  • n (int) – radial order

  • m (int) – azimuthal order

  • samples (int) – square grid size

Returns

zernike term evaluated over the grid

Return type

numpy.ndarray

grid_bypass(n, m, norm, r, p)

Bypass the grid computation, providing radial coordinates directly.

Notes

To avoid memory leaks, you should use grid_bypass_cleanup after you are finished with this function for a given pair of r, p arrays

Parameters
  • n (int) – radial order

  • m (int) – azimuthal order

  • norm (bool) – whether to orthonormalize the polynomials

  • r (numpy.ndarray) – radial coordinates. Unnormalized in the sense of the coordinate perturbation of the jacobi polynomials. Notionally on a regular grid spanning [0,1]

  • p (numpy.ndarray) – azimuthal coordinates matching r

Returns

zernike polynomial n or m at this coordinate.

Return type

numpy.ndarray

grid_bypass_cleanup(r, p)

Remove data related to r, p from the cache.

Parameters
  • r (numpy.ndarray) – radial coordinates

  • p (numpy.ndarray) – azimuthal coordinates

get_azterm(m, samples)

Retrieve the azimuthally variant term.

Parameters
  • m (int) – azimuthal order

  • samples (int) – number of samples on the (square) grid

Returns

azimuthally variant component

Return type

numpy.ndarray

get_jacobi(n, m, samples, nj=None, r=None)

Retrieve the jacobi polynomial for a given zernike set.

Parameters
  • n (int) – radial order

  • m (int) – azimuthal order

  • samples (int) – square grid size

  • nj (int) – jacobi order, (n-m)/2

  • r (numpy.ndarray, optional) – transformed radial coordinate

Returns

jacobi term evaluated over the grid

Return type

numpy.ndarray

get_grid(samples, modified=True)

Retrieve a grid for a given sample count.

Parameters
  • samples (int) – sample size of the square grid

  • modified (bool, optional) – if True, return the modified grid, r -> 2r^2 - 1 suitable for use with the jacobi polynomials (which are used in this impl to generate Zernikes)

Returns

array of rho, phi values

Return type

numpy.ndarray, numpy.ndarray`

clear(*args)

Empty the cache.

nbytes()

Total size in memory of the cache in bytes.

class prysm.zernike.BaseZernike(*args, **kwargs)

Bases: prysm.pupil.Pupil

Basic class implementing Zernike features.

build()

Use the wavefront coefficients stored in this class instance to build a wavefront model.

Returns

self – this Zernike instance

Return type

BaseZernike

top_n(n=5)

Identify the top n terms in the wavefront.

Parameters

n (int, optional) – identify the top n terms.

Returns

list of tuples (magnitude, index, term)

Return type

list

magnitudes

Return the magnitude and angles of the zernike components in this wavefront.

names

Names of the terms in self.

barplot(orientation='h', buffer=1, zorder=3, number=True, offset=0, width=0.8, fig=None, ax=None)

Create a barplot of coefficients and their names.

Parameters
  • orientation (str, {‘h’, ‘v’, ‘horizontal’, ‘vertical’}) – orientation of the plot

  • buffer (float, optional) – buffer to use around the left and right (or top and bottom) bars

  • zorder (int, optional) – zorder of the bars. Use zorder > 3 to put bars in front of gridlines

  • number (bool, optional) – if True, plot numbers along the y=0 line showing indices

  • offset (float, optional) – offset to apply to bars, useful for before/after Zernike breakdowns

  • width (float, optional) – width of bars, useful for before/after Zernike breakdowns

  • 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

barplot_magnitudes(orientation='h', sort=False, buffer=1, zorder=3, offset=0, width=0.8, fig=None, ax=None)

Create a barplot of magnitudes of coefficient pairs and their names.

E.g., astigmatism will get one bar.

Parameters
  • orientation (str, {‘h’, ‘v’, ‘horizontal’, ‘vertical’}) – orientation of the plot

  • sort (bool, optional) – whether to sort the zernikes in descending order

  • buffer (float, optional) – buffer to use around the left and right (or top and bottom) bars

  • zorder (int, optional) – zorder of the bars. Use zorder > 3 to put bars in front of gridlines

  • offset (float, optional) – offset to apply to bars, useful for before/after Zernike breakdowns

  • width (float, optional) – width of bars, useful for before/after Zernike breakdowns

  • 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

barplot_topn(n=5, orientation='h', buffer=1, zorder=3, fig=None, ax=None)

Plot the top n terms in the wavefront.

Parameters
  • n (int, optional) – plot the top n terms.

  • orientation (str, {‘h’, ‘v’, ‘horizontal’, ‘vertical’}) – orientation of the plot

  • buffer (float, optional) – buffer to use around the left and right (or top and bottom) bars

  • zorder (int, optional) – zorder of the bars. Use zorder > 3 to put bars in front of gridlines

  • 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

truncate(n)

Truncate the wavefront to the first n terms.

Parameters

n (int) – number of terms to keep.

Returns

modified FringeZernike instance.

Return type

self

truncate_topn(n)

Truncate the pupil to only the top n terms.

Parameters

n (int) – number of parameters to keep

Returns

modified FringeZernike instance.

Return type

self

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

fcn

Complex wavefunction associated with the pupil.

static from_interferogram(interferogram, wvl=None, mask_phase=True)

Create a new Pupil instance from an interferogram.

Parameters
  • interferogram (Interferogram) – an interferogram object

  • wvl (float, optional) – wavelength of light, in micrometers, if not present in interferogram.meta

Returns

new Pupil instance

Return type

Pupil

Raises

ValueError – wavelength not present

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.

strehl

Strehl ratio of the pupil.

class prysm.zernike.FringeZernike(*args, **kwargs)

Bases: prysm.zernike.BaseZernike

Fringe Zernike description of an optical pupil.

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

barplot(orientation='h', buffer=1, zorder=3, number=True, offset=0, width=0.8, fig=None, ax=None)

Create a barplot of coefficients and their names.

Parameters
  • orientation (str, {‘h’, ‘v’, ‘horizontal’, ‘vertical’}) – orientation of the plot

  • buffer (float, optional) – buffer to use around the left and right (or top and bottom) bars

  • zorder (int, optional) – zorder of the bars. Use zorder > 3 to put bars in front of gridlines

  • number (bool, optional) – if True, plot numbers along the y=0 line showing indices

  • offset (float, optional) – offset to apply to bars, useful for before/after Zernike breakdowns

  • width (float, optional) – width of bars, useful for before/after Zernike breakdowns

  • 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

barplot_magnitudes(orientation='h', sort=False, buffer=1, zorder=3, offset=0, width=0.8, fig=None, ax=None)

Create a barplot of magnitudes of coefficient pairs and their names.

E.g., astigmatism will get one bar.

Parameters
  • orientation (str, {‘h’, ‘v’, ‘horizontal’, ‘vertical’}) – orientation of the plot

  • sort (bool, optional) – whether to sort the zernikes in descending order

  • buffer (float, optional) – buffer to use around the left and right (or top and bottom) bars

  • zorder (int, optional) – zorder of the bars. Use zorder > 3 to put bars in front of gridlines

  • offset (float, optional) – offset to apply to bars, useful for before/after Zernike breakdowns

  • width (float, optional) – width of bars, useful for before/after Zernike breakdowns

  • 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

barplot_topn(n=5, orientation='h', buffer=1, zorder=3, fig=None, ax=None)

Plot the top n terms in the wavefront.

Parameters
  • n (int, optional) – plot the top n terms.

  • orientation (str, {‘h’, ‘v’, ‘horizontal’, ‘vertical’}) – orientation of the plot

  • buffer (float, optional) – buffer to use around the left and right (or top and bottom) bars

  • zorder (int, optional) – zorder of the bars. Use zorder > 3 to put bars in front of gridlines

  • 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

build()

Use the wavefront coefficients stored in this class instance to build a wavefront model.

Returns

self – this Zernike instance

Return type

BaseZernike

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

fcn

Complex wavefunction associated with the pupil.

static from_interferogram(interferogram, wvl=None, mask_phase=True)

Create a new Pupil instance from an interferogram.

Parameters
  • interferogram (Interferogram) – an interferogram object

  • wvl (float, optional) – wavelength of light, in micrometers, if not present in interferogram.meta

Returns

new Pupil instance

Return type

Pupil

Raises

ValueError – wavelength not present

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

magnitudes

Return the magnitude and angles of the zernike components in this wavefront.

names

Names of the terms in self.

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.

strehl

Strehl ratio of the pupil.

top_n(n=5)

Identify the top n terms in the wavefront.

Parameters

n (int, optional) – identify the top n terms.

Returns

list of tuples (magnitude, index, term)

Return type

list

truncate(n)

Truncate the wavefront to the first n terms.

Parameters

n (int) – number of terms to keep.

Returns

modified FringeZernike instance.

Return type

self

truncate_topn(n)

Truncate the pupil to only the top n terms.

Parameters

n (int) – number of parameters to keep

Returns

modified FringeZernike instance.

Return type

self

class prysm.zernike.NollZernike(*args, **kwargs)

Bases: prysm.zernike.BaseZernike

Noll Zernike description of an optical pupil.

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

barplot(orientation='h', buffer=1, zorder=3, number=True, offset=0, width=0.8, fig=None, ax=None)

Create a barplot of coefficients and their names.

Parameters
  • orientation (str, {‘h’, ‘v’, ‘horizontal’, ‘vertical’}) – orientation of the plot

  • buffer (float, optional) – buffer to use around the left and right (or top and bottom) bars

  • zorder (int, optional) – zorder of the bars. Use zorder > 3 to put bars in front of gridlines

  • number (bool, optional) – if True, plot numbers along the y=0 line showing indices

  • offset (float, optional) – offset to apply to bars, useful for before/after Zernike breakdowns

  • width (float, optional) – width of bars, useful for before/after Zernike breakdowns

  • 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

barplot_magnitudes(orientation='h', sort=False, buffer=1, zorder=3, offset=0, width=0.8, fig=None, ax=None)

Create a barplot of magnitudes of coefficient pairs and their names.

E.g., astigmatism will get one bar.

Parameters
  • orientation (str, {‘h’, ‘v’, ‘horizontal’, ‘vertical’}) – orientation of the plot

  • sort (bool, optional) – whether to sort the zernikes in descending order

  • buffer (float, optional) – buffer to use around the left and right (or top and bottom) bars

  • zorder (int, optional) – zorder of the bars. Use zorder > 3 to put bars in front of gridlines

  • offset (float, optional) – offset to apply to bars, useful for before/after Zernike breakdowns

  • width (float, optional) – width of bars, useful for before/after Zernike breakdowns

  • 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

barplot_topn(n=5, orientation='h', buffer=1, zorder=3, fig=None, ax=None)

Plot the top n terms in the wavefront.

Parameters
  • n (int, optional) – plot the top n terms.

  • orientation (str, {‘h’, ‘v’, ‘horizontal’, ‘vertical’}) – orientation of the plot

  • buffer (float, optional) – buffer to use around the left and right (or top and bottom) bars

  • zorder (int, optional) – zorder of the bars. Use zorder > 3 to put bars in front of gridlines

  • 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

build()

Use the wavefront coefficients stored in this class instance to build a wavefront model.

Returns

self – this Zernike instance

Return type

BaseZernike

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

fcn

Complex wavefunction associated with the pupil.

static from_interferogram(interferogram, wvl=None, mask_phase=True)

Create a new Pupil instance from an interferogram.

Parameters
  • interferogram (Interferogram) – an interferogram object

  • wvl (float, optional) – wavelength of light, in micrometers, if not present in interferogram.meta

Returns

new Pupil instance

Return type

Pupil

Raises

ValueError – wavelength not present

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

magnitudes

Return the magnitude and angles of the zernike components in this wavefront.

names

Names of the terms in self.

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.

strehl

Strehl ratio of the pupil.

top_n(n=5)

Identify the top n terms in the wavefront.

Parameters

n (int, optional) – identify the top n terms.

Returns

list of tuples (magnitude, index, term)

Return type

list

truncate(n)

Truncate the wavefront to the first n terms.

Parameters

n (int) – number of terms to keep.

Returns

modified FringeZernike instance.

Return type

self

truncate_topn(n)

Truncate the pupil to only the top n terms.

Parameters

n (int) – number of parameters to keep

Returns

modified FringeZernike instance.

Return type

self

class prysm.zernike.ANSI1TermZernike(*args, **kwargs)

Bases: prysm.zernike.BaseZernike

1-term ANSI Zernike description of an optical pupil.

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

barplot(orientation='h', buffer=1, zorder=3, number=True, offset=0, width=0.8, fig=None, ax=None)

Create a barplot of coefficients and their names.

Parameters
  • orientation (str, {‘h’, ‘v’, ‘horizontal’, ‘vertical’}) – orientation of the plot

  • buffer (float, optional) – buffer to use around the left and right (or top and bottom) bars

  • zorder (int, optional) – zorder of the bars. Use zorder > 3 to put bars in front of gridlines

  • number (bool, optional) – if True, plot numbers along the y=0 line showing indices

  • offset (float, optional) – offset to apply to bars, useful for before/after Zernike breakdowns

  • width (float, optional) – width of bars, useful for before/after Zernike breakdowns

  • 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

barplot_magnitudes(orientation='h', sort=False, buffer=1, zorder=3, offset=0, width=0.8, fig=None, ax=None)

Create a barplot of magnitudes of coefficient pairs and their names.

E.g., astigmatism will get one bar.

Parameters
  • orientation (str, {‘h’, ‘v’, ‘horizontal’, ‘vertical’}) – orientation of the plot

  • sort (bool, optional) – whether to sort the zernikes in descending order

  • buffer (float, optional) – buffer to use around the left and right (or top and bottom) bars

  • zorder (int, optional) – zorder of the bars. Use zorder > 3 to put bars in front of gridlines

  • offset (float, optional) – offset to apply to bars, useful for before/after Zernike breakdowns

  • width (float, optional) – width of bars, useful for before/after Zernike breakdowns

  • 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

barplot_topn(n=5, orientation='h', buffer=1, zorder=3, fig=None, ax=None)

Plot the top n terms in the wavefront.

Parameters
  • n (int, optional) – plot the top n terms.

  • orientation (str, {‘h’, ‘v’, ‘horizontal’, ‘vertical’}) – orientation of the plot

  • buffer (float, optional) – buffer to use around the left and right (or top and bottom) bars

  • zorder (int, optional) – zorder of the bars. Use zorder > 3 to put bars in front of gridlines

  • 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

build()

Use the wavefront coefficients stored in this class instance to build a wavefront model.

Returns

self – this Zernike instance

Return type

BaseZernike

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

fcn

Complex wavefunction associated with the pupil.

static from_interferogram(interferogram, wvl=None, mask_phase=True)

Create a new Pupil instance from an interferogram.

Parameters
  • interferogram (Interferogram) – an interferogram object

  • wvl (float, optional) – wavelength of light, in micrometers, if not present in interferogram.meta

Returns

new Pupil instance

Return type

Pupil

Raises

ValueError – wavelength not present

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

magnitudes

Return the magnitude and angles of the zernike components in this wavefront.

names

Names of the terms in self.

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.

strehl

Strehl ratio of the pupil.

top_n(n=5)

Identify the top n terms in the wavefront.

Parameters

n (int, optional) – identify the top n terms.

Returns

list of tuples (magnitude, index, term)

Return type

list

truncate(n)

Truncate the wavefront to the first n terms.

Parameters

n (int) – number of terms to keep.

Returns

modified FringeZernike instance.

Return type

self

truncate_topn(n)

Truncate the pupil to only the top n terms.

Parameters

n (int) – number of parameters to keep

Returns

modified FringeZernike instance.

Return type

self

class prysm.zernike.ANSI2TermZernike(*args, **kwargs)

Bases: prysm.pupil.Pupil

2-term ANSI Zernike description of an optical pupil.

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

build()

Use the wavefront coefficients stored in this class instance to build a wavefront model.

Returns

self – this Zernike instance

Return type

BaseZernike

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

fcn

Complex wavefunction associated with the pupil.

static from_interferogram(interferogram, wvl=None, mask_phase=True)

Create a new Pupil instance from an interferogram.

Parameters
  • interferogram (Interferogram) – an interferogram object

  • wvl (float, optional) – wavelength of light, in micrometers, if not present in interferogram.meta

Returns

new Pupil instance

Return type

Pupil

Raises

ValueError – wavelength not present

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.

strehl

Strehl ratio of the pupil.

prysm.zernike.zernikefit(data, x=None, y=None, rho=None, phi=None, terms=16, norm=False, residual=False, round_at=6, map_='Fringe')

Fits a number of Zernike coefficients to provided data.

Works by minimizing the mean square error between each coefficient and the given data. The data should be uniformly sampled in an x,y grid.

Parameters
  • data (numpy.ndarray) – data to fit to.

  • x (numpy.ndarray, optional) – x coordinates, same shape as data

  • y (numpy.ndarray, optional) – y coordinates, same shape as data

  • rho (numpy.ndarray, optional) – radial coordinates, same shape as data

  • phi (numpy.ndarray, optional) – azimuthal coordinates, same shape as data

  • terms (int or iterable, optional) – if an int, number of terms to fit, otherwise, specific terms to fit. If an iterable of ints, members of the single index set map_, else interpreted as (n,m) terms, in which case both m+ and m- must be given.

  • norm (bool, optional) – if True, normalize coefficients to unit RMS value

  • residual (bool, optional) – if True, return a tuple of (coefficients, residual)

  • round_at (int, optional) – decimal place to round values at.

  • map (str, optional, {‘Fringe’, ‘Noll’, ‘ANSI’}) – which ordering of Zernikes to use

Returns

  • coefficients (numpy.ndarray) – an array of coefficients matching the input data.

  • residual (float) – RMS error between the input data and the fit.

Raises

ValueError – too many terms requested.