def forward4PM(meshERT, meshRST, schemeERT, schemeSRT, Fx): """Forward response of fx.""" ert = ERTManager() srt = Refraction() phi = 1 - Fx[-1] fpm = FourPhaseModel(phi=phi) rho = fpm.rho(*Fx) slo = fpm.slowness(*Fx) rho = np.append(rho, np.mean(rho)) # outer region rhoVec = rho[meshERT.cellMarkers()] # needs to be copied! sloVec = slo[meshRST.cellMarkers()] dataERT = ert.simulate(meshERT, rhoVec, schemeERT) dataSRT = srt.simulate(meshRST, sloVec, schemeSRT) return dataERT, dataSRT
# Adapt sensor positions to slope pos = np.array(scheme.sensorPositions()) for x in pos[:, 0]: i = np.where(pos[:, 0] == x) new_y = x * slope + 137 pos[i, 1] = new_y scheme.setSensorPositions(pos) ############################################################################### # Now we initialize the refraction manager and asssign P-wave velocities to the # layers. To this end, we create a map from cell markers 0 through 3 to # velocities (in m/s) and generate a velocity vector. To check whether the # it is correct, we plot it # along with the sensor positions ra = Refraction() vp = np.array(mesh.cellMarkers()) vp[vp == 1] = 250 vp[vp == 2] = 500 vp[vp == 3] = 1300 ax, _ = pg.show(mesh, vp, colorBar=True, logScale=False, label='v in m/s') ax.plot(pos[:, 0], pos[:, 1], 'w+') ############################################################################### # We use this model to create noisified synthetic data and look at the # traveltime curves showing three different slopes. data = ra.simulate(mesh, 1.0 / vp, scheme,
paraDomain = pg.load("paraDomain_1.bms") depth = mesh.ymax() - mesh.ymin() ert = ERTManager() resinv = ert.invert(ertData, mesh=mesh, lam=60, zWeight=zWeight, maxIter=maxIter) print("ERT chi:", ert.inv.chi2()) print("ERT rms:", ert.inv.relrms()) np.savetxt("res_conventional.dat", resinv) ############# ttData = pg.DataContainer("rst_filtered.data", "s g") rst = Refraction(ttData) # INVERSION rst.setMesh(mesh, secNodes=3) from pygimli.physics.traveltime import createGradientModel2D minvel = 1000 maxvel = 5000 startmodel = createGradientModel2D(ttData, paraDomain, minvel, maxvel) np.savetxt("rst_startmodel.dat", 1 / startmodel) vest = rst.invert(ttData, mesh=paraDomain, zWeight=zWeight, lam=250) # vest = rst.inv.runChi1() print("RST chi:", rst.inv.chi2()) print("RST rms:", rst.inv.relrms()) rst.rayCoverage().save("rst_coverage.dat")
noiseLevel=0.05, noiseAbs=0.0) ertData.save("erttrue.dat") ert.setData(ertData) ert.setMesh(meshERTFWD) ert.inv.setData(ertData("rhoa")) pg.boxprint("Simulate traveltimes") meshRSTFWD = pg.Mesh() meshRSTFWD.createMeshByMarker(meshERTFWD, 2) vel = pg.RVector() pg.interpolate(mesh, veltrue, meshRSTFWD.cellCenters(), vel) vel = mt.fillEmptyToCellArray(meshRSTFWD, vel, slope=False) ttScheme = createRAData(sensors) rst = Refraction(verbose=True) error = 0.0005 # = 0.5 ms meshRSTFWD.createSecondaryNodes(3) ttData = rst.simulate(meshRSTFWD, 1. / vel, ttScheme, noisify=True, noiseLevel=0.0, noiseAbs=error) ttData.set("err", np.ones(ttData.size()) * error) rst.setData(ttData) rst.dataContainer.save("tttrue.dat")
# Load meshes and data ertScheme = pg.DataContainerERT("ert_filtered.data") fr_min = 0.1 fr_max = 0.9 phi = np.ones(paraDomain.cellCount()) * poro # Setup managers and equip with meshes ert = ERTManager() ert.setMesh(mesh) ert.setData(ertScheme) ert.fop.createRefinedForwardMesh() ttData = pg.DataContainer("rst_filtered.data", "s g") rst = Refraction() rst.setMesh(paraDomain) rst.setData(ttData) rst.fop.createRefinedForwardMesh() # Set errors ttData.set("err", np.ones(ttData.size()) * rste) ertScheme.set("err", np.ones(ertScheme.size()) * erte) if constrained: # Find cells around boreholes to fix ice content to zero fixcells = [] for cell in paraDomain.cells(): x, y, _ = cell.center() if (x > 9) and (x < 11) and (y > -depth_5198): fixcells.append(cell.id())
#!/usr/bin/env python # -*- coding: utf-8 -*- """Example of reading, displaying and inverting refraction data using""" import pygimli as pg from pygimli.physics import Refraction ra = Refraction('koenigsee.sgt') print(ra) ra.showData() # show first arrivals as curves (done later with response) ra.showVA() # show data as apparent velocity image if False: # user defined mesh ra.createMesh() # depth=<user-defined depth>, quality=<trangle quality> ra.showMesh() # show just the mesh for checking # ra.estimateError(absoluteError=0.0006, relativeError=0.001) ra.invert(zWeight=0.2) # # options: vtop/vbottom..gradient starting model velocity, zweight=0.2, lam=30 # ra.showResult() # velocity image, cMin/cMax - color range, logScale=bool ra.showResultAndFit() pg.wait()
#!/usr/bin/env python # -*- coding: utf-8 -*- """ Example refraction script applied to an example file (shaly bedrock detection from Günther&Rücker (2006), EAGE Near Surface) """ import os import pygimli as pg from pygimli.physics import Refraction # load example file explicitly from same directory (if called from elsewhere) workpath=os.path.dirname(__file__) if len(workpath) == 0: workpath = '.' ra = Refraction(workpath + '/example_topo.sgt') # ra = Refraction() # ra.loadData(os.path.dirname(__file__) + '/example_topo.sgt') print(ra) if False: # possible (typical) actions ra.showData() # show only data (right after init) ra.showVA() # show apparent velocity image ra.createMesh(depth=15.) # pass non-default meshing options ra.invert(lam=300, zWeight=0.1) # use vtop/vbottom for startmodel ra.showResultAndFit() # typical output: model and data with response pg.wait()
phi.append(1 - frtrue[idx]) phi = np.array(phi) fr_min = 0 fr_max = 1 else: phi = poro fpm = FourPhaseModel(phi=phi) # Setup managers and equip with meshes ert = ERTManager() ert.setMesh(meshERT) ert.setData(ertScheme) ert.fop.createRefinedForwardMesh() rst = Refraction("tttrue.dat", verbose=True) ttData = rst.dataContainer rst.setMesh(meshRST, secNodes=3) # Setup joint modeling and inverse operators JM = JointMod(meshRST, ert, rst, fpm, fix_poro=fix_poro, zWeight=0.25) data = pg.cat(ttData("t"), ertScheme("rhoa")) error = pg.cat(rst.relErrorVals(ttData), ertScheme("err")) # Set gradient starting model of f_ice, f_water, f_air = phi/3 velstart = np.loadtxt("rst_startmodel_%d.dat" % case) rhostart = np.ones_like(velstart) * np.mean(ertScheme("rhoa")) fas, fis, fws, _ = fpm.all(rhostart, velstart) frs = np.ones_like(fas) - fpm.phi if not fix_poro:
pg.boxprint("Calculating case %s" % case) # Load meshes and data ertScheme = pg.DataContainerERT("ert_filtered.data") fr_min = 0.1 fr_max = 0.9 phi = np.ones(paraDomain.cellCount()) * poro # Setup managers and equip with meshes ert = ERTManager() ert.setMesh(mesh) ert.setData(ertScheme) ert.fop.createRefinedForwardMesh() rst = Refraction("rst_filtered.data", verbose=True) ttData = rst.dataContainer rst.setMesh(paraDomain) rst.fop.createRefinedForwardMesh() # Set errors ttData.set("err", np.ones(ttData.size()) * rste) ertScheme.set("err", np.ones(ertScheme.size()) * erte) if constrained: # Find cells around boreholes to fix ice content to zero fixcells = [] for cell in paraDomain.cells(): x, y, _ = cell.center() if (x > 9) and (x < 11) and (y > -depth_5198): fixcells.append(cell.id())
################################################################################ # We import pyGIMLi and the refraction manager. import pygimli as pg from pygimli.physics import Refraction ################################################################################ # The helper function `pg.getExampleFile` downloads the data set and saves it # into a temporary location. filename = pg.getExampleFile("traveltime/koenigsee.sgt") ################################################################################ # We initialize an instance of the refraction manager with the filename. ra = Refraction(filename) print(ra) ################################################################################ # Let's have a look at the data in the form of traveltime curves and apparent # velocity images. ra.showData() # show first arrivals as curves (done later with response) ra.showVA() # show data as apparent velocity image ################################################################################ # Finally, we call the `invert` method and plot the result.The mesh is created # based on the sensor positions on-the-fly. Yes, it is really as simple as that. ra.invert(zWeight=0.2) ra.showResult()