def las2rsf(lasf, rsff): las = LASReader(lasf) rsf = m8r.Output(rsff) data = las.data2d shape = data.shape rsf.put('n1', shape[1]) rsf.put('n2', shape[0]) rsf.put('o2', las.start) rsf.put('d2', las.step) rsf.put('null', las.null) k = 0 for name in las.curves.names: k += 1 key = 'key%d' % k rsf.put(key, name) item = las.curves.items[name] rsf.put(key + '_units', item.units) desc = ' '.join(item.descr.translate(None, '"').split()[1:]) rsf.put(name, desc) for name in las.well.names: item = las.well.items[name] desc = item.data.translate(None, '"') rsf.put(name, desc) rsf.write(data) rsf.close()
def las2rsf(lasf, rsff): las = LASReader(lasf) rsf = m8r.Output(rsff) data = las.data2d data = data.astype('float32') shape = data.shape rsf.put('n1', shape[1]) rsf.put('n2', shape[0]) rsf.put('o2', las.start) rsf.put('d2', las.step) rsf.put('null', las.null) k = 0 for name in las.curves.names: k += 1 key = 'key%d' % k rsf.put(key, name) item = las.curves.items[name] rsf.put(key + '_units', item.units) if sys.version_info[0] >= 3: desc = ' '.join( item.descr.translate(str.maketrans('', '', '"')).split()[1:]) else: desc = ' '.join(item.descr.translate(None, '"').split()[1:]) rsf.put(name, desc) for name in las.well.names: item = las.well.items[name] if sys.version_info[0] >= 3: desc = item.data.translate(str.maketrans('', '', '"')) else: desc = item.data.translate(None, '"') rsf.put(name, desc) rsf.write(data) rsf.close()
def np_to_rsf(vel, model_output, d1 = const.dx, d2 = const.dx): ''' Write 2D numpy array vel to rsf file model_output ''' yy = sf.Output(model_output) yy.put('n1',np.shape(vel)[1]) yy.put('n2',np.shape(vel)[0]) yy.put('d1',d1) yy.put('d2',d2) yy.put('o1',0) yy.put('o2',0) yy.write(vel) yy.close()
vout = vt.numb_force_range(vo, oX[1], oX[1] + dX[1] * (nX[1] - 1)) #lmbda = 1#10 #niter = 20 #rho = 0.001 rhoscl = 1e-2 eps = 1e-12 mem = 3 verb = True #epsilon = 0.001 #Fmovie = m8r.Output("updates") moviename = par.string('updates') if moviename is not None: Fmovie = m8r.Output(moviename) vt.put_axis(Fmovie, 2, oX[0], dX[0], nX[0]) vt.put_axis(Fmovie, 3, 0, 1, niter) # vt.put_axis(Fmovie,3,0,1,niter+1) no longer including starting model # Fmovie.write(vo) no longer including starting model in updates else: Fmovie = None #Fmovie.write(vo) #, movie_lst_step, movie_lst_vel vout, costlst, frames = vt.variational_velocity(s, ds, vo, rho, lmbda, epsilon, dX, oX, nX, niter, mem, rhoscl, eps, Fmovie, search_type, verb) vout = vt.numb_force_range(vout, oX[1], oX[1] + dX[1] * (nX[1] - 1))
def main(argv=sys.argv): nt = 300 nx = 64 nz = 300 nb = 50 v = 1.0 top = 3.2 c1 = 0.9 c2 = 6.8 d1 = 0.02 d2 = 0.12 par = m8r.Par(argv) top = par.float('top', 5.0) c1 = par.float('c1', 0.5) c2 = par.float('c2', 5.0) vp = vplot.Vplot() vp.uorig(-c1, -.5) vp.uclip(0., top - 3., 4., top) vp.umove(0., top - 0.) vp.udraw(0., top - 4.) vp.umove(0., top - 0.) vp.udraw(4., top - 0.) z = 0.4 while z < 4: vp.penup() x0 = z * math.tan(math.pi * 45. / 180.) x = 0 while x < 4: t = math.hypot(z, x - x0) / v vp.upendn(x, top - t) x += 0.01 z += 0.4 b = numpy.zeros(nb, 'f') for ib in xrange(nb): b[ib] = math.exp(-3. * (ib + 1.) / 20.) * math.sin(math.pi * (ib + 1) / 10) cs = par.string('c') if cs: c = m8r.Output('c') c.setformat('native_float') c.put('n1', nt) c.put('n2', nx) c.put('d1', d1) c.put('d2', d2) tdat = numpy.zeros((nx, nt), 'f') for iz in range(12): z = (iz + 1.) * nt / 12. x0 = z * math.tan(math.pi * 45. / 180.) for ix in xrange(nx): x = (ix + 1.) * d2 / d1 t = math.hypot(z, x - x0) / v for ib in xrange(nb): it = t + ib - 1 if it < nt: tdat[ix, it] += b[ib] c.write(tdat) vp.uorig(-c2, -.5) vp.uclip(0., top - 3., 4., top) vp.umove(0., top - 0.) vp.udraw(0., top - 4.) vp.umove(0., top - 0.) vp.udraw(4., top - 0.) t = 0.4 while t < 6: vp.penup() x0 = t / math.sin(math.pi * 45. / 180.) theta = -89.5 while theta < 89.5: z = t * math.cos(math.pi * theta / 180) x = x0 + t * math.sin(math.pi * theta / 180) vp.upendn(x, top - z) theta += 1 t += 0.4 ds = par.string('d') if ds: d = m8r.Output('d') d.setformat('native_float') d.put('n1', nz) d.put('n2', nx) d.put('d1', d1) d.put('d1', d2) zdat = numpy.zeros([nx, nz], 'f') for it in range(20): t = (it + 1.) * nz / 20. x0 = t / math.sin(math.pi * 45. / 180.) theta = -89.5 while theta < 89.5: z = t * math.cos(math.pi * theta / 180.) x = x0 + t * math.sin(math.pi * theta / 180.) ix = x * d1 / d2 r = math.hypot(z, x - x0) for ib in xrange(nb): iz = z + ib - 1 if iz >= 0 and iz < nz and ix >= 0 and ix < nx: zdat[ix, iz] += b[ib] * r theta += 1 d.write(zdat)
#!/usr/bin/env python import sys import math import numpy import m8r # initialize par = m8r.Par() inp = m8r.Input() out = m8r.Output() # get dimensions from input n1 = inp.int('n1') n2 = inp.int('n2') # get parameters from command line angle = par.float('angle', 90.) # rotation angle interp = par.string('interp', 'nearest') # [n,l,c] interpolation type # convert degrees to radians angle = angle * math.pi / 180. cosa = math.cos(angle) sina = math.sin(angle) orig = numpy.zeros([n1, n2], 'f') rotd = numpy.zeros([n1, n2], 'f')
def apply(self,uin,uout): n1,n2 = uin.shape uout[2:n1-2,2:n2-2] = \ self.c11*(uin[1:n1-3,2:n2-2]+uin[3:n1-1,2:n2-2]) + \ self.c12*(uin[0:n1-4,2:n2-2]+uin[4:n1 ,2:n2-2]) + \ self.c21*(uin[2:n1-2,1:n2-3]+uin[2:n1-2,3:n2-1]) + \ self.c22*(uin[2:n1-2,0:n2-4]+uin[2:n1-2,4:n2 ]) + \ self.c0*uin[2:n1-2,2:n2-2] par = m8r.Par() # setup I/O files Fr=m8r.Input() # source position Fo=m8r.Output() # output wavefield Fv=m8r.Input ("v") # velocity Fw=m8r.Input ("wav") # source wavefield # Read/Write axes a1 = Fr.axis(1); n1 = a1['n']; d1 = a1['d'] a2 = Fr.axis(2); n2 = a2['n']; d2 = a2['d'] at = Fw.axis(1); nt = at['n']; dt = at['d'] ft = par.int('ft',0) jt = par.int('jt',0) Fo.put('n3',(nt-ft)/jt) Fo.put('d3',jt*dt)
(x-self.xin[i])*(self.yin[i+1]-self.yin[i])/ \ (self.xin[i+1]-self.xin[i]) return self.yin[-1] # create InterpText object to interpolate spnElev.txt spnElev = InterpText() spnElev.read('spnElev.txt') # create InterpText object to interpolate recnoSpn.txt recnoSpn = InterpText() recnoSpn.read('recnoSpn.txt') # set up to read parameters and read and write the seismic data par = m8r.Par() inp = m8r.Input() output = m8r.Output("out") # get locations of the header keys used to initialize geometry #input headers indx_fldr = inp.get_segy_keyindx('fldr') indx_tracf = inp.get_segy_keyindx('tracf') #output headers indx_ep = inp.get_segy_keyindx('ep') indx_sx = inp.get_segy_keyindx('sx') indx_sy = inp.get_segy_keyindx('sy') indx_gx = inp.get_segy_keyindx('gx') indx_gy = inp.get_segy_keyindx('gy') indx_cdp = inp.get_segy_keyindx('cdp') indx_offset = inp.get_segy_keyindx('offset') indx_sdepth = inp.get_segy_keyindx('sdepth') indx_selev = inp.get_segy_keyindx('selev')
import sys import numpy import m8r c0 = -30. / 12. c1 = +16. / 12. c2 = -1. / 12. par = m8r.Par() verb = par.bool("verb", False) # verbosity # setup I/O files Fw = m8r.Input() Fv = m8r.Input("vel") Fr = m8r.Input("ref") Fo = m8r.Output() # Read/Write axes at = Fw.axis(1) nt = at['n'] dt = at['d'] az = Fv.axis(1) nz = az['n'] dz = az['d'] ax = Fv.axis(2) nx = ax['n'] dx = ax['d'] Fo.putaxis(az, 1) Fo.putaxis(ax, 2) Fo.putaxis(at, 3)
bestcost = cost # set array to best best = np.array(v) # record best index bestindex = i # if worst cost if (cost > worstcost) or (i == 0): worstcost = cost worstindex = i worst = np.array(v) print('Best model was %i with cost of %g' % (bestindex, bestcost), file=sys.stderr) print('Worst model was %i with cost of %g' % (worstindex, worstcost), file=sys.stderr) # write output Fout = m8r.Output() # set output sampling vt.put_axis(Fout, 3, 0, 1, 1) Fout.write(best) # record all costs if desired costname = par.string('costs') if costname is not None: Fcost = m8r.Output(costname) vt.put_axis(Fcost, 1, 0, 1, i + 1) vt.put_axis(Fcost, 2, 0, 1, 1) vt.put_axis(Fcost, 3, 0, 1, 1) costs = np.asarray(costlst) Fcost.write(costs) Fcost.close()
#!/usr/bin/env python import numpy from math import sqrt import m8r # initialize parameters par = m8r.Par() # input and output vel = m8r.Input() tim = m8r.Output() # time axis from input nt = vel.int('n1') dt = vel.float('d1') # offset axis from command line nh = par.int('nh', 1) # number of offsets dh = par.float('dh', 0.01) # offset sampling h0 = par.float('h0', 0.0) # first offset # get reflectors nr = par.int('nr', 1) # number of reflectors r = par.ints('r', nr) type = par.string('type', 'hyperbolic') # traveltime computation type niter = par.int('niter', 10) # maximum number of shooting iterations