コード例 #1
0
ファイル: setup_aster.c プロジェクト: bitursa/maos
/**
  Estimate wavefront error propagated from measurement error. pgm is the reconstructor. ineam is the
  error inverse.
  trace(Mcc*(pgm*neam*pgm'))
*/
static dmat *calc_recon_error(const dmat *pgm,   /**<[in] the reconstructor*/
			      const dmat *neam,/**<[in] the inverse of error covariance matrix*/
			      const dmat *mcc   /**<[in] NGS mode covariance matrix.*/
			      ){
    dmat *psp=NULL;
    dmat *tmp=NULL;
    dcp(&tmp, pgm);
    dmuldiag(tmp, neam);
    dmm(&psp, 0, tmp, pgm, "nt", 1);
    PDMAT(psp,ppsp); 
    PDMAT(mcc,pmcc);
    /*It is right for both ix, iy to stop at ib.*/
    double all[mcc->nx];
    for(int ib=0; ib<mcc->ny; ib++){
	all[ib]=0;
	for(int iy=0; iy<=ib; iy++){
	    for(int ix=0; ix<=ib; ix++){
		all[ib]+=ppsp[iy][ix]*pmcc[iy][ix];
	    }
	}
    }
    dfree(psp);
    dmat *res=dnew(3,1);
    res->p[0]=all[5];//total error
    res->p[1]=all[1];//total TT error
    if(mcc->nx>5){
	res->p[2]=all[5]-all[4];//focus alone
	if(res->p[2]<0){
	    res->p[2]=0;//due to coupling, this may be negative.
	}
    }
    return res;
}
コード例 #2
0
/**
   Compute Von Karman covariance function at separations computed from the grid
   size nx and sampling dx, with Fried parameter of r0, and outerscale of L0.  
   ninit is the initial side size of the atm array to start with.
*/
static vkcov_t* vkcov_calc(double r0, double L0, double dx, long n, long ninit){
    if(L0>9000) L0=INFINITY;/*L0 bigger than 9000 is treated as infinity. */
    vkcov_t *node=vkcov_get(r0, L0, dx, n, ninit);
    if(node) return node;
    node=mycalloc(1,vkcov_t);
    node->r0=r0;
    node->L0=L0;
    node->dx=dx;
    node->n=n;
    node->ninit=ninit;
    long nroot=(long)round(log2((double)n-1));
    node->next=head;
    if(r0>=L0){
	error("Illegal parameter: r0=%g, L0=%g\n", r0, L0);
    }
    head=node;
    dmat *r=dnew(2, nroot+2);
    double sqrt2=sqrt(2);
    IND(r,0,0)=0;
    IND(r,1,0)=0;
    for(long i=0; i<=nroot; i++){
	long j=1<<i;
	IND(r,0,i+1)=j*dx;
	IND(r,1,i+1)=j*dx*sqrt2;
    }
    double D=(n-1)*dx;
    node->cov=turbcov(r, D*sqrt(2), r0, L0);
    dfree(r);
    dmat *rc0=dnew(ninit*ninit, ninit*ninit);
    dmat*  rc=rc0;
    double dx2=dx*(n-1)/(ninit-1);
    for(long j=0; j<ninit; j++){
	double y=dx2*j;
	for(long i=0; i<ninit; i++){
	    double x=dx2*i;
	    long k=i+j*ninit;
	    for(long j2=0; j2<ninit; j2++){
		double y2=dx2*j2;
		for(long i2=0; i2<ninit; i2++){
		    double x2=dx2*i2;
		    long k2=i2+j2*ninit;
		    IND(rc,k2,k)=sqrt((x-x2)*(x-x2)+(y-y2)*(y-y2));
		}
	    }
	}
    }
    node->C=turbcov(rc0, D*sqrt(2), r0, L0);
    dfree(rc0);
    dmat *u=NULL, *s=NULL, *v=NULL;
    dsvd(&u, &s, &v, node->C);
    dcwpow(s, 1./2.);
    node->K=ddup(u);
    dmuldiag(node->K, s);

    dcwpow(s, -1);
    dmuldiag(u, s);
    node->KI=dtrans(u);
    dfree(u);
    dfree(v);
    dfree(s);
    /*we have: K*K'==C */
    return node;
}