map4 stretch4_init (int n1, float o1, float d1 /* regular axis */, int nd /* data samples */, float eps /* regularization */) /*< initialize >*/ { int i; map4 str; str = (map4) sf_alloc (1, sizeof(*str)); str->nt = n1; str->t0 = o1; str->dt = d1; str->nd = nd; str->eps = eps; str->x = sf_intalloc (nd); str->m = sf_boolalloc (nd); str->w = sf_floatalloc2 (4,nd); str->diag = sf_floatalloc (str->nt); for (i = 0; i < 3; i++) { str->offd[i] = sf_floatalloc (str->nt-1-i); } str->slv = sf_banded_init (str->nt,3); str->tslv = sf_spline4_init(str->nt); return str; }
void fixbad (int niter /* number of iterations */, sf_filter aa /* PEF */, int ny /* data size */, float *yy /* in - data, out - deburst */) /*< find bad data and restore it >*/ { int iy; float *rr, *rabs, rbar; bool *known; rr = sf_floatalloc(ny); rabs = sf_floatalloc(ny); known = sf_boolalloc(ny); sf_helicon_init(aa); sf_helicon_lop (false,false,ny,ny,yy,rr); for (iy=0; iy < ny; iy++) rabs[iy] = fabsf (rr[iy]); rbar = sf_quantile(ny/2,ny,rabs); for (iy=0; iy < ny; iy++) known[iy] = (bool) ((yy[iy] > 0.) && (fabsf(rr[iy]) < 4. * rbar)); mis2 (niter, ny, yy, aa, known, 0., true); free(rr); free(rabs); free(known); }
sf_map sf_stretch_init (int n1, float o1, float d1 /* regular axis */, int nd /* data length */, float eps /* regularization */, bool narrow /* if zero boundary */) /*< initialize >*/ { sf_map str; str = (sf_map) sf_alloc (1, sizeof(*str)); str->nt = n1; str->t0 = o1; str->dt = d1; str->nd = nd; str->eps = eps; str->narrow = narrow; str->x = sf_intalloc (nd); str->m = sf_boolalloc (nd); str->w = sf_floatalloc (nd); str->diag = sf_floatalloc (n1); str->offd = sf_floatalloc (n1-1); str->slv = sf_tridiagonal_init (n1); return str; }
void mask4freq (int nw /* filter size */, int nj /* dealiasing stretch */, int nx, int ny /* data size */, float *yy /* data [ny][nx] */, bool *mm /* mask [ny][nx]*/) /*< mask in 2-D frequency filter>*/ { int ix, iy, iw, is, n, i; bool *xx; n=nx*ny; xx = sf_boolalloc(n); for (i=0; i < n; i++) { xx[i] = (bool) (yy[i] == 0.); mm[i] = false; } for (iy=0; iy < ny-1; iy++) { for (ix = nw*nj; ix < nx-nw*nj; ix++) { i=ix + nx*iy; for (iw = 0; iw <= 2*nw; iw++) { is = (iw-nw)*nj; mm[i] = (bool) (mm[i] || xx[i-is]); } } } free(xx); }
void stretch_init ( int n1 /* trace length */, float o1 /* trace origin */, float d1 /* trace sampling */, int n2 /* number of data samples */) /*< initialization >*/ { nt = n1; t0 = o1; dt = d1; nd = n2; x = sf_intalloc(nd); m = sf_boolalloc(nd); w = sf_floatalloc(nd); }
void tomo2_init (float*** rays, int *raylen, int nrays, float o1, float o2, float d1, float d2, int n1, int n2, interpolator interp, int nf_in) { int ir, id, i1, i2, nd; float x1, x2, rx; nf = nf_in; m1 = n1; m2 = n2; nr = nrays; rl = raylen; nxy = (int***) sf_alloc(nr,sizeof(int**)); mask = (bool**) sf_alloc(nr,sizeof(bool*)); w1 = (float***) sf_alloc(nr,sizeof(float**)); w2 = (float***) sf_alloc(nr,sizeof(float**)); for (ir = 0; ir < nr; ir++) { nd = rl[ir]; nxy[ir] = sf_intalloc2(2,nd); mask[ir] = sf_boolalloc(nd); w1[ir] = sf_floatalloc2(nf,nd); w2[ir] = sf_floatalloc2(nf,nd); for (id = 0; id < nd; id++) { rx = (rays[ir][id][0] - o1)/d1; i1 = (int) floor(rx + 1. - 0.5*nf); x1 = rx - floor(rx); rx = (rays[ir][id][1] - o2)/d2; i2 = (int) floor(rx + 1. - 0.5*nf); x2 = rx - floor(rx); if (i1 > - nf && i1 < n1 && i2 > - nf && i2 < n2) { mask[ir][id] = false; interp (x1, nf, w1[ir][id]); interp (x2, nf, w2[ir][id]); nxy[ir][id][0] = i1; nxy[ir][id][1] = i2; } else { mask[ir][id] = true; } } } }
void medbin_init (float **coord /* coordinates [nd][2] */, float o1, float o2, float d1, float d2, int n1, int n2 /* axes */, int nd_in /* number of data points */) /*< initialize >*/ { int id, im, i1, i2, start; nd = nd_in; nm = n1*n2; ct = sf_intalloc(nm); pt = sf_intalloc(nm); k = sf_intalloc(nd); m = sf_boolalloc(nd); bd = sf_floatalloc(nd); for (im=0; im < nm; im++) { ct[im] = 0.; } for (id = 0; id < nd; id++) { i1 = 0.5 + (coord[id][0] - o1)/d1; i2 = 0.5 + (coord[id][1] - o2)/d2; m[id] = (bool) ((i1 >= 0) && (i1 < n1) && (i2 >= 0) && (i2 < n2)); if (m[id]) { im = i2*n1+i1; ct[im]++; k[id] = im; } } start = 0; for (im=0; im < nm; im++) { pt[im] = start; start += ct[im]; } }
int main(int argc, char* argv[]) { int i, niter, n1, n2, n12, i3, n3, rect1, rect2, order; float *mm, *dd, **pp, lam; bool *known; sf_file in, out, dip, mask; sf_init (argc,argv); in = sf_input("in"); out = sf_output("out"); dip = sf_input("dip"); if (!sf_histint(in,"n1",&n1)) sf_error("No n1= in input"); if (!sf_histint(in,"n2",&n2)) sf_error("No n2= in input"); n12 = n1*n2; n3 = sf_leftsize(in,2); if (!sf_getint("niter",&niter)) niter=100; /* number of iterations */ if (!sf_getint("order",&order)) order=1; /* accuracy order */ pp = sf_floatalloc2(n1,n2); mm = sf_floatalloc(n12); known = sf_boolalloc(n12); if (NULL != sf_getstring ("mask")) { mask = sf_input("mask"); dd = sf_floatalloc(n12); } else { mask = NULL; dd = NULL; } if (!sf_getint("rect1",&rect1)) rect1=3; if (!sf_getint("rect2",&rect2)) rect2=3; /* smoothing radius */ pwdsl_init(n1,n2,order,rect1,rect2,0.01); pwdsl_set(pp); sf_mask_init(known); for (i3=0; i3 < n3; i3++) { sf_warning("slice %d of %d",i3+1,n3); sf_floatread(mm,n12,in); if (NULL != mask) { sf_floatread(dd,n12,mask); } else { dd = mm; } /* figure out scaling and make known data mask */ lam = 0.; for (i=0; i < n12; i++) { if (dd[i] != 0.) { known[i] = true; lam += 1.; } else { known[i] = false; } } lam = sqrtf(lam/n12); /* read dip */ sf_floatread(pp[0],n12,dip); sf_conjgrad_init(n12, n12, n12, n12, lam, 10*FLT_EPSILON, true, true); sf_conjgrad(NULL,sf_mask_lop,pwdsl_lop,dd,mm,mm,niter); sf_conjgrad_close(); sf_floatwrite (mm,n12,out); } exit(0); }
int main(int argc, char* argv[]) { bool verb,isreversed; sf_file Fs,Fr,Fi,Fc; /* I/O files */ sf_axis az,ax,at,ac,aa; /* cube axes */ int nz,nx,nt, nhx, nhz, nht,nc; int it, ihx, ihz, iht,ic; int nhx2,nhz2,nht2; off_t iseek; float ***us=NULL,***ur=NULL,****ii=NULL; pt2d *cc=NULL; bool *ccin=NULL; float cxmin,czmin; float cxmax,czmax; int icx, icz; int mcx, mcz, mct; int pcx, pcz, pct; int **mcxall, **pcxall; int **mczall, **pczall; int *mctall, *pctall; int lht; float scale; /* gaussian taper */ bool gaus; float gsx,gsz,gst; /* std dev */ float gx, gz, gt; /*------------------------------------------------------------*/ /* init RSF */ sf_init(argc,argv); /* OMP parameters */ #ifdef _OPENMP omp_init(); #endif if(! sf_getbool("verb",&verb)) verb=false; /* verbosity flag */ if(! sf_getbool("isreversed",&isreversed)) isreversed=false; /* reversed rec wfld? */ Fs = sf_input ("in" ); /* source wavefield */ Fr = sf_input ("ur" ); /* receiver wavefield */ Fc = sf_input ("cc" ); /* CIP coordinates */ Fi = sf_output("out"); /* image */ /*------------------------------------------------------------*/ /* read axes */ az=sf_iaxa(Fs,1); nz = sf_n(az); ax=sf_iaxa(Fs,2); nx = sf_n(ax); at=sf_iaxa(Fs,3); nt = sf_n(at); /* CIP coordinates */ ac = sf_iaxa(Fc,2); sf_setlabel(ac,"cc"); sf_setunit(ac,""); nc = sf_n(ac); if(! sf_getint("nhz",&nhz)) nhz=0; nhz2=2*nhz+1; /* z lags */ if(! sf_getint("nhx",&nhx)) nhx=0; nhx2=2*nhx+1; /* x lags */ if(! sf_getint("nht",&nht)) nht=0; nht2=2*nht+1; /* t lags */ lht=2*nht; if(verb) { sf_warning("nhx=%3d nhz=%3d nht=%3d",nhx2,nhz2,nht2); sf_raxa(az); sf_raxa(ax); sf_raxa(at); sf_raxa(ac); } /* set output axes */ aa=sf_maxa(nhz2,-nhz*sf_d(az),sf_d(az)); sf_setlabel(aa,"hz"); sf_setunit(aa,""); if(verb) sf_raxa(aa); sf_oaxa(Fi,aa,1); aa=sf_maxa(nhx2,-nhx*sf_d(ax),sf_d(ax)); sf_setlabel(aa,"hx"); sf_setunit(aa,""); if(verb) sf_raxa(aa); sf_oaxa(Fi,aa,2); aa=sf_maxa(nht2,-nht*sf_d(at),sf_d(at)); sf_setlabel(aa,"ht"); sf_setunit(aa,""); if(verb) sf_raxa(aa); sf_oaxa(Fi,aa,3); sf_oaxa(Fi,ac,4); if(! sf_getbool("gaus",&gaus)) gaus=false; /* Gaussian taper flag */ if(gaus) { if(! sf_getfloat("gsx",&gsx)) gsx=nhx*sf_d(ax); gsx=1./(2*gsx*gsx); if(! sf_getfloat("gsz",&gsz)) gsz=nhz*sf_d(az); gsz=1./(2*gsz*gsz); if(! sf_getfloat("gst",&gst)) gst=nht*sf_d(at); gst=1./(2*gst*gst); } /*------------------------------------------------------------*/ /* allocate work arrays */ us=sf_floatalloc3(nz,nx,nht2); ur=sf_floatalloc3(nz,nx,nht2); ii=sf_floatalloc4(nhz2,nhx2,nht2,nc); /* zero output */ for(ic=0; ic<nc; ic++) { for (iht=0; iht<nht2; iht++) { for (ihx=0; ihx<nhx2; ihx++) { for(ihz=0; ihz<nhz2; ihz++) { ii[ic][iht][ihx][ihz] = 0; } } } } /*------------------------------------------------------------*/ /* CIP coordinates */ cc= (pt2d*) sf_alloc(nc,sizeof(*cc)); pt2dread1(Fc,cc,nc,2); mcxall=sf_intalloc2(nhx2,nc); pcxall=sf_intalloc2(nhx2,nc); mczall=sf_intalloc2(nhz2,nc); pczall=sf_intalloc2(nhz2,nc); ccin=sf_boolalloc(nc); cxmin = sf_o(ax) + nhx *sf_d(ax); cxmax = sf_o(ax) + (sf_n(ax)-1-nhx)*sf_d(ax); czmin = sf_o(az) + nhz *sf_d(az); czmax = sf_o(az) + (sf_n(az)-1-nhz)*sf_d(az); if(verb) { sf_warning("cxmin=%f,cxmax=%f",cxmin,cxmax); sf_warning("czmin=%f,czmax=%f",czmin,czmax); } for(ic=0; ic<nc; ic++) { ccin[ic]=(cc[ic].x>=cxmin && cc[ic].x<=cxmax && cc[ic].z>=czmin && cc[ic].z<=czmax)?true:false; if(ccin[ic]) { icx = 0.5+(cc[ic].x-sf_o(ax))/sf_d(ax); for(ihx=-nhx; ihx<nhx+1; ihx++) { mcxall[ic][nhx+ihx] = icx-ihx; pcxall[ic][nhx+ihx] = icx+ihx; } icz = 0.5+(cc[ic].z-sf_o(az))/sf_d(az); for(ihz=-nhz; ihz<nhz+1; ihz++) { mczall[ic][nhz+ihz] = icz-ihz; pczall[ic][nhz+ihz] = icz+ihz; } } } mctall=sf_intalloc(nht2); pctall=sf_intalloc(nht2); for (iht=0; iht<nht2; iht++) { mctall[iht]=iht; pctall[iht]=2*nht-iht; } /*------------------------------------------------------------*/ if(isreversed) { /* receiver wavefield is reversed */ /* read wavefield @ [0...2nht-1]*/ for(iht=0;iht<2*nht;iht++) { sf_floatread(us[iht][0],nz*nx,Fs); sf_floatread(ur[iht][0],nz*nx,Fr); } if(verb) fprintf(stderr,"nt\n"); for(it=nht;it<nt-nht;it++) { if(verb) fprintf(stderr,"\b\b\b\b\b\b\b\b\b\b%04d",it); /* read wavefield @ [2nht]*/ sf_floatread(us[ lht ][0],nz*nx,Fs); sf_floatread(ur[ lht ][0],nz*nx,Fr); #ifdef _OPENMP #pragma omp parallel for schedule(dynamic) \ private(ic, \ ihx,ihz,iht, \ mcx,mcz,mct, \ pcx,pcz,pct) \ shared (nc,ii,us,ur, \ nhx2, nhz2, nht2, \ mcxall,mczall,mctall, \ pcxall,pczall,pctall,ccin) #endif for(ic=0; ic<nc; ic++) { if(ccin[ic]) { for (iht=0; iht<nht2; iht++) { mct=mctall [iht]; pct=pctall [iht]; for (ihx=0; ihx<nhx2; ihx++) { mcx=mcxall[ic][ihx]; pcx=pcxall[ic][ihx]; for(ihz=0; ihz<nhz2; ihz++) { mcz=mczall[ic][ihz]; pcz=pczall[ic][ihz]; ii[ic][iht][ihx][ihz] += us[mct][mcx][mcz]*ur[pct][pcx][pcz]; } /* ihz */ } /* ihx */ } /* iht */ } } /* ic */ /* update wavefield index (cycle) */ for(iht=0;iht<nht2;iht++) { mctall[iht] = (mctall[iht]+1) % nht2; pctall[iht] = (pctall[iht]+1) % nht2; } lht = (lht+1) % nht2; } /* it */ if(verb) fprintf(stderr,"\n"); } else { /* receiver wavefield is NOT reversed */ /* read wavefield @ [0...2nht-1]*/ for(iht=0;iht<2*nht;iht++) { sf_floatread(us[iht][0],nz*nx,Fs); iseek = (off_t)(nt-1-iht)*nz*nx*sizeof(float); sf_seek(Fr,iseek,SEEK_SET); sf_floatread(ur[iht][0],nz*nx,Fr); } if(verb) fprintf(stderr,"nt\n"); for(it=nht;it<nt-nht;it++) { if(verb) fprintf(stderr,"\b\b\b\b\b\b\b\b\b\b%04d",nt-nht-1-it); /* read wavefield @ [2nht]*/ sf_floatread(us[ lht ][0],nz*nx,Fs); iseek=(off_t)(nt-nht-1-it)*nz*nx*sizeof(float); sf_seek(Fr,iseek,SEEK_SET); sf_floatread(ur[ lht ][0],nz*nx,Fr); #ifdef _OPENMP #pragma omp parallel for schedule(dynamic) \ private(ic, \ ihx,ihz,iht, \ mcx,mcz,mct, \ pcx,pcz,pct) \ shared (nc,ii,us,ur, \ nhx2, nhz2, nht2, \ mcxall,mczall,mctall, \ pcxall,pczall,pctall,ccin) #endif for(ic=0; ic<nc; ic++) { if(ccin[ic]) { for (iht=0; iht<nht2; iht++) { mct=mctall [iht]; pct=pctall [iht]; for (ihx=0; ihx<nhx2; ihx++) { mcx=mcxall[ic][ihx]; pcx=pcxall[ic][ihx]; for(ihz=0; ihz<nhz2; ihz++) { mcz=mczall[ic][ihz]; pcz=pczall[ic][ihz]; ii[ic][iht][ihx][ihz] += us[mct][mcx][mcz]*ur[pct][pcx][pcz]; } /* ihz */ } /* ihx */ } /* iht */ } } /* ic */ /* update wavefield index (cycle) */ for(iht=0;iht<nht2;iht++) { mctall[iht] = (mctall[iht]+1) % nht2; pctall[iht] = (pctall[iht]+1) % nht2; } lht = (lht+1) % nht2; } /* it */ if(verb) fprintf(stderr,"\n"); } /* end "is reversed" */ /*------------------------------------------------------------*/ /*------------------------------------------------------------*/ /* scale image */ scale = 1./nt; for(ic=0; ic<nc; ic++) { for (iht=0; iht<nht2; iht++) { for (ihx=0; ihx<nhx2; ihx++) { for(ihz=0; ihz<nhz2; ihz++) { ii[ic][iht][ihx][ihz] *= scale; } } } } /*------------------------------------------------------------*/ /* apply Gaussian taper */ if(gaus) { for(ic=0; ic<nc; ic++) { for (iht=0;iht<nht2;iht++) { gt=(iht-nht)*sf_d(at); gt*=gt; for (ihx=0;ihx<nhx2;ihx++) { gx=(ihx-nhx)*sf_d(ax); gx*=gx; for(ihz=0;ihz<nhz2;ihz++) { gz=(ihz-nhz)*sf_d(az); gz*=gz; ii[ic][iht][ihx][ihz] *= exp(-gt*gst - gx*gsx - gz*gsz); } } } } } /*------------------------------------------------------------*/ /* write image */ sf_floatwrite(ii[0][0][0],nc*(nhx2)*(nhz2)*(nht2),Fi); /*------------------------------------------------------------*/ /* deallocate arrays */ free(***ii); free(**ii); free(*ii); free(ii); free(*us); free(us); free(*ur); free(ur); free(cc); free(ccin); free(*mcxall); free(mcxall); free(*pcxall); free(pcxall); free(*mczall); free(mczall); free(*pczall); free(pczall); /*------------------------------------------------------------*/ exit (0); }
int main(int argc, char* argv[]) { int niter, n1, n2, i, nf1, nf2, nf3, nf4, nf5, nf6, n3, n4, i4, nf; float *mm, *kk, *filt, eps; bool *known, exact, verb; sf_file in, out, fil, mask=NULL; sf_init (argc,argv); in = sf_input("in"); fil = sf_input("filt"); out = sf_output("out"); if (!sf_getint("niter",&niter)) niter=100; /* Number of iterations */ if (!sf_getbool("exact",&exact)) exact=true; /* If y, preserve the known data values */ if (!sf_getfloat("eps",&eps)) eps=0.; /* regularization parameter */ if (!sf_getbool("verb",&verb)) verb = false; /* verbosity flag */ /* input data, output model */ if (!sf_histint(in,"n1",&n1)) sf_error("No n1= in input"); if (!sf_histint(in,"n2",&n2)) sf_error("No n2= in input"); if (!sf_histint(in,"n3",&n3)) sf_error("No n3= in input"); n4 = sf_leftsize(in,3); if (1==n1 && 1==n2 && 1==n3) { if (!sf_histint(in,"n4",&n1)) sf_error("No n4= in input"); if (!sf_histint(in,"n5",&n2)) sf_error("No n5= in input"); if (!sf_histint(in,"n6",&n3)) sf_error("No n6= in input"); n4 = sf_leftsize(in,6); } sf_fileflush(out,in); /* copy data dimensions */ /* input filter */ if (!sf_histint(fil,"n1",&nf1)) sf_error("No n1= in filter"); if (!sf_histint(fil,"n2",&nf2)) sf_error("No n2= in filter"); if (!sf_histint(fil,"n3",&nf3)) sf_error("No n3= in filter"); if (!sf_histint(fil,"n4",&nf4)) sf_error("No n4= in filter"); if (!sf_histint(fil,"n5",&nf5)) sf_error("No n5= in filter"); if (!sf_histint(fil,"n6",&nf6)) sf_error("No n6= in filter"); if (nf4!=n1 || nf5!=n2 || nf6!=n3) sf_error("need n1==nf4 && n2==nf5 && n3==nf6"); nf = nf1*nf2*nf3*nf4*nf5*nf6; filt = sf_floatalloc(nf); mm = sf_floatalloc(n1*n2*n3); kk = sf_floatalloc(n1*n2*n3); known = sf_boolalloc(n1*n2*n3); for (i=0; i < n1*n2*n3; i++) { mm[i]=0.; kk[i]=0.; known[i]=false; } if (NULL != sf_getstring("mask")) { /* optional input mask file for known data */ mask = sf_input("mask"); } for (i4=0; i4 < n4; i4++) { sf_warning("slice %d of %d",i4+1,n4); sf_floatread(mm,n1*n2*n3,in); sf_floatread(filt,nf,fil); if (NULL != sf_getstring("mask")) { sf_floatread(kk,n1*n2*n3,mask); for (i=0; i < n1*n2*n3; i++) { known[i] = (bool) (kk[i] != 0.); } } else { for (i=0; i < n1*n2*n3; i++) { known[i] = (bool) (mm[i] != 0.); } } if (exact) { for (i=0; i < n1*n2*n3; i++) { if (known[i]) kk[i] = mm[i]; } } nmis3(niter, nf1, nf2, nf3, nf4, nf5, nf6, filt, mm, known, eps, verb); if (exact) { for (i=0; i < n1*n2*n3; i++) { if (known[i]) mm[i] = kk[i]; } } sf_floatwrite(mm,n1*n2*n3,out); } exit (0); }
int main(int argc, char* argv[]) { int i, niter, nw, n1, n2, n12, i1, i3, n3, iter, order; float *mm, *dd, *dd2, *dd3, **pp, *m; float eps, perc; char *type, *oper; bool verb, *known; sf_file in, out, dip, mask=NULL; sf_init (argc,argv); in = sf_input("in"); out = sf_output("out"); dip = sf_input("dip"); if (!sf_histint(in,"n1",&n1)) sf_error("No n1= in input"); if (!sf_histint(in,"n2",&n2)) sf_error("No n2= in input"); n12 = n1*n2; n3 = sf_leftsize(in,2); if (!sf_getint("niter",&niter)) niter=20; /* number of iterations */ if (!sf_getint("order",&nw)) nw=1; /* [1,2,3] accuracy order */ if (nw < 1 || nw > 3) sf_error ("Unsupported nw=%d, choose between 1 and 3",nw); if (NULL == (type=sf_getstring("type"))) type="biorthogonal"; /* [haar,linear,biorthogonal] wavelet type, the default is biorthogonal */ if (NULL == (oper=sf_getstring("oper"))) oper="bregman"; /* [bregman,thresholding] method, the default is bregman */ if (!sf_getbool("verb",&verb)) verb = false; /* verbosity flag */ if (!sf_getfloat("eps",&eps)) eps=0.01; /* regularization parameter */ if (!sf_getfloat("perc",&perc)) perc=99.; /* percentage for soft thresholding */ if (!sf_getint("order",&order)) order=1; /* accuracy order */ pp = sf_floatalloc2(n1,n2); mm = sf_floatalloc(n12); dd = sf_floatalloc(n12); known = sf_boolalloc(n12); m = sf_floatalloc(n12); dd2 = sf_floatalloc(n12); dd3 = sf_floatalloc(n12); if (NULL != sf_getstring ("mask")) { mask = sf_input("mask"); } else { mask = NULL; } sf_sharpen_init(n12,perc); seislet_init(n1,n2,true,true,eps,order,type[0]); seislet_set(pp); for (i3=0; i3 < n3; i3++) { if (verb) { sf_warning("slice %d of %d",i3+1,n3); } else { sf_warning("slice %d of %d;",i3+1,n3); } sf_floatread(dd,n12,in); sf_floatread(pp[0],n12,dip); if (NULL != mask) { sf_floatread(m,n12,mask); for (i=0; i < n12; i++) { known[i] = (bool) (m[i] != 0.); } } else { for (i=0; i < n12; i++) { known[i] = (bool) (dd[i] != 0.); } } for (i1=0; i1 < n12; i1++) { dd2[i1] = 0.; dd3[i1] = 0.; } for (iter=0; iter < niter; iter++) { /* Start iteration */ switch (oper[0]) { case 'b': if (verb) sf_warning("Bregman iteration %d of %d;",iter+1,niter); for (i1=0; i1 < n12; i1++) { if (known[i1]) { dd3[i1]= dd[i1]+dd3[i1]-dd2[i1]; } } for (i1=0; i1 < n12; i1++) { if (known[i1]) { dd2[i1]= 0.; } } for (i1=0; i1 < n12; i1++) { dd2[i1]+= dd3[i1]; } break; case 't': if (verb) sf_warning("Thresholding iteration %d of %d;", iter+1,niter); for (i1=0; i1 < n12; i1++) { if (known[i1]) { dd3[i1]= dd[i1]+dd3[i1]-dd2[i1]; } } for (i1=0; i1 < n12; i1++) { dd2[i1] = dd3[i1]; } break; default: sf_error("Unknown wavelet type=%c",oper); break; } seislet_lop(true,false,n12,n12,mm,dd2); /* Thresholding */ sf_sharpen(mm); sf_weight_apply(n12, mm); seislet_lop(false,false,n12,n12,mm,dd2); } /* End interation */ for (i1=0; i1 < n12; i1++) { dd[i1] = dd2[i1]; } sf_floatwrite (dd,n12,out); } sf_sharpen_close(); sf_warning("."); exit(0); }
int main(int argc, char* argv[]) { int i, ia, na, nx, ns, dim, niter; int n[SF_MAX_DIM], m[SF_MAX_DIM], a[SF_MAX_DIM]; float a0, eps, *mm, *pp; bool verb, *known; sf_filter aa; char* lagfile; sf_file in, out, filt, lag, mask; sf_init (argc,argv); in = sf_input("in"); filt = sf_input("filt"); out = sf_output("out"); dim = sf_filedims (in,n); if (!sf_histint(filt,"n1",&na)) sf_error("No n1= in filt"); aa = sf_allocatehelix (na); if (!sf_histfloat(filt,"a0",&a0)) a0=1.; if (!sf_histints(filt,"a",a,dim)) { for (i=0; i < dim; i++) { a[i]=1; } } if (NULL != (lagfile = sf_getstring("lag")) /* file with filter lags */ || NULL != (lagfile = sf_histstring(filt,"lag"))) { lag = sf_input(lagfile); sf_intread(aa->lag,na,lag); } else { lag = NULL; for( ia=0; ia < na; ia++) { aa->lag[ia] = ia+1; } } if (!sf_getints ("n",m,dim) && (NULL == lag || !sf_histints (lag,"n",m,dim))) { for (i=0; i < dim; i++) { m[i] = n[i]; } } if (NULL != lag) sf_fileclose(lag); bound (dim, m, n, a, aa); sf_floatread (aa->flt,na,filt); sf_fileclose(filt); for( ia=0; ia < na; ia++) { aa->flt[ia] /= a0; } if (!sf_getint ("ns",&ns)) sf_error("Need ns="); /* scaling */ if (!sf_getint("niter",&niter)) niter=100; /* Number of iterations */ if (!sf_getfloat("eps",&eps)) eps=1.; /* regularization parameter */ if (!sf_getbool("verb",&verb)) verb=true; /* verbosity flag */ nx = 1; for( i=0; i < dim; i++) { nx *= n[i]; } mm = sf_floatalloc (nx); pp = sf_floatalloc (nx); known = sf_boolalloc (nx); sf_mask_init(known); hshape_init (nx,ns,aa); sf_conjgrad_init(nx, nx, nx, nx, eps, 1.e-8, verb, false); if (NULL != sf_getstring("mask")) { /* optional input mask file for known data */ mask = sf_input("mask"); sf_floatread(mm,nx,mask); sf_fileclose(mask); for (i=0; i < nx; i++) { known[i] = (bool) (mm[i] != 0.); } sf_floatread(mm,nx,in); } else { sf_floatread(mm,nx,in); for (i=0; i < nx; i++) { known[i] = (bool) (mm[i] != 0.); } } sf_conjgrad(NULL, sf_mask_lop, hshape_lop, pp, mm, mm, niter); sf_floatwrite (mm,nx,out); exit (0); }
int main (int argc, char *argv[]) { int n1,n2, n12, niter, i; float eps, lam, p0, q0, p1, q1, *u, **p; bool verb, *m; sf_file in, out, mask; sf_init(argc,argv); in = sf_input ("in"); out = sf_output ("out"); if (SF_FLOAT != sf_gettype(in)) sf_error("Need float type"); if (!sf_histint(in,"n1",&n1)) sf_error("Need n1= in input"); if (!sf_histint(in,"n2",&n2)) sf_error("Need n2= in input"); n12 = n1*n2; sf_putint(out,"n3",4); if (!sf_getint("niter",&niter)) niter=5; /* number of iterations */ if (!sf_getfloat("eps",&eps)) eps=1; /* vertical smoothness */ if (!sf_getfloat("lam",&lam)) lam=1; /* horizontal smoothness */ eps = sqrtf(12*eps+1.); lam = sqrtf(12*lam+1.); if (!sf_getfloat("p0",&p0)) p0=1.; /* initial first component */ if (!sf_getfloat("q0",&q0)) q0=1.; /* initial first component */ if (!sf_getfloat("p1",&p1)) p1=-1.; /* initial second component */ if (!sf_getfloat("q1",&q1)) q1=1.; /* initial second component */ if (!sf_getbool("verb",&verb)) verb = false; /* verbosity flag */ /* initialize spectral estimation */ twofreq2_init(n1, n2, (int) eps, (int) lam); u = sf_floatalloc(n12); p = sf_floatalloc2(n12,4); /* allocate mask */ if (NULL != sf_getstring("mask")) { m = sf_boolalloc(n12); mask = sf_input("mask"); } else { mask = NULL; m = NULL; } /* initialize mask */ if (NULL != mask) { sf_floatread(u,n12,mask); mask4freq (2, 1, n1, n2, u, m); } /* read data */ sf_floatread(u,n12,in); /* initialize components */ for(i=0; i < n12; i++) { p[0][i] = p0; p[1][i] = q0; p[2][i] = p1; p[3][i] = q1; } /* estimate components */ twofreq2(niter, verb, u, p, m); /* write components */ sf_floatwrite(p[0],n12*4,out); exit (0); }
int main(int argc, char* argv[]) { int i, niter, n1, n2, n12, i3, n3, ns, order, np; float *mm, *dd, *xx, **pp, **qq, lam, eps; bool *known; sf_file in, out, dip, mask; sf_init (argc,argv); in = sf_input("in"); out = sf_output("out"); dip = sf_input("dip"); if (!sf_histint(in,"n1",&n1)) sf_error("No n1= in input"); if (!sf_histint(in,"n2",&n2)) sf_error("No n2= in input"); n12 = n1*n2; n3 = sf_leftsize(in,2); if (!sf_getint("niter",&niter)) niter=100; /* number of iterations */ if (!sf_getint("order",&order)) order=1; /* accuracy order */ pp = sf_floatalloc2(n1,n2); mm = sf_floatalloc(n12); xx = sf_floatalloc(n12); known = sf_boolalloc(n12); np = sf_leftsize(dip,2); if (np > n3) { qq = sf_floatalloc2(n1,n2); } else { qq = NULL; } if (NULL != sf_getstring ("mask")) { mask = sf_input("mask"); dd = sf_floatalloc(n12); } else { mask = NULL; dd = NULL; } if (!sf_getint("ns",&ns)) ns=1; /* smoothing radius */ if (!sf_getfloat("eps",&eps)) eps=0.01; /* regularization */ sf_mask_init(known); for (i3=0; i3 < n3; i3++) { sf_warning("slice %d of %d",i3+1,n3); sf_floatread(mm,n12,in); for (i=0; i < n12; i++) { xx[i] = mm[i]; } if (NULL != mask) { sf_floatread(dd,n12,mask); } else { dd = mm; } /* figure out scaling and make known data mask */ lam = 0.; for (i=0; i < n12; i++) { if (dd[i] != 0.) { known[i] = true; lam += 1.; } else { known[i] = false; } } lam = sqrtf(lam/n12); /* read dip */ sf_floatread(pp[0],n12,dip); sf_conjgrad_init(n12, n12, n12, n12, lam, 10*FLT_EPSILON, true, true); if (NULL != qq) { sf_floatread(qq[0],n12,dip); pwsmooth2_init(ns, n1, n2, order, eps, pp, qq); sf_conjgrad(NULL,sf_mask_lop,pwsmooth2_lop,xx,mm,mm,niter); pwsmooth2_close(); } else { pwsmooth_init(ns, n1, n2, order, eps, pp); sf_conjgrad(NULL,sf_mask_lop,pwsmooth_lop,xx,mm,mm,niter); pwsmooth_close(); } sf_conjgrad_close(); sf_floatwrite (mm,n12,out); } exit(0); }
/*------------------------------------------------------------*/ int main(int argc, char* argv[]) { bool verb; /* verbosity flag */ bool pos; /* direction of spraying */ bool adj; /* adjoint operator flag */ bool wflcausal, oprcausal; /* causal wfl?, opr? */ sf_file Fopr, Fwfl, Fimg, Fcip; /* I/O files */ float ****opr=NULL,****wfl=NULL,*****img=NULL; int itO,itW; sf_axis az,ax,ay,at,ac,aa; /* wfld axes */ int nz,nx,ny,nt,nc; int iz,ix,iy,it,ic; sf_axis ahx, ahy, ahz, aht; /* EIC axes */ int nhx, nhy, nhz, nht; int ihx, ihy, ihz, iht; float dhx, dhy, dhz, dht; pt3d *cc=NULL; bool *ccin=NULL; float cxmin,czmin,cymin; float cxmax,czmax,cymax; int icx, icz, icy; int mcx, mcz, mcy, mct; int pcx, pcz, pcy, pct; int **mcxall, **pcxall; int **mcyall, **pcyall; int **mczall, **pczall; int *mctall, *pctall; int lht,fht; /* last buffer index */ float scale; /* time summation scaling */ int nslice; /* wavefield slice size */ bool gaus; /* gaussian taper */ float gsx,gsy,gsz,gst; /* std dev */ /*------------------------------------------------------------*/ sf_init(argc,argv); #ifdef _OPENMP omp_init(); #endif if(! sf_getbool( "verb",&verb )) verb=false; /* verbosity flag */ if(! sf_getbool( "positive",&pos )) pos=true; /* if positive sprays opr to positive shits, else, sprays to negative shifts */ if(! sf_getbool( "adj",&adj )) adj=false; /* adjoint flag */ if(! sf_getbool("wflcausal",&wflcausal)) wflcausal=false; /* causal wfl? */ if(! sf_getbool("oprcausal",&oprcausal)) oprcausal=false; /* causal opr? */ /*------------------------------------------------------------*/ Fopr = sf_input ("opr" ); /* operator */ az=sf_iaxa(Fopr,1); if(verb) sf_raxa(az); nz = sf_n(az); ax=sf_iaxa(Fopr,2); if(verb) sf_raxa(ax); nx = sf_n(ax); ay=sf_iaxa(Fopr,3); if(verb) sf_raxa(ay); ny = sf_n(ay); at=sf_iaxa(Fopr,4); if(verb) sf_raxa(at); nt = sf_n(at); scale = 1./nt; /* time summation scaling */ nslice = nz*nx*ny*sizeof(float); /* wavefield slice */ Fcip = sf_input ("cip" ); /* CIP coordinates */ ac = sf_iaxa(Fcip,2); sf_setlabel(ac,"c"); sf_setunit(ac,""); if(verb) sf_raxa(ac); nc = sf_n(ac); /*------------------------------------------------------------*/ /* setup output */ if(adj) { Fimg = sf_input ("in"); /* read img */ ahz=sf_iaxa(Fimg,1); nhz=(sf_n(ahz)-1)/2; if(verb) sf_raxa(ahz); ahx=sf_iaxa(Fimg,2); nhx=(sf_n(ahx)-1)/2; if(verb) sf_raxa(ahx); ahy=sf_iaxa(Fimg,3); nhy=(sf_n(ahy)-1)/2; if(verb) sf_raxa(ahy); aht=sf_iaxa(Fimg,4); nht=(sf_n(aht)-1)/2; if(verb) sf_raxa(aht); aa=sf_maxa(1,0,1); sf_setlabel(aa,""); sf_setunit(aa,""); /* set output axes */ Fwfl = sf_output("out"); /* write wfl */ sf_oaxa(Fwfl,az,1); sf_oaxa(Fwfl,ax,2); sf_oaxa(Fwfl,ay,3); sf_oaxa(Fwfl,at,4); sf_oaxa(Fwfl,aa,5); } else { Fwfl = sf_input ( "in"); /* read wfl */ if(! sf_getint("nhz",&nhz)) nhz=0; /* z lags */ dhz=2*sf_d(az); ahz=sf_maxa(2*nhz+1,-nhz*dhz,dhz); sf_setlabel(ahz,"hz"); sf_setunit(ahz,""); if(verb) sf_raxa(ahz); if(! sf_getint("nhx",&nhx)) nhx=0; /* x lags */ dhx=2*sf_d(ax); ahx=sf_maxa(2*nhx+1,-nhx*dhx,dhx); sf_setlabel(ahx,"hx"); sf_setunit(ahx,""); if(verb) sf_raxa(ahx); if(! sf_getint("nhy",&nhy)) nhy=0; /* y lags */ dhy=2*sf_d(ay); ahy=sf_maxa(2*nhy+1,-nhy*dhy,dhy); sf_setlabel(ahy,"hy"); sf_setunit(ahy,""); if(verb) sf_raxa(ahy); if(! sf_getint("nht",&nht)) nht=0; /* t lags */ dht=2*sf_d(at); aht=sf_maxa(2*nht+1,-nht*dht,dht); sf_setlabel(aht,"ht"); sf_setunit(aht,""); if(verb) sf_raxa(aht); Fimg = sf_output("out"); /* write img */ sf_oaxa(Fimg,ahz,1); sf_oaxa(Fimg,ahx,2); sf_oaxa(Fimg,ahy,3); sf_oaxa(Fimg,aht,4); sf_oaxa(Fimg, ac,5); } /*------------------------------------------------------------*/ if(! sf_getbool("gaus",&gaus)) gaus=false; /* Gaussian taper */ if(gaus) { if(! sf_getfloat("gsx",&gsx)) gsx=0.25*sf_n(ahx)*sf_d(ahx); gsx=(nhx==0)?1:1./(2*gsx*gsx); if(! sf_getfloat("gsy",&gsy)) gsy=0.25*sf_n(ahy)*sf_d(ahy); gsy=(nhy==0)?1:1./(2*gsy*gsy); if(! sf_getfloat("gsz",&gsz)) gsz=0.25*sf_n(ahz)*sf_d(ahz); gsz=(nhz==0)?1:1./(2*gsz*gsz); if(! sf_getfloat("gst",&gst)) gst=0.25*sf_n(aht)*sf_d(aht); gst=(nht==0)?1:1./(2*gst*gst); } /*------------------------------------------------------------*/ /* allocate arrays */ opr=sf_floatalloc4(nz,nx,ny,sf_n(aht)); wfl=sf_floatalloc4(nz,nx,ny,sf_n(aht)); img=sf_floatalloc5(sf_n(ahz),sf_n(ahx),sf_n(ahy),sf_n(aht),sf_n(ac)); /*------------------------------------------------------------*/ /* CIP coordinates */ cc= (pt3d*) sf_alloc(nc,sizeof(*cc)); pt3dread1(Fcip,cc,nc,3); mcxall=sf_intalloc2(sf_n(ahx),sf_n(ac)); pcxall=sf_intalloc2(sf_n(ahx),sf_n(ac)); mcyall=sf_intalloc2(sf_n(ahy),sf_n(ac)); pcyall=sf_intalloc2(sf_n(ahy),sf_n(ac)); mczall=sf_intalloc2(sf_n(ahz),sf_n(ac)); pczall=sf_intalloc2(sf_n(ahz),sf_n(ac)); ccin=sf_boolalloc(sf_n(ac)); cxmin = sf_o(ax) + nhx *sf_d(ax); cxmax = sf_o(ax) + (sf_n(ax)-1-nhx)*sf_d(ax); cymin = sf_o(ay) + nhy *sf_d(ay); cymax = sf_o(ay) + (sf_n(ay)-1-nhy)*sf_d(ay); czmin = sf_o(az) + nhz *sf_d(az); czmax = sf_o(az) + (sf_n(az)-1-nhz)*sf_d(az); for(ic=0;ic<nc;ic++) { ccin[ic]=(cc[ic].x>=cxmin && cc[ic].x<=cxmax && cc[ic].y>=cymin && cc[ic].y<=cymax && cc[ic].z>=czmin && cc[ic].z<=czmax)?true:false; if(ccin[ic]) { icx = 0.5+(cc[ic].x-sf_o(ax))/sf_d(ax); for(ihx=-nhx; ihx<nhx+1; ihx++) { mcxall[ic][nhx+ihx] = icx-ihx; pcxall[ic][nhx+ihx] = icx+ihx; } icy = 0.5+(cc[ic].y-sf_o(ay))/sf_d(ay); for(ihy=-nhy; ihy<nhy+1; ihy++) { mcyall[ic][nhy+ihy] = icy-ihy; pcyall[ic][nhy+ihy] = icy+ihy; } icz = 0.5+(cc[ic].z-sf_o(az))/sf_d(az); for(ihz=-nhz; ihz<nhz+1; ihz++) { mczall[ic][nhz+ihz] = icz-ihz; pczall[ic][nhz+ihz] = icz+ihz; } } } mctall=sf_intalloc(sf_n(aht)); pctall=sf_intalloc(sf_n(aht)); for (iht=0; iht<sf_n(aht); iht++) { mctall[iht]= iht; pctall[iht]=sf_n(aht)-1-iht; } if(adj) { /* ADJIONT OPERATOR */ for(iht=0;iht<sf_n(aht);iht++) CICLOOP( wfl[iht][iy][ix][iz]=0; ); /* zero wfl */ for(it=0;it<nt;it++) sf_floatwrite(wfl[0][0][0],nz*nx*ny,Fwfl); /* reserve wfl */ sf_seek(Fwfl,0,SEEK_SET); /* seek back */ sf_floatread(img[0][0][0][0],sf_n(ac)*sf_n(ahy)*sf_n(ahx)*sf_n(ahz)*sf_n(aht),Fimg); /* read img */ ; applyScaling (img,ac,aht,ahx,ahy,ahz,scale); /* scaling */ if(gaus) applyGaussian(img,ac,aht,ahx,ahy,ahz,gst,gsx,gsy,gsz); /* Gaussian */ lht=0; itO=-999999; itW=-999999; for(it=-nht;it<nt+nht;it++) { if(verb) fprintf(stderr,"\b\b\b\b\b\b%04d",it); fht=(lht+1) % sf_n(aht); if(it<nt-nht) { itO = it + nht; if( !oprcausal ) sf_seek(Fopr,(off_t)(nt-1-itO)*nslice,SEEK_SET); else sf_seek(Fopr,(off_t) itO *nslice,SEEK_SET); sf_floatread(opr[ lht ][0][0],nz*nx*ny,Fopr); } for(iht=0;iht<sf_n(aht);iht++) { mctall[iht] = (mctall[iht]+1) % sf_n(aht); /* cycle iht index */ pctall[iht] = (pctall[iht]+1) % sf_n(aht); } if(it>=0+nht && it<nt-nht) { #ifdef _OPENMP #pragma omp parallel for schedule(dynamic) \ private(ic, ihx,ihy,ihz,iht,mcx, mcy, mcz, mct, pcx, pcy, pcz, pct) \ shared (nc,ccin,ahx,ahy,ahz,aht,mcxall,mcyall,mczall,mctall,pcxall,pcyall,pczall,pctall) #endif for(ic=0;ic<nc;ic++){ if(ccin[ic]) { /* sum over c only! */ if(pos){ EICLOOP( wfl [mct][mcy][mcx][mcz] += opr [pct][pcy][pcx][pcz] * img[ic][iht][ihy][ihx][ihz]; ); }else{ EICLOOP( wfl [pct][pcy][pcx][pcz] += opr [mct][mcy][mcx][mcz] * img[ic][iht][ihy][ihx][ihz]; ); } } }