Exemplo n.º 1
0
class TestTT(unittest.TestCase):
    def setUp(self):
        # Dummy data container
        self.data = pg.DataContainer()
        self.data.createSensor([0.0, 0.0])
        self.data.createSensor([1.0, 2.0])
        self.data.resize(1)
        self.data.set("s", pg.Vector(1, 1.0))
        self.data.set("g", pg.Vector(1, 2.0))
        self.data.registerSensorIndex("s")
        self.data.registerSensorIndex("g")

        # Without secondary nodes
        self.mesh = pg.createGrid([0, 1, 2], [0, 1, 2])

        # Slowness
        self.slo = [1, 2, 1, 4]

        self.mgr = TravelTimeManager()

    def test_withoutSecNodes(self):
        fop = self.mgr.fop
        fop.setData(self.data)
        fop.setMesh(self.mesh, ignoreRegionManager=True)
        t = fop.response(self.slo)
        np.testing.assert_allclose(t, 1 + np.sqrt(2))

        data = self.mgr.simulate(slowness=self.slo,
                                 scheme=self.data,
                                 mesh=self.mesh,
                                 secNodes=0)
        np.testing.assert_allclose(data['t'], 1 + np.sqrt(2))

    def test_withSecNodes(self):
        fop = self.mgr.fop
        fop.setData(self.data)
        fop.setMesh(self.mesh.createMeshWithSecondaryNodes(n=3),
                    ignoreRegionManager=True)

        t = fop.response(self.slo)
        np.testing.assert_allclose(t,
                                   np.sqrt(5))  # only works for odd secNodes

        data = self.mgr.simulate(slowness=self.slo,
                                 scheme=self.data,
                                 mesh=self.mesh,
                                 secNodes=3)
        np.testing.assert_allclose(data['t'],
                                   np.sqrt(5))  # only works for odd secNodes

    def test_Jacobian(self):
        fop = self.mgr.fop
        fop.setData(self.data)
        fop.setMesh(self.mesh.createMeshWithSecondaryNodes(n=5),
                    ignoreRegionManager=True)

        fop.createJacobian(self.slo)
        J = fop.jacobian()
        np.testing.assert_allclose(J * self.slo, np.sqrt(5))
Exemplo n.º 2
0
    def setUp(self):
        # Dummy data container
        self.data = pg.DataContainer()
        self.data.createSensor([0.0, 0.0])
        self.data.createSensor([1.0, 2.0])
        self.data.resize(1)
        self.data.set("s", pg.Vector(1, 1.0))
        self.data.set("g", pg.Vector(1, 2.0))
        self.data.registerSensorIndex("s")
        self.data.registerSensorIndex("g")

        # Without secondary nodes
        self.mesh = pg.createGrid([0, 1, 2], [0, 1, 2])

        # Slowness
        self.slo = [1, 2, 1, 4]

        self.mgr = TravelTimeManager()
Exemplo n.º 3
0
# Adapt sensor positions to slope
pos = np.array(scheme.sensors())
for x in pos[:, 0]:
    i = np.where(pos[:, 0] == x)
    new_y = x * slope + 137
    pos[i, 1] = new_y

scheme.setSensors(pos)

###############################################################################
# Now we initialize the TravelTime 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
# model looks correct, we plot it along with the sensor positions.

mgr = TravelTimeManager()
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')
pg.viewer.mpl.drawSensors(ax,
                          scheme.sensors(),
                          diam=0.5,
                          facecolor='white',
                          edgecolor='black')

###############################################################################
# We use this model to create noisified synthetic data and look at the
# traveltime data matrix. Note, we force a specific noise seed as we want
Exemplo n.º 4
0
# into a temporary location. Printing the data reveals that there are 714 data
# points using 63 sensors (shots and geophones) with the data columns s (shot),
# g (geophone), and t (traveltime). By default, there is also a validity flag.

data = pg.getExampleFile("traveltime/koenigsee.sgt", load=True, verbose=True)
print(data)

################################################################################
# Let's have a look at the data in the form of traveltime curves.

fig, ax = pg.plt.subplots()
pg.physics.traveltime.drawFirstPicks(ax, data)

################################################################################
# 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,
    smoothing = 100
    vertWeight = 0.1
    minVel = 1000
    maxVel = 4500
    maxIterations = 15
    #*************************************************************************

    #********** DO INVERSION***************************************************
    #Convert the file
    inFile = convertPicks2Gimli(pickFile, topoFile, minError, maxError)

    #Read in the file with gimli method
    data = loadGimliTT(inFile)

    #Create the structure required for inversion using TravelTimeManager and data container
    ra = TravelTimeManager(data)

    #Generate 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,
    data.resize(nData)
    data['s'] = [source] * nData # only one shot at first sensor
    data['g'] = range(nData)  # and all sensors are receiver geophones

    # Draw initial mesh with velocity distribution
    pg.show(mesh, vel, ax=ax[0, j], label="Velocity (m/s)", hold=True,
            logScale=False, cMap="summer_r", coverage=0.7)
    drawMesh(ax[0, j], mesh, color="white", lw=0.21)

    # We compare the accuracy for 0-5 secondary nodes
    sec_nodes = [0, 1, 5]
    t_all = []
    durations = []
    paths = []

    mgr = TravelTimeManager()

    cols = ["orangered", "blue", "black"]
    recs = [1, 3, 8, 13]

    for i, n in enumerate(sec_nodes):

        # Perform traveltime calculations and log time with pg.tic() & pg.toc()
        pg.tic()
        res = mgr.simulate(vel=vel, scheme=data, mesh=mesh, secNodes=n)
        # We need to copy res['t'] here because res['t'] is a reference to
        # an array in res, and res will be removed in the next iteration.
        # Unfortunately, we don't have any reverence counting for core objects yet.
        t_all.append(res['t'].array())
        durations.append(pg.dur())
        pg.toc("Raytracing with %d secondary nodes:" % n)
                                    isSubSurface=True)
meshERT.save("meshERT_%d.bms" % case)

# 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)
    nRuns = 2
    path2Runs = "/Users/bflinch/Dropbox/Clemson/Research/GithubDevel/PyGimliRefractionInversionScripts/BootstrapInversion/runs/"
    #*************************************************************************

    #********** DO INVERSION***************************************************
    if nRuns > 1:
        for i in range(0, nRuns):
            folderName = "run" + str(i + 1)
            #Convert the file
            inFile = resamplePicks(pickFile, fract2Remove, topoFile, minError,
                                   maxError)
            #Read in the file with gimli method
            data = loadGimliTT(inFile)

            #Create the structure required for inversion using TravelTimeManager and data container
            ra = TravelTimeManager(data)
            #Generate the mesh
            mesh = ra.createMesh(data=ra.data,
                                 paraDepth=maxDepth,
                                 paraDX=meshDx,
                                 paraMaxCellSize=maxTriArea)

            #Do the Inversion (time the inversion)
            start = time.time()
            ra.inv.maxIter = maxIterations
            ra.invert(data=ra.data,
                      mesh=mesh,
                      lam=smoothing,
                      zWeight=vertWeight,
                      useGradient=True,
                      vTop=minVel,
Exemplo n.º 9
0
# points using 63 sensors (shots and geophones) with the data columns s (shot),
# g (geophone), and t (traveltime). By default, there is also a validity flag.

data = pg.getExampleFile("traveltime/koenigsee.sgt", load=True, verbose=True)
print(data)

################################################################################
# Let's have a look at the data in the form of traveltime curves.

fig, ax = pg.plt.subplots()
pg.physics.traveltime.drawFirstPicks(ax, data)

################################################################################
# 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)

################################################################################
Exemplo n.º 10
0
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()
Exemplo n.º 11
0
################################################################################
# We import pyGIMLi and the refraction manager.

import pygimli as pg
from pygimli.physics import TravelTimeManager

################################################################################
# The helper function `pg.getExampleFile` downloads the data set and saves it
# into a temporary location.

data = pg.getExampleFile("traveltime/koenigsee.sgt", load=True, verbose=True)

################################################################################
# We initialize the refraction manager.
mgr = TravelTimeManager()

################################################################################
# Let's have a look at the data in the form of traveltime curves and apparent
# velocity images.
mgr.showData(data)  # show first arrivals as curves (done later with response)
#TODO mgr.showVA(data)  # 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.

mgr.invert(data,
           secNodes=3,
           paraMaxCellSize=5.0,
           zWeight=0.2,
Exemplo n.º 12
0
        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)

ttData = pg.DataContainer("tttrue.dat")
rst = TravelTimeManager(verbose=True)
rst.setData(ttData)
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(ttData("err") / ttData("t"), 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: