Пример #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))
Пример #2
0
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
# reproducable results for testing purposes.
# TODO: show first arrival traveltime curves.
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)
    # 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)

        for r, p in enumerate(recs):
            if r == 0:
                lab = "Raypath with %d sec nodes" % n
            else:
                lab = None

            recNode = mgr.fop.mesh().findNearestNode([sensors[p], 0.0])
            sourceNode = mgr.fop.mesh().findNearestNode([0.0, 0.0])