Exemplo n.º 1
0
static void test_cov(){/*not good */
    rand_t rstat;
    int seed=4;
    double r0=0.2;
    double dx=1./64;
    long N=1+1024;
    long nx=N;
    long ny=N;
    long nframe=1;
    seed_rand(&rstat, seed);
    map_t *atm=mapnew(nx, ny, dx,dx, NULL);
    cmat *atmhat=cnew((N+1)*3,(N+1)*3);
    dmat *atmhattot=dnew((N+1)*3,(N+1)*3);
    //cfft2plan(atmhat,-1);
    //cfft2plan(atmhat, 1);
    dset((dmat*)atm,1);
    cembedd(atmhat, (dmat*)atm, 0);
    cfft2(atmhat, -1);
    cabs22d(&atmhattot, 1, atmhat, 1);
    ccpd(&atmhat, atmhattot);
    cfft2i(atmhat, 1);
    cfftshift(atmhat);
    dmat *denom=dnew((N+1)*3,(N+1)*3);
    dmat *cov=dnew((N+1)*3,(N+1)*3);
    creal2d(&denom, 0, atmhat, 1);
    writebin(denom, "denom.bin");
    
    dzero(atmhattot);
    for(long i=0; i<nframe; i++){
	info("%ld of %ld\n", i, nframe);
	
	for(long j=0; j<nx*ny; j++){
	    atm->p[j]=randn(&rstat);
	}
	fractal_do((dmat*)atm, dx, r0,L0,ninit);
	/*mapwrite(atm, "atm_%ld.bin", i); */
	cembedd(atmhat, (dmat*)atm, 0);
	cfft2(atmhat, -1);
	cabs22d(&atmhattot, 1, atmhat, 1);

	if(i==0 || (i+1)%10==0){
	    dscale(atmhattot, 1./(i+1));
	    ccpd(&atmhat, atmhattot);
	    writebin(atmhattot, "atm_psf_%ld.bin",i+1);
	    cfft2i(atmhat, 1);
	    cfftshift(atmhat);
	    creal2d(&cov, 0, atmhat, 1);
	    for(long k=0; k<cov->nx*cov->ny; k++){
		cov->p[k]/=denom->p[k];
	    }
	    writebin(cov, "atm_cov_%ld.bin",i+1);
	}
    }
}
Exemplo n.º 2
0
/**
   Convert PSD into time series.*/
dmat* psd2time(const dmat *psdin, rand_t *rstat, double dt, int nstepin){
    if(!psdin){
	error("psdin cannot be null\n");
    }
    long nstep=nextpow2(nstepin);
    double df=1./(dt*nstep);
    dmat *fs=dlinspace(0, df, nstep);
    dmat *psd=NULL;
    if(psdin->ny==1){//[alpha, beta, fmin, fmax] discribes power law with cut on/off freq.
	psd=dnew(nstep, 1);
	double alpha=psdin->p[0];
	double beta=psdin->p[1];
	long i0=1, imax=nstep;
	if(psdin->nx>2){
	    i0=(long)round(psdin->p[2]/df);
	    if(i0<1) i0=1;
	}
	if(psdin->nx>3){
	    imax=(long)round(psdin->p[3]/df);
	}
	info("fmin=%g, fmax=%g, df=%g, i0=%ld, imax=%ld\n", 
	     psdin->p[2], psdin->p[3], df, i0, imax);
	for(long i=i0; i<imax; i++){
	    psd->p[i]=beta*pow(i*df, alpha);
	}
    }else if(psdin->ny==2){
	if(psdin->nx<2){ 
	    error("Invalid PSD\n");
	}
	psd=dinterp1(psdin, 0, fs, 1e-40);
	psd->p[0]=0;/*disable pistion. */
    }else{
	error("psdin is invalid format.\n");
    }
    cmat *wshat=cnew(nstep, 1);
    //cfft2plan(wshat, -1);
    for(long i=0; i<nstep; i++){
	wshat->p[i]=sqrt(psd->p[i]*df)*COMPLEX(randn(rstat), randn(rstat));
    }
    cfft2(wshat, -1);
    dmat *out=NULL;
    creal2d(&out, 0, wshat, 1);
    cfree(wshat);
    dfree(psd);
    dfree(fs);
    dresize(out, nstepin, 1);
    return out;
}
Exemplo n.º 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);
}