MAOS
Multithreaded Adaptive Optics Simulator
loc.h File Reference

Macros

#define locfree(A)   if(A){locfree_do(A);A=NULL;}
 
#define ptsfree(A)   if(A){locfree_do((loc_t*)A);A=NULL;}
 
#define locarrfree(A, B)   ({locarrfree_do(A,B);A=NULL;})
 
#define loc_create_stat(loc)   if(!loc->stat) loc_create_stat_do(loc);
 
#define ptsresize(pts, nsa)   locresize((loc_t*)pts, nsa)
 

Functions

lmatloc_create_embed (long *nembed, const loc_t *loc, real oversize, int fftpad)
 
void loc_create_map_npad (const loc_t *loc, int npad, int nx, int ny)
 
void loc_create_map (const loc_t *loc)
 
uint32_t lochash (const loc_t *loc, uint32_t key)
 
void loc_embed (map_t *dest, const loc_t *loc, const real *in)
 
dcellloc_embed2 (const loc_t *loc, const dmat *arr)
 
void loc_embed_add (map_t *dest, const loc_t *loc, const real *in)
 
void loc_embed_cell (dcell **dest, const loc_t *loc, const dcell *in)
 
void loc_extract (dmat *dest, const loc_t *loc, map_t *in)
 
loc_tmap2loc (map_t *amp, real thres)
 
void loc_free_map (loc_t *loc)
 
void locfree_do (loc_t *loc)
 
void locarrfree_do (loc_t **loc, int nloc)
 
real loc_diam (const loc_t *loc)
 
int loccenter (const loc_t *loc)
 
loc_tlocnew (long nloc, real dx, real dy)
 
loc_tlocref (loc_t *in)
 
pts_tptsnew (long nsa, real dsax, real dsay, long nxsa, long nysa, real dx, real dy)
 
void loc_calc_ptt (real *out, real *coeffout, const loc_t *loc, const real ipcc, const dmat *imcc, const real *amp, const real *opd)
 
void loc_calc_mod (real *out, real *coeffout, const dmat *mod, const real *amp, real *opd)
 
dmatloc_mcc_ptt (const loc_t *loc, const real *amp)
 
dcellpts_mcc_ptt (const pts_t *pts, const real *amp)
 
void loc_sub_ptt (dmat *opd, const real *ptt, const loc_t *loc)
 
void loc_add_ptt (dmat *opd, const real *ptt, const loc_t *loc)
 
void loc_remove_ptt (dmat *opd, const loc_t *loc, const real *amp, dmat *imcc, int both)
 
real loc_remove_focus_grad (dmat *grad, const loc_t *saloc, real factor)
 
void pts_ztilt (dmat **out, const pts_t *pts, const dcell *imcc, const real *amp, const real *opd)
 
loc_tmk1dloc_vec (real *x, long nx)
 
loc_tmk1dloc (real x0, real dx, long nx)
 
loc_tmksqloc_auto (long nx, long ny, real dx, real dy)
 
loc_tmksqloc_map (const map_t *map)
 
loc_tmksqloc (long nx, long ny, real dx, real dy, real ox, real oy)
 
loc_tmkannloc (real D, real Din, real dx, real thres)
 
void loc_create_stat_do (loc_t *loc)
 
void loc_free_stat (loc_t *loc)
 
void loc_circle_add (dmat *phi, loc_t *loc, real cx, real cy, real r, real rin, real val)
 
void loc_circle_mul (dmat *phi, loc_t *loc, real cx, real cy, real r, real rin, real val)
 
void loc_ellipse_add (dmat *phi, loc_t *loc, real cx, real cy, real rx, real ry, real val)
 
void loc_reduce (loc_t *loc, dmat *amp, real thres, int cont, int **skipout)
 
void loc_reduce_spcell (loc_t *loc, dspcell *sp, int dim, int cont)
 
void loc_reduce_sp (loc_t *loc, dsp *sp, int dim, int cont)
 
void loc_add_focus (const dmat *opd, const loc_t *loc, real val)
 
dmatloc2mat (loc_t *loc, int piston)
 
loc_tpts2loc (pts_t *pts)
 
void locrot (loc_t *loc, const real theta)
 
real loc_angle (const loc_t *loc1, const loc_t *loc2)
 
void locstretch (loc_t *loc, const real theta, const real frac)
 
loc_tlocdup (loc_t *loc)
 
void locmean (real *xm, real *ym, const loc_t *loc)
 
dmatparse_poly (const char *_ps)
 
loc_tloctransform (const loc_t *loc, const char *ps)
 
loc_tloctransform2 (const loc_t *loc, const dmat *coeff)
 
loc_tlocshift (const loc_t *loc, real sx, real sy)
 
void loc_nxny (long *nx, long *ny, const loc_t *loc)
 
void locresize (loc_t *loc, long nloc)
 
void dembed_locstat (dmat **out, real alpha, loc_t *loc, real *oin, real beta, int reverse)
 
void cembed_locstat (cmat **out, real alpha, loc_t *loc, real *oin, real beta, int reverse)
 
void loc_dxdy (loc_t *loc)
 
loc_td2loc (const dmat *A)
 
loc_tlocreaddata (file_t *fp, header_t *header)
 
void locwritedata (file_t *fp, const loc_t *loc)
 

Detailed Description

This file defines functions relates to pts_t, loc_t, map_t, etc.

Function Documentation

◆ loc_create_embed()

lmat* loc_create_embed ( long nembed,
const loc_t loc,
real  oversize,
int  fftpad 
)

Create an vector to embed OPD into square array for FFT purpose. oversize is 2 for fft.

◆ loc_create_map_npad()

void loc_create_map_npad ( const loc_t loc,
int  npad,
int  nx,
int  ny 
)

Create a map for loc so that we can obtain the index in loc by x,y coordinate. Useful in ray tracing (accphi.c). If extend is true, the invalid region in the map is replaced with closest valid point. This extends the coverage of the grid automatically.

◆ loc_create_map()

void loc_create_map ( const loc_t loc)

Create a map for loc with padding of 1.

◆ lochash()

uint32_t lochash ( const loc_t loc,
uint32_t  key 
)

apply hashlittle() to loc_t.

◆ loc_embed()

void loc_embed ( map_t dest,
const loc_t loc,
const real *  in 
)

Embed in into dest according to map defined in loc->map. Arbitraty map cannot be used here for mapping.

◆ loc_embed2()

dcell* loc_embed2 ( const loc_t loc,
const dmat arr 
)

A convenient wrapper for loc_embed to be called by matlab or python

◆ loc_embed_add()

void loc_embed_add ( map_t dest,
const loc_t loc,
const real *  in 
)

Embed in into dest according to map defined in loc->map. Arbitraty map cannot be used here for mapping.

◆ loc_embed_cell()

void loc_embed_cell ( dcell **  pdest,
const loc_t loc,
const dcell in 
)

Embed in into dest according to map defined in loc->map for cells. Arbitraty map cannot be used here for mapping.

◆ loc_extract()

void loc_extract ( dmat dest,
const loc_t loc,
map_t in 
)

Embed in into dest according to map defined in loc->map. Arbitraty map cannot be used here for mapping.

◆ map2loc()

loc_t* map2loc ( map_t map,
real  thres 
)

Convert a map to a loc that collects all positive entries.

◆ loc_free_map()

void loc_free_map ( loc_t loc)

Free the MAP in loc_t

◆ locfree_do()

void locfree_do ( loc_t loc)

Free loc_t data.

◆ locarrfree_do()

void locarrfree_do ( loc_t **  loc,
int  nloc 
)

Free loc_t array

◆ loc_diam()

real loc_diam ( const loc_t loc)

Estimate the diameter of loc. 2021-09-03: corrected calculation for square grid. Use the inscribed diameter but not circumcircle.

◆ loccenter()

int loccenter ( const loc_t loc)

Find the point that closes to origin (0,0) in loc. Useful in single point piston constraint in creating reconstructor.

◆ locnew()

loc_t* locnew ( long  nloc,
real  dx,
real  dy 
)

Create a loc with nloc elements.

◆ locref()

loc_t* locref ( loc_t in)

Reference an existing loc

◆ ptsnew()

pts_t* ptsnew ( long  nsa,
real  dsax,
real  dsay,
long  nxsa,
long  nysa,
real  dx,
real  dy 
)

Create a pts with nsa, dsa, nx, dx

◆ loc_calc_mod()

void loc_calc_mod ( real *  rmsout,
real *  coeffout,
const dmat mod,
const real *  amp,
real *  opd 
)

Calculate variance of OPD in modes defined in mod.

Notice the difference in rmsout for loc_calc_ptt and this loc_calc_mode. in loc_calc_ptt, out[0] is PR, out[1] is TT, out[2] is PTTR in loc_calc_mod, out[0] is PR, out[1] is PTR, out[2] is PTTR, etc

The mod is already orth-noramlized so that we have the following simple forms.

coeffout is in unit of zernike!

◆ loc_mcc_ptt()

dmat* loc_mcc_ptt ( const loc_t loc,
const real *  amp 
)

assemble modes of piston/tip/tilt into Nx3 matrix M, and compute their inverse covariance matrix. mcc=M'*(amp.*M)

◆ pts_mcc_ptt()

dcell* pts_mcc_ptt ( const pts_t pts,
const real *  amp 
)

same as loc_mcc_ptt, except using pts instead of loc. this is used to build imcc for TT/F powfs ztilt imcc

◆ loc_sub_ptt()

void loc_sub_ptt ( dmat opd,
const real *  ptt,
const loc_t loc 
)

Subtract Piston/Tip/Tilt (in radian) from OPD

◆ loc_add_ptt()

void loc_add_ptt ( dmat opd,
const real *  ptt,
const loc_t loc 
)

Add Piston/Tip/Tilt from OPD

◆ loc_remove_ptt()

void loc_remove_ptt ( dmat opd,
const loc_t loc,
const real *  amp,
dmat imcc,
int  cov 
)

Project piston/tip/tilt from opd which may have multiple independent columns. If cov is set, opd should be symmetric (covariance) and ptt is removed from left and right side.

◆ loc_remove_focus_grad()

real loc_remove_focus_grad ( dmat grad,
const loc_t saloc,
real  factor 
)

Remove focus mode from gradients. Do not consider noise weighting

◆ pts_ztilt()

void pts_ztilt ( dmat **  out,
const pts_t pts,
const dcell imcc,
const real *  amp,
const real *  opd 
)

Compute zernike best fit for all subapertures. add result to out. returns radians not zernike modes of tip/tilt. Used in wfsgrad

◆ mk1dloc_vec()

loc_t* mk1dloc_vec ( real *  x,
long  nx 
)

Create 1 dimensional loc with given vector.

◆ mk1dloc()

loc_t* mk1dloc ( real  x0,
real  dx,
long  nx 
)

Create 1 dimensional loc with origin at x0, sampling of dx, and nx numbers.

◆ mksqloc_auto()

loc_t* mksqloc_auto ( long  nx,
long  ny,
real  dx,
real  dy 
)

Create a loc array of size nx*ny at sampling dx with origin at (nx/2, ny/2)

◆ mksqloc_map()

loc_t* mksqloc_map ( const map_t map)

Create a loc array that covers the map_t. Notice that it is different from map2loc which only covers valid (value>0) regions.

◆ mksqloc()

loc_t* mksqloc ( long  nx,
long  ny,
real  dx,
real  dy,
real  ox,
real  oy 
)

Create a loc array contains coorindates in a square map of size nx*ny, with sampling dx, and at origin ox,oy

◆ mkannloc()

loc_t* mkannloc ( real  D,
real  Din,
real  dx,
real  thres 
)

Create a loc array within diameter D, and inner diameter Din, with spacing dx.

◆ loc_create_stat_do()

void loc_create_stat_do ( loc_t loc)

Gather information about the starting of each column in loc.

◆ loc_free_stat()

void loc_free_stat ( loc_t loc)

Free the stat in loc_t

◆ loc_circle_add()

void loc_circle_add ( dmat phi,
loc_t loc,
real  cx,
real  cy,
real  r,
real  rin,
real  val 
)

Add a gray pixel circular map in phi using coordinates defined in loc, center defined using cx, cy, radius of r, and value of val

◆ loc_circle_mul()

void loc_circle_mul ( dmat phi,
loc_t loc,
real  cx,
real  cy,
real  r,
real  rin,
real  val 
)

Apply an annular mask in phi.

◆ loc_ellipse_add()

void loc_ellipse_add ( dmat phi,
loc_t loc,
real  cx,
real  cy,
real  rx,
real  ry,
real  val 
)

Create a gray pixel elliptical map in phi using coordinates defined in loc, center defined using cx, cy, radii of rx, ry, and value of val

◆ loc_reduce()

void loc_reduce ( loc_t loc,
dmat amp,
real  thres,
int  cont,
int **  skipout 
)

Remove points in loc that have zero value in amp and modify amp in the same time. Keep each row continuous if cont==1. Return in skipout the index of skipped points if skipout is not NULL.

◆ loc_reduce_spcell()

void loc_reduce_spcell ( loc_t loc,
dspcell spc,
int  dim,
int  cont 
)

Remove uncoupled points in loc and modify spc in the same time. debugged on 2009-12-20. Not used often. using a dspcell, to compute the coupling which is modified accordingly.

◆ loc_reduce_sp()

void loc_reduce_sp ( loc_t loc,
dsp sp,
int  dim,
int  cont 
)

Remove uncoupled points in loc and modify sp in the same time. debugged on 2009-12-20. use single sparse matrix, which is modified accordingly.

◆ loc_add_focus()

void loc_add_focus ( const dmat opd,
const loc_t loc,
const real  val 
)

Add val amount of focus to opd. The unit is in radian like. Piston is removed.

◆ loc2mat()

dmat* loc2mat ( loc_t loc,
int  piston 
)

Create a dmat containing locx and locy in two columns

◆ pts2loc()

loc_t* pts2loc ( pts_t pts)

Convert pts_t to loc_t. Each entry in pts recors the lower left point in each subaperture.

◆ locrot()

void locrot ( loc_t loc,
const real  theta 
)

Rotate the coordinates by theta (radian) CCW.

◆ loc_angle()

real loc_angle ( const loc_t loc1,
const loc_t loc2 
)

Determine the angle of rotation from loc1 to loc2. CCW is positive.

◆ locstretch()

void locstretch ( loc_t loc,
const real  theta,
const real  frac 
)

Stretch the coordinate by frac along theta (radian) CCW.

◆ locdup()

loc_t* locdup ( loc_t loc)

duplicate a loc_t object;

◆ locmean()

void locmean ( real *  xm,
real *  ym,
const loc_t loc 
)

Compute average of locx, locy

◆ parse_poly()

dmat* parse_poly ( const char *  _ps)

Parse string representation of polynominal to array representation.

◆ loctransform()

loc_t* loctransform ( const loc_t loc,
const char *  polycoeff 
)

Transform coordinate. loc (input) contains x,y; locm (return) contains xm, ym. polyn contains the formula

\[ xm{ip}=\sum_{ic}(coeff[0](0,ic)*pow(x,coeff[0](1,ic))*pow(y,coeff[0](2,ic))) ym{ip}=\sum_{ic}(coeff[1](0,ic)*pow(x,coeff[1](1,ic))*pow(y,coeff[1](2,ic))) \]

was using string input. New scheme uses bin files to preserve precision.

◆ loctransform2()

loc_t* loctransform2 ( const loc_t loc,
const dmat coeff 
)

Transform coordinate with coefficients. See loctransform()

Parameters
locInput loc_t
coeffn*4 matrix

◆ locshift()

loc_t* locshift ( const loc_t loc,
real  sx,
real  sy 
)

Shift a loc coordinate

◆ loc_nxny()

void loc_nxny ( long nx,
long ny,
const loc_t loc 
)

Compute the size of a map that is used to build loc or can fully contain loc (embed)

◆ locresize()

void locresize ( loc_t loc,
long  nloc 
)

Resize a loc_t by shrinking.

◆ loc_dxdy()

void loc_dxdy ( loc_t out)

Determine dx and dy from data.

◆ d2loc()

loc_t* d2loc ( const dmat A)

Convert a 2 column vector to loc

◆ locreaddata()

loc_t* locreaddata ( file_t *  fp,
header_t header 
)

Verify the magic, dimension and read in the loc_t by calling locreaddata2().

◆ locwritedata()

void locwritedata ( file_t *  fp,
const loc_t loc 
)

Write the actual data to file pointer.