WFS

wfs.py routines in support of the ShaneAO Hartmann WFS

To check the configuration:

import wfs w = wfs.wfs(secondary=True) tw = wfs.tweeter() dimg(w.show(tw))

To generate a reconstructor matrix (takes a while):

import wfs w = wfs.wfs(secondary=True) tw = wfs.tweeter() w.Hmatrix() w.m2a(tw) w.Rmatrix()

class wfs.wfs(mode=1, secondary=False)

wfs is the wavefront sensor class. This is configured specifically for ShaneAO, where subapertures on the wavefront sensor are aligned to actuators on the tweeter DM. See also tweeter.

The purpose of the wavefront sensor class is to generate reasonable system (H) and control (R) matrices for the real-time controller, based on a selection of the wfs geometry and some internal mode set.

The current version of this module implements a subset of Zernike modes as the internal mode set.

Hmatrix()

Hmatrix creates the system matrix, H, sometimes called the forward matrix, for the Hartmann sensor. H is a mapping from mode coeffients of wavefront phase to Hartmann slope signals.

The math is

s = H c

where c is the vector of mode coefficients and s is the vector of wfs slopes, stacked as [s_x, s_y]

The result of the calculation is the matrix self.H which has dimensions number of slopes by number of modes.

Rmatrix()

Calculate the reconstruction matrix, R, given the system matrix, H, and the mode-to-actuator matrix, A.

The math is:

R = A H +

where H + is the pseudo-inverse of H.

Note this is the most general of reconstruction matrix formulations. The internal mode set is any, not necessarily orthonormal, set of basis functions that are convenient and spanning the Hilbert subspace you want to restrict control solutions to. For example, the mode set can be Zernike functions, Fourier function (sines and cosines), natural DM modes, actuator influence functions, and so on, or any combination of these. The A matrix simply maps these basis functions to actuator command vectors. For example A could be the identity matrix in the case where the ‘mode set’ is the set of actuator influence functions. (not recommended in the ShaneAO case, since the actuators over-sample what is visible to the wavefront sensor). . The pseudo-inverse of H could be computed according to regularization, penalty function, or Bayesian statistical priors methodologies, i.e.

H + = (Q + H T W H) -1 H T
gmodes()

Calculaate the gradients of each of the modes that were generated using zmodes. These gradients of modes will subsequently be used to determine the slope signals that each mode causes on the Hartmann wavefront sensor. The numerical approach is to take a central difference on the fine grid scale. The results are stored in 3-d data cubes self.gxset and self.gyset for x and y slopes respectively.

m2a(tw, method='average')

The method m2a creates the matrix A, which converts from mode coefficients into actuator command vectors.

The result is stored in a matrix self.A which has dimensions number of actuators by number of modes.

The present numerical method is to simply set the actuator to the average value of the mode within a box surrounding the actuator that extends half way to neighboring actuators all around. A fancier technique might take into account the influence function of the actuator, so this method depends on the tweeter object, tw, given in the argument list.

sense(phi)

Simulate the Hartmann sensor by calculating the local slopes on phase sheet phi averaged on subapertures. The slopes are returned in a vector of length number of subaps x 2: all of the x slopes followed by all of the y slopes.

The input array, phi, must be the same shape and on the same sampling as the modes in the wfs mode set.

show(tw)

Create a diagnostic image that shows the positions of the actuators, subapertures, and pupil overlayed

Requires a tweeter object, tw, as input.

Returns a 2-d array, the diagnostic layout image

_images/wfs-show.png
subaps()

Generate a set of windows that define the subaperture regions on the pupil. The result is stored in a 3-d data cube self.subapset. Another array called self.wap is the 2-d array that is the union of all the subaps

type()

Returns the type of the object, which is ‘wfs’

zmodes(nmodes=0, res=10)

Generate the Zernike mode set, up to <nmodes> number of modes, excluding piston. The modes are generated on a fine grid with dx = (actuator spacing)/res. (The unit of length on the grid is tweeter actuator spacing.) The result is stored in the 3-d data cube self.modeset