MAOS
Multithreaded Adaptive Optics Simulator
Loading...
Searching...
No Matches
pywfs.h File Reference

Data Structures

struct  pywfs_cfg_t
struct  pywfs_t

Macros

#define pywfs_ng(pycfg)

Functions

pywfs_t * pywfs_new (pywfs_cfg_t *pycfg, loc_t *loc, const dmat *amp)
void pywfs_free (pywfs_t *pywfs)
void pycfg_free (pywfs_cfg_t *pycfg)
void pywfs_grad (dmat **pgrad, const pywfs_t *pywfs, const dmat *ints)
void pywfs_ints (dmat **ints, const pywfs_t *pywfs, const dmat *opd, real siglev)
dmat * pywfs_mkg (pywfs_t *pywfs, const loc_t *ploc, const char *distortion, const dmat *mod, const dmat *opdadd, real displacex, real displacey)
dmat * pywfs_tt (const pywfs_t *pywfs)
void pywfs_simu (dmat **ints, dmat **grad, pywfs_cfg_t *pycfg, int order, dmat *wvl, real siglev, loc_t *loc, const dmat *amp, const dmat *opd)
void pywfs_gain_calibrate (pywfs_t *pywfs, const dmat *grad, real r0)
void pywfs_test (pywfs_t *pywfs)

Detailed Description

Setup pyramid WFS and do simulation.


Data Structure Documentation

◆ pywfs_cfg_t

struct pywfs_cfg_t

Pyramid WFS configurations. //Todo: move to pywfs.h after pywfs.h is moved to lib folder

Collaboration diagram for pywfs_cfg_t:
Data Fields
int order

Number of pixels per pupil in each dimension.

real siglev

Nominal siglev per subaperture

dmat * wvl

wavelength

real dx

OPD sampling. Use loc->dx if not present

real D

Aperture diameter. Use loc_diam if not present

int nside

Number of sides. can be 4 (default) or 3. 4-side is traditional pyramid while 3-side is much easier to make.

int raw

1: use normalized ints of each sub-pupil as gradient. 0 (default): use difference between sub-pupils

real dsa

Subaperture size (default is D/order)

real saat

drop subapertures below this fraction (default is 0)

real hs

Height of guide star (default is inf)

real hc

Conjugation height of WFS pupil (default is 0)

real modulate

Amount of modulation in radian (default is 5 lambda/D)

int modulpos

Number of positions per modulation cycle per ring(default is 32)

int modulring

Number of rings within the maximum radius to modulate (default is 1, use more to simulate extended object)

int sigmatch

Scale gradients by matching intensity (1: locally, 2 (default): globally).

real poke

How much to poke for mkg. (default is 1e-7 m)

dmat * wvlwts

Wavelength weights

real pixblur

pixel blur (default is 0.3)

real fieldstop

size of field stop in arcsec (default is none).

int modulpos_i

For testing: Index of modulate position to use between 0 and modulpos

dmat * psx

pyramid WFS pupil shift along x (in pixel). pupil ordering: -x+y, +x+y, -x-y, +x-y.

dmat * psy

pyramid WFS pupil shift along y (in pixel).

real flate

pyramid flat edge angular width (in arcsec)

real flatv

pyramid flat vertex angular width (in arcsec)

real pupelong

pyramid pupil (detector) elongation ratio (long axis / short axis - 1).

◆ pywfs_t

struct pywfs_t

Parameters used by Pyramid WFS.

Collaboration diagram for pywfs_t:
Data Fields
const pywfs_cfg_t * cfg

Configuration. do not try to free.

int iwfs0

First iwfs for this powfs

int gpu

Whether GPU can be used

loc_t * loc

Pupil plane grid

dmat * amp

Pupil plane amplitude map

loc_t * saloc

powfs.saloc

locfft_t * locfft

First fft to form PSF

ccell * pyramid

OPD of pyramid. Angular size of clear aperture is different

cmat * nominal

For sampling results onto detector

dspcell * si

For sampling results onto detector

dmat * sioff

Offset for si

dmat * saa

Subaperture area. Average is one

dmat * gradoff

Gradient of a flat wavefront

dmat * GTT

Response of TT mode.

dmat * pupilshift

Pupil shift. 4x2.

loccell * msaloc

Mishaped saloc of each sub-pupil due to optical effects

dmat * opdadd

Aberrations along the WFS path (on locfft grid)

real gain

Optical gain of PYWFS

Macro Definition Documentation

◆ pywfs_ng

#define pywfs_ng ( pycfg)
Value:
((pycfg && (pycfg->raw||pycfg->nside<3))?pycfg->nside:2)

Function Documentation

◆ pywfs_new()

pywfs_t * pywfs_new ( pywfs_cfg_t * pycfg,
loc_t * loc,
const dmat * amp )

Create and initialize a pyramid WFS from configuration pycfg. Optional parameters in pycfg are filled with defaults. loc is the pupil OPD grid (created from pycfg->D and dx if NULL); amp is the amplitude on loc (uniform if NULL). Computes subaperture illumination, gradient offset and optical gain. pycfg is referenced, not copied, and must outlive the returned struct. Free with pywfs_free().

Parameters
[in,out]pycfgThe configuration. Unset optional parameters are filled with defaults.
[in]locThe pupil OPD grid (referenced). If NULL, an annular grid is created from pycfg->D and pycfg->dx.
[in]ampThe amplitude on loc (referenced). Uniform if NULL.
Returns
Newly allocated PYWFS struct; free with pywfs_free().

◆ pywfs_free()

void pywfs_free ( pywfs_t * pywfs)

frees pywfs_t

Parameters
[in]pywfsThe PYWFS struct to free. Can be NULL. pywfs->cfg is not freed.

◆ pycfg_free()

void pycfg_free ( pywfs_cfg_t * pycfg)

Free pywfs_cfg_t and its arrays.

Parameters
[in]pycfgThe configuration to free. Can be NULL.

◆ pywfs_grad()

void pywfs_grad ( dmat ** pgrad,
const pywfs_t * pywfs,
const dmat * ints )

Compute gradients. It replaces the result, not accumulate.

Parameters
[out]pgradThe gradients (nsa*ng). Allocated if NULL.
[in]pywfsPYWFS parameters.
[in]intsThe subaperture intensity (nsa*nside).

◆ pywfs_ints()

void pywfs_ints ( dmat ** ints,
const pywfs_t * pywfs,
const dmat * opd,
real siglev )

Perform FFT over the complex PSF with additional phases caused by the pyramid. FFT on each quadrant of the PSF creates diffraction effects.

Parameters
[in,out]intsThe intensity (nsa*nside), accumulated into. Allocated if NULL.
[in]pywfsPYWFS parameters.
[in]opdThe OPD on pywfs->locfft->loc (m).
[in]siglevThe signal level per subaperture.

◆ pywfs_mkg()

dmat * pywfs_mkg ( pywfs_t * pywfs,
const loc_t * locin,
const char * distortion,
const dmat * mod,
const dmat * opdadd,
real displacex,
real displacey )

Compute the PYWFS interaction matrix with caching. locin is on pupil.

Parameters
[in,out]pywfsPYWFS parameters. pywfs->opdadd is replaced if opdadd is set.
[in]locinThe grid of the input OPD, on pupil.
[in]distortionThe pupil distortion transform string for loctransform(). Can be NULL.
[in]modThe modes defined on locin. If NULL, use zonal poke.
[in]opdaddAdditional OPD on pywfs->loc as the operating point. Can be NULL.
[in]displacexDisplacement along x of locin from pupil (m).
[in]displaceyDisplacement along y of locin from pupil (m).
Returns
Newly allocated interaction matrix (nsa*ng)*nmod; the caller frees it.

◆ pywfs_tt()

dmat * pywfs_tt ( const pywfs_t * pywfs)

Return measurement of T/T mode, normalized for 1 unit of input.

Parameters
[in]pywfsPYWFS parameters.
Returns
Newly allocated (nsa*ng)*2 matrix of gradients for unit tip and tilt; the caller frees it.

◆ pywfs_simu()

void pywfs_simu ( dmat ** ints,
dmat ** grad,
pywfs_cfg_t * pycfg,
int order,
dmat * wvl,
real siglev,
loc_t * loc,
const dmat * amp,
const dmat * opd )

A convenient wrapper to simulate pywfs from Python.

Parameters
[in,out]intsSubaperture images, accumulated into. Allocated if NULL. Can be NULL.
[out]gradSubaperture gradients. Allocated if NULL.
[in,out]pycfgConfiguration struct. Unset parameters are filled. Optional if order, wvl, siglev are all set.
[in]orderPWFS order. Optional if pycfg is set.
[in]wvlWavelength (m). Optional if pycfg is set.
[in]siglevSignal level of each subaperture. Optional if pycfg is set.
[in]locOPD loc. Can be NULL.
[in]ampOPD amplitude map. Can be NULL.
[in]opdOPD (m).

◆ pywfs_gain_calibrate()

void pywfs_gain_calibrate ( pywfs_t * pywfs,
const dmat * grad,
real r0 )

PYWFS gain calibrate using measurements. The idea is as follows. With a given input OPD, the PWFS measures OPDR. Feed OPDR to PWFS, it measures OPDR2. Optionally add a fitting error to the input. Scale OPDR by alpha, it measures OPDR3. Iterate the alpha until OPDR3 has the same magnitude as OPDR. The final alpha is the gain adjustment. This does not quite work because the original input OPD and OPDR has different spatial frequency content. Most of OPD is not measurable.

Parameters
[in,out]pywfsPYWFS parameters. pywfs->gain is updated.
[in]gradThe measured gradients.
[in]r0Fried parameter (m) used to add fitting error. 0 to disable.

◆ pywfs_test()

void pywfs_test ( pywfs_t * pywfs)

Test PYWFS implementation when env MAOS_PYWFS_DEBUG is set. 1 (or -1 with petal modes): linearity with zernike (petal) modes; 2: linearity with noise and dithering; 3: NCPA calibration; 4: automatic gain calibration. Results are saved to files and the program exits afterwards.

Parameters
[in,out]pywfsPYWFS parameters. Can be NULL. pywfs->gain may be changed by the gain calibration test.