Beispiel #1
0
/**
   Read in the WFS grid and amplitude map.
 */
static void read_powfs_locamp(POWFS_S *powfs, const PARMS_S *parms){
    const int npowfs=parms->maos.npowfs;
    for(int ipowfs=0; ipowfs<npowfs; ipowfs++){
	powfs[ipowfs].loc=locread("%s",parms->maos.fnwfsloc[ipowfs]);
	powfs[ipowfs].amp=dread("%s",parms->maos.fnwfsamp[ipowfs]);
	powfs[ipowfs].saloc=locread("%s",parms->maos.fnsaloc[ipowfs]);
	powfs[ipowfs].saloc->dx=parms->maos.dxsa[ipowfs];
	powfs[ipowfs].saloc->dy=parms->maos.dxsa[ipowfs];
	const loc_t *loc=powfs[ipowfs].loc;
	const dmat *amp=powfs[ipowfs].amp;
	const long nsa=parms->maos.nsa[ipowfs];
	const long ptspsa=loc->nloc/nsa;
	if(loc->nloc!=nsa*ptspsa){
	    error("loc %ld does not divide to %ld sa\n",loc->nloc, nsa);
	}
	powfs[ipowfs].locxamp=mycalloc(nsa,double);
	powfs[ipowfs].locyamp=mycalloc(nsa,double);
	for(long isa=0; isa<nsa; isa++){
	    const double* iamp=amp->p+isa*ptspsa;
	    const double* locx=loc->locx+isa*ptspsa;
	    const double* locy=loc->locy+isa*ptspsa;
	    double ampsum=0, locxamp=0, locyamp=0;
	    for(long iloc=0; iloc<ptspsa; iloc++){
		ampsum+=iamp[iloc];
		locxamp+=iamp[iloc]*locx[iloc];
		locyamp+=iamp[iloc]*locy[iloc];
	    }
	    powfs[ipowfs].locxamp[isa]=locxamp/ampsum;
	    powfs[ipowfs].locyamp[isa]=locyamp/ampsum;
	}
    }
}
Beispiel #2
0
static void test_grid_proj(){
    dmat *junk=dread("M3_p.bin");
    dmat *X=dread("M3_x.bin");
    dmat *Y=dread("M3_y.bin");
    dmat *tmp=dread("M3_theta.bin");
    double bx=tmp->p[0];
    double by=tmp->p[1];
    dfree(tmp);
    rmap_t *mapin=calloc(1, sizeof(rmap_t));
    mapin->p=junk->p;
    mapin->ox=X->p[0];
    mapin->oy=Y->p[0];
    mapin->dx=X->p[1]-X->p[0];
    mapin->dy=Y->p[1]-Y->p[0];
    mapin->nx=X->nx*X->ny;
    mapin->ny=Y->nx*Y->ny;
    double d_m3_f=20.;/*from m3 to focus */
    double d_exitpupil_f=46.38661051;
    /*double d_m2_m3=23.59375000; */
    /*double d_m2_f=43.59375000; */
    double d_exitpupil_m3=d_exitpupil_f-d_m3_f;
    double r_exitpupil=1.546220350;
    double r_pupil=15;

    if(X->p[X->nx*X->ny-1]-X->p[0]-mapin->dx*X->nx*X->ny>1.e-10){
	error("X has non even spacing\n");
    }
    if(Y->p[Y->nx*Y->ny-1]-Y->p[0]-mapin->dy*Y->nx*Y->ny>1.e-10){
	error("Y has non even spacing\n");
    }
    free(junk);/*don't dfree */
    dfree(X); dfree(Y);
    /*direction of guide star */
    /*loc_t *loc2=mksqloc2(2000,2000,1./64.); */
    loc_t* loc2=locread("aper_locs.bin");
    
    dmat *amp=dread("aper_amp.bin");
    double *phi2=calloc(1, sizeof(double)*loc2->nloc);
    proj_rect_grid(mapin,M_PI*0.75,M_PI*0.5,
		   loc2,-r_exitpupil/r_pupil,r_exitpupil/r_pupil,
		   amp->p,phi2,-2,d_exitpupil_f,d_exitpupil_m3,-bx,-by);
    /*drawopdamp("test_proj",loc2,phi2,amp,"phi"); */
    
    writedbl(phi2,loc2->nloc,1,"phi");
    /*locwrite(loc2,"loc"); */
}
Beispiel #3
0
int main(int argc, char *argv[]) {
    if(argc<7) {
        info("Usage: %s loc.bin amp.bin cov.bin ncomp pttr wvl1 wvl2 ...\n", argv[0]);
        exit(0);
    }
    enum {
        P_EXE,
        P_LOC,
        P_AMP,
        P_COV,
        P_NCOMP,
        P_PTTR,
        P_WVL
    };
    loc_t *loc=locread("%s",argv[P_LOC]);
    dmat *amp=NULL;
    if(strcmp(argv[P_AMP],"NULL")) {
        amp=dread("%s",argv[P_AMP]);
    } else {
        amp=dnew(loc->nloc,1);
        dset(amp,1);
    }
    dmat *cov=dread("%s",argv[P_COV]);
    long ncomp=strtol(argv[P_NCOMP], NULL, 10);
    long pttr=strtol(argv[P_PTTR], NULL, 10);
    cmat *otf=otf=cnew(ncomp, ncomp);
    dmat *psf=NULL;
    for(int iwvl=0; iwvl<argc-P_WVL; iwvl++) {
        double wvl=strtod(argv[iwvl+P_WVL], NULL);
        double dtheta=wvl/(ncomp*loc->dx);
        genotf(&otf, loc, amp, NULL, NULL, 0, wvl, dtheta, cov, 0, 0, ncomp, ncomp, 1, pttr);
        writebin(otf, "%s_otf_%g.bin", argv[P_COV], wvl);
        cfftshift(otf);
        cfft2i(otf, 1);
        cfftshift(otf);
        creal2d(&psf, 0, otf, 1);
        writebin(psf, "%s_psf_%g.bin", argv[P_COV], wvl);
    }
    cfree(otf);
    dfree(psf);
    dfree(cov);
    dfree(amp);
    locfree(loc);
}