data = mgr.simulate(slowness=1.0 / vp,
                    scheme=scheme,
                    mesh=mesh,
                    noiseLevel=0.001,
                    noiseAbs=0.001,
                    seed=1337,
                    verbose=True)
mgr.showData(data)
###############################################################################
# Now we invert the synthetic data. We need a new independent mesh without
# information about the layered structure. This mesh can be created manual or
# guessd automatic from the data sensor positions (in this example). We
# tune the maximum cell size in the parametric domain to 15m²
vest = mgr.invert(data,
                  secNodes=2,
                  paraMaxCellSize=15.0,
                  maxIter=10,
                  verbose=True)
np.testing.assert_array_less(mgr.inv.inv.chi2(), 1.1)

###############################################################################
# The manager also holds the method showResult that is used to plot the result.
# Note that only covered cells are shown by default.
# For comparison we plot the geometry on top.

ax, _ = mgr.showResult(cMin=min(vp), cMax=max(vp), logScale=False)
pg.show(geom, ax=ax, fillRegion=False, regionMarker=False)

###############################################################################
# Note that internally the following is called
#
Exemple #2
0
################################################################################
# We initialize the refraction manager.
mgr = TravelTimeManager()

# Alternatively, one can plot a matrix plot of apparent velocities which is the
# more general function also making sense for crosshole data.
ax, cbar = mgr.showData(data)

################################################################################
# Finally, we call the `invert` method and plot the result.The mesh is created
# based on the sensor positions on-the-fly.

mgr.invert(data,
           secNodes=3,
           paraMaxCellSize=5.0,
           zWeight=0.2,
           vTop=500,
           vBottom=5000,
           verbose=1)

ax, cbar = mgr.showResult(logScale=True)
mgr.drawRayPaths(ax=ax, color="w", lw=0.3, alpha=0.5)

################################################################################
# Show result and fit of measured data and model response. You may want to save your results too.
fig = mgr.showResultAndFit()
mgr.saveResult()
################################################################################
# You can play around with the gradient starting model (`vTop` and `vBottom`
# arguments) and the regularization strength `lam`. You can also customize the
# mesh.
    mesh = ra.createMesh(data=ra.data,
                         paraDepth=maxDepth,
                         paraDX=meshDx,
                         paraMaxCellSize=maxTriArea)
    #Plot the mesh
    #pg.show(mesh=mesh)

    #Do the Inversion (time the inversion)
    start1 = time.time()
    ra.inv.maxIter = maxIterations
    #ra.invert(data=ra.data,mesh=mesh,lam=smoothing,zWeight=vertWeight,useGradient=True,vTop=minVel,vBottom=maxVel,maxIter=maxIterations,limits=[100,5000])
    #ra2.invert(data=ra2.data,mesh=mesh,lam=smoothing,zWeight=vertWeight,useGradient=True,vTop=minVel-minVel/1.6,vBottom=maxVel-maxVel/1.6,maxIter=maxIterations,limits=[25,3000])
    ra.invert(data=ra.data,
              mesh=mesh,
              lam=smoothing,
              zWeight=vertWeight,
              useGradient=True,
              vTop=minVel,
              vBottom=maxVel,
              verbose=True)
    end1 = time.time()

    #Print out important model Inversion results
    print('***********P-WAVE RESULTS***********')
    s1 = "Time Elapse (min): " + str("{:0.2f}".format(
        (end1 - start1) / 60)) + " min\n"
    s2 = "Chi2 = " + str("{:0.4f}".format(ra.inv.chi2())) + "\n"
    s3 = "RMS = " + str("{:0.4f}".format(
        1000 * ra.inv._inv.absrms())) + " ms\n"
    s4 = "Total Iterations = " + str("{:0.0f}".format(ra.inv.maxIter)) + "\n"
    print(s1)
    print(s2)
    mesh = ra.createMesh(data=ra.data,
                         paraDepth=maxDepth,
                         paraDX=meshDx,
                         paraMaxCellSize=maxTriArea)
    #Plot the mesh
    #pg.show(mesh=mesh)

    #Do the Inversion (time the inversion)
    start1 = time.time()
    ra.inv.maxIter = maxIterations
    #ra.invert(data=ra.data,mesh=mesh,lam=smoothing,zWeight=vertWeight,useGradient=True,vTop=minVel,vBottom=maxVel,maxIter=maxIterations,limits=[100,5000])
    #ra2.invert(data=ra2.data,mesh=mesh,lam=smoothing,zWeight=vertWeight,useGradient=True,vTop=minVel-minVel/1.6,vBottom=maxVel-maxVel/1.6,maxIter=maxIterations,limits=[25,3000])
    ra.invert(data=ra.data,
              mesh=mesh,
              lam=smoothing,
              zWeight=vertWeight,
              useGradient=True,
              vTop=minVel,
              vBottom=maxVel,
              verbose=True)
    end1 = time.time()

    vel = ra.paraModel()
    vel2Start = vel / 2
    ra2.inv.startModel = vel2Start
    ra2.inv.maxIter = maxIterations
    start2 = time.time()
    ra2.invert(data=ra2.data,
               mesh=mesh,
               lam=smoothing,
               zWeight=vertWeight,
               verbose=True,
# ERT inversion
ert = ERTManager()
ert.setMesh(meshERT)

resinv = ert.invert(ertData, lam=30, zWeight=zWeight, maxIter=maxIter)
print("ERT chi: %.2f" % ert.inv.chi2())
print("ERT rms: %.2f" % ert.inv.inv.relrms())
np.savetxt("res_conventional_%d.dat" % case, resinv)

# Seismic inversion
ttData = pg.DataContainer("tttrue.dat")
print(ttData)
rst = TravelTimeManager(verbose=True)
rst.setMesh(meshRST, secNodes=3)

veltrue = np.loadtxt("veltrue.dat")
startmodel = createGradientModel2D(ttData, meshRST, np.min(veltrue),
                                   np.max(veltrue))
np.savetxt("rst_startmodel_%d.dat" % case, 1 / startmodel)
vest = rst.invert(ttData,
                  zWeight=zWeight,
                  startModel=startmodel,
                  maxIter=maxIter,
                  lam=220)
print("RST chi: %.2f" % rst.inv.chi2())
print("RST rms: %.2f" % rst.inv.inv.relrms())

rst.rayCoverage().save("rst_coverage_%d.dat" % case)
np.savetxt("vel_conventional_%d.dat" % case, vest)
import numpy as np
from matplotlib import pyplot as plt
# Import of PyGimli
import pygimli as pg
from pygimli import meshtools as mt
from pygimli.physics import TravelTimeManager as TTMgr
# Import of TKinker
from tkinter import Tk
from tkinter.filedialog import askopenfilename as askfilename


if __name__ == '__main__':
    root = Tk()
    filename = askfilename(filetypes = (("First-Arrival", "*.sgt"), ("All types", "*.*")))
    root.destroy()
    # Parameters:
    lambdaParam = 10 # Smoothing the model
    depthMax = 50 # Forcing a given depth to the model
    maxCellSize = 2.5 # Forcing a given size for the mesh cells
    zWeightParam = 0.1 # Forcing Horizontal features in the model (smaller than 1) or vertical (larger than 1)
    # Inversion:
    dataTT = pg.DataContainer(filename, 's g t')
    print(dataTT)
    mgr = TTMgr(data=dataTT)
    meshTT = mgr.createMesh(data=dataTT, paraMaxCellSize=maxCellSize, paraDepth=depthMax)
    mgr.invert(data=dataTT, mesh= meshTT, zWeight=zWeightParam, lam=lambdaParam, verbose=True)
    ax,cbar = mgr.showResult(logScale=True)
    mgr.drawRayPaths(ax=ax, color='w', lw=0.3, alpha=0.5)
    plt.show()
    mgr.showCoverage()
    plt.show()