Exemple #1
0
    def test_region_marker_position_two_ways_v2(self):
        rect1 = mt.createRectangle(
            start=[0.0, -1.5],
            end=[4.0, -4.0],
            isClosed=True,
            marker=1,
        )

        # scaled version
        rect2 = mt.createRectangle(
            pos=[2.0, -2.75],
            size=[4.0, 2.5],
            isClosed=True,
            marker=2,
        )
        assert rect1.regionMarkers()[0].x() == 4 * 0.2
        assert rect1.regionMarkers()[0].y() == -1.5 - 2.5 * 0.2

        assert rect1.regionMarkers()[0].marker() == 1
        assert rect2.regionMarkers()[0].marker() == 2

        assert rect1.regionMarkers()[0].x() == rect1.regionMarkers()[0].x()
        assert rect2.regionMarkers()[0].x() == rect2.regionMarkers()[0].x()

        assert rect1.regionMarkers()[0].y() == rect1.regionMarkers()[0].y()
        assert rect2.regionMarkers()[0].y() == rect2.regionMarkers()[0].y()
Exemple #2
0
    def test_region_marker_position_two_ways_v2(self):
        rect1 = mt.createRectangle(
            start=[0.0, -1.5],
            end=[4.0, -4.0],
            isClosed=True,
            marker=1,
        )

        # scaled version
        rect2 = mt.createRectangle(
            pos=[2.0, -2.75],
            size=[4.0, 2.5],
            isClosed=True,
            marker=2,
        )
        assert rect1.regionMarker()[0].x() == 4 * 0.2
        assert rect1.regionMarker()[0].y() == -1.5 - 2.5 * 0.2

        assert rect1.regionMarker()[0].marker() == 1
        assert rect2.regionMarker()[0].marker() == 2

        assert rect1.regionMarker()[0].x() == rect1.regionMarker()[0].x()
        assert rect2.regionMarker()[0].x() == rect2.regionMarker()[0].x()

        assert rect1.regionMarker()[0].y() == rect1.regionMarker()[0].y()
        assert rect2.regionMarker()[0].y() == rect2.regionMarker()[0].y()
def generate_hom_world_with_inclusion(world_dim: list, incl_start: list,
                                      incl_dim: list):
    """ Creates a homogeneous world with inclusion.

    Utility function to create a homogeneous world with an inclusion. Region markers are set to 1 for the background
    world and 2 for the inclusion.

    Parameter:
        world_dim: World dimensions as [x,z].
        incl_start: Inclusion upper left corner as [x,z].
        incl_dim: Inclusion dimension as [x,z].

    Returns:
        The created world.
    """
    # Create geometric objects
    world = mt.createWorld(start=[0, 0], end=[world_dim[0], -world_dim[1]])
    inclusion = mt.createRectangle(
        start=incl_start,
        end=[incl_start[0] + incl_dim[0], incl_start[1] - incl_dim[1]],
        marker=2,
        boundaryMarker=10)
    # Merge geometries
    geom = mt.mergePLC([world, inclusion])
    return geom
Exemple #4
0
def simulateSynth(model, tMax=5000, satSteps=150, ertSteps=10, area=0.1,
                  synthPath='synth/'):
    """Create synthetic example."""

    if not os.path.exists('synth/'):
        os.mkdir(synthPath)

    world = mt.createWorld(start=[-20, 0], end=[20, -16], layers=[-2, -8],
                           worldMarker=False)
    for i, b in enumerate(world.boundaries()):
        b.setMarker(i + 1)

    block = mt.createRectangle(start=[-6, -3.5], end=[6, -6.0], marker=4,
                               boundaryMarker=11, area=area)
    geom = mt.mergePLC([world, block])
    geom.save(synthPath + 'synthGeom')
    # pg.show(geom, boundaryMarker=1)

    paraMesh = pg.meshtools.createMesh(geom, quality=32, area=area,
                                       smooth=[1, 10])

    # translate 1 2 3 4 - > 0 1 2 3
    mapMarker = np.array([0, 0, 1, 2, 3], 'float')
    paraMesh.setCellMarkers(mapMarker[np.array(paraMesh.cellMarkers())])
    paraMesh.save(synthPath + 'synth.bms')

    fop = HydroGeophysicalModelling(mesh=paraMesh, tMax=tMax,
                                    satSteps=satSteps,
                                    ertSteps=ertSteps,
                                    verbose=1)

    # openblas have some problems with to high thread count ..
    # we need to dig into
    print("ThreadCount:", pg.threadCount())
    pg.setThreadCount(4)

    print('##### Simulate synthetic data ' + '#'*50)
    pg.tic()
    rhoaR = fop.response(pg.RVector(model)[paraMesh.cellMarkers()])
    pg.toc()
    print('#'*100)

    # add some noise here
    rand = pg.RVector(len(rhoaR))
    pg.randn(rand)

    rhoaR *= (1.0 + rand * fop.ws.derr.flatten())
    fop.ws.rhoaR = rhoaR.reshape(fop.ws.derr.shape)

    # fop.ws.mesh.save(synthPath + 'synth.bms')
    np.save(synthPath + 'synthK', fop.ws.k)
    np.save(synthPath + 'synthVel', fop.ws.vel)
    np.save(synthPath + 'synthSat', fop.ws.sat)

    fop.ws.scheme.save(synthPath + 'synth.shm', 'a b m n')
    np.save(synthPath + 'synthRhoaRatio', fop.ws.rhoaR)
    np.save(synthPath + 'synthRhoa', fop.ws.rhoa)
    np.save(synthPath + 'synthErr', fop.ws.derr)
def generate_layered_world_with_inclusion(world_dim: list, layer_heights: list,
                                          incl_start: list, incl_dim: list):
    """ Creates a layered world with inclusion.

    Utility function to create a layered world with an inclusion. Region markers are starting at 1 and increasing with
    depth. The inclusion has the highest marker number.

    Parameter:
        world_dim: World dimensions as [x,z].
        layer_heights: Heights of the single layers.
        incl_start: Inclusion upper left corner as [x,z].
        incl_dim: Inclusion dimension as [x,z].

    Returns:
        The created world.
    """
    # Check parameter integrity
    if sum(layer_heights) > world_dim[1]:
        return None
    # Create geometric objects
    world = mt.createWorld(start=[0, 0], end=[world_dim[0], -world_dim[1]])
    current_depth = 0
    layers = []
    for i in range(len(layer_heights)):
        layer = mt.createRectangle(
            start=[0, -current_depth],
            end=[world_dim[0], -(current_depth + layer_heights[i])],
            marker=i + 1,
            boundaryMarker=10)
        current_depth += layer_heights[i]
        layers.append(layer)
    if current_depth != world_dim[1]:
        layer = mt.createRectangle(start=[0, -current_depth],
                                   end=[world_dim[0], -world_dim[1]],
                                   marker=i + 2,
                                   boundaryMarker=10)
        layers.append(layer)
    inclusion = mt.createRectangle(
        start=incl_start,
        end=[incl_start[0] + incl_dim[0], incl_start[1] - incl_dim[1]],
        marker=len(layers) + 1,
        boundaryMarker=10)
    # Merge geometries
    geom = mt.mergePLC([world, inclusion] + layers)
    return geom
Exemple #6
0
 def test_region_marker_position_translation_scale(self):
     rect1 = mt.createRectangle(
         pos=[1.0, 2.0],
         size=[2.0, 4],
         isClosed=True,
         marker=20,
     )
     assert rect1.regionMarkers()[0].x() == -0.3
     assert rect1.regionMarkers()[0].y() == 0.3
     assert rect1.regionMarkers()[0].marker() == 20
Exemple #7
0
 def test_region_marker_position_basics(self):
     rect1 = mt.createRectangle(
         start=[0.0, 0.0],
         end=[2.0, -1.0],
         isClosed=True,
         marker=1,
     )
     # by default the region marker should be located at
     # sPos + (ePos - sPos) * 0.2)
     assert rect1.regionMarkers()[0].x() == 0.4
     assert rect1.regionMarkers()[0].y() == -0.2
     assert rect1.regionMarkers()[0].marker() == 1
Exemple #8
0
 def test_region_marker_position_translation_scale(self):
     rect1 = mt.createRectangle(
         pos=[1.0, 2.0],
         size=[2.0, 4],
         isClosed=True,
         marker=20,
     )
     # by default the region marker should be located at
     # sPos + (ePos - sPos) * 0.2)
     assert rect1.regionMarker()[0].x() == 0.4
     assert rect1.regionMarker()[0].y() == 4 - 4 * 0.2
     assert rect1.regionMarker()[0].marker() == 20
Exemple #9
0
 def test_region_markerposition_pos_size(self):
     # scaled version
     rect1 = mt.createRectangle(
         pos=[2.0, -2.75],
         size=[4.0, 2.5],
         isClosed=True,
         marker=5,
         markerPosition=[0.0, 0.0],
     )
     assert rect1.regionMarkers()[0].x() == 0
     assert rect1.regionMarkers()[0].y() == 0
     assert rect1.regionMarkers()[0].marker() == 5
Exemple #10
0
    def test_region_markerposition_start_end(self):
        rect1 = mt.createRectangle(
            start=[0.0, -1.5],
            end=[4.0, -4.0],
            isClosed=True,
            marker=10,
            markerPosition=[0.0, 0.0],
        )
        assert rect1.regionMarkers()[0].x() == 0
        assert rect1.regionMarkers()[0].y() == 0

        assert rect1.regionMarkers()[0].marker() == 10
Exemple #11
0
 def test_region_markerposition_pos_size(self):
     # scaled version
     rect1 = mt.createRectangle(
         pos=[2.0, -2.75],
         size=[4.0, 2.5],
         isClosed=True,
         marker=5,
         markerPosition=[0.0, 0.0],
     )
     assert rect1.regionMarker()[0].x() == 0
     assert rect1.regionMarker()[0].y() == 0
     assert rect1.regionMarker()[0].marker() == 5
Exemple #12
0
    def test_region_markerposition_start_end(self):
        rect1 = mt.createRectangle(
            start=[0.0, -1.5],
            end=[4.0, -4.0],
            isClosed=True,
            marker=10,
            markerPosition=[0.0, 0.0],
        )
        assert rect1.regionMarker()[0].x() == 0
        assert rect1.regionMarker()[0].y() == 0

        assert rect1.regionMarker()[0].marker() == 10
Exemple #13
0
 def test_region_marker_position_basics(self):
     rect1 = mt.createRectangle(
         start=[0.0, 0.0],
         end=[2.0, -1.0],
         isClosed=True,
         marker=1,
     )
     # by default the region marker should be located at
     # sPos + (ePos - sPos) * 0.2)
     assert rect1.regionMarker()[0].x() == 0.4
     assert rect1.regionMarker()[0].y() == -0.2
     assert rect1.regionMarker()[0].marker() == 1
Exemple #14
0
 def test_region_marker_position_translation_scale(self):
     rect1 = mt.createRectangle(
         pos=[1.0, 2.0],
         size=[2.0, 4],
         isClosed=True,
         marker=20,
     )
     # by default the region marker should be located at
     # sPos + (ePos - sPos) * 0.2)
     assert rect1.regionMarker()[0].x() == 0.4
     assert rect1.regionMarker()[0].y() == 4 - 4 * 0.2
     assert rect1.regionMarker()[0].marker() == 20
Exemple #15
0
def testCBarLevels():
    """
    Expectations
    ------------
    axs[0, 0]: show regions with plc
        Show needs to deliver the regions with Set3 colormap. Each tick on the
        colobar should be in the middle of the related color section.

    axs[1, 0]: show regions with mesh
        really the same thing as on axs[0, 0] but with mesh.

    ax[0, 1]: show mesh with cell data
        if nLevs is given i would expect that the colormap then is levelled.
        currently that is not the fact. but at least its the full range. labels
        need to be at begin/end of each color section.

    ax[1, 1]: show mesh with node data
        the colorbar range misses parts of its full range. labels need to be
        at begin/end of each color section.
    """
    # create a geometry
    world = mt.createWorld(start=[-10, 0],
                           end=[10, -16],
                           layers=[-8],
                           worldMarker=False)

    block = mt.createRectangle(start=[-6, -3.5],
                               end=[6, -6.0],
                               marker=4,
                               boundaryMarker=10,
                               area=0.1)

    circ = mt.createCircle(pos=[0, -11], marker=5, radius=2, boundaryMarker=11)

    poly = mt.mergePLC([world, block, circ])
    mesh = mt.createMesh(poly, quality=34)

    # create random data
    rhomap = [[1, 10], [2, 4], [4, 20], [5, 8]]
    # map data to cell/node count
    cell_data = pg.solver.parseArgToArray(rhomap, mesh.cellCount(), mesh)
    node_data = mt.cellDataToNodeData(mesh, cell_data)

    # plot everything
    fig, axs = pg.plt.subplots(2, 2, figsize=(20, 10))

    pg.show(poly, ax=axs[0, 0])

    pg.show(mesh, ax=axs[1, 0], markers=True)

    pg.show(mesh, cell_data, ax=axs[0, 1], colorBar=True, nLevs=7)

    pg.show(mesh, node_data, ax=axs[1, 1], colorBar=True, nLevs=7)
Exemple #16
0
def testShowVariants():
    # Create geometry definition for the modelling domain
    world = mt.createWorld(start=[-10, 0], end=[10, -16],
                        layers=[-8], worldMarker=False)

    # Create a heterogeneous block
    block = mt.createRectangle(start=[-6, -3.5], end=[6, -6.0],
                            marker=4,  boundaryMarker=10, area=0.1)

    circ = mt.createCircle(pos=[0, -11], radius=2, boundaryMarker=11, isHole=True)

    # Merge geometrical entities
    geom = world + block + circ
    mesh = mt.createMesh(geom)

    fig, axs = plt.subplots(3,5)

    pg.show(geom, ax=axs[0][0])
    axs[0][0].set_title('plc, (default)')
    pg.show(geom, fillRegion=False, ax=axs[0][1])
    axs[0][1].set_title('plc, fillRegion=False')
    pg.show(geom, showBoundary=False, ax=axs[0][2])
    axs[0][2].set_title('plc, showBoundary=False')
    pg.show(geom, markers=True, ax=axs[0][3])
    axs[0][3].set_title('plc, markers=True')
    pg.show(mesh, ax=axs[0][4], showBoundary=False)
    axs[0][4].set_title('mesh, showBoundary=False')

    pg.show(mesh, ax=axs[1][0])
    axs[1][0].set_title('mesh, (default)')
    pg.show(mesh, mesh.cellMarkers(), label='Cell markers', ax=axs[1][1])
    axs[1][1].set_title('mesh, cells, (default)')
    pg.show(mesh, markers=True, ax=axs[1][2])
    axs[1][2].set_title('mesh, cells, markers=True')
    pg.show(mesh, mesh.cellMarkers(), label='Cell markers', showMesh=True, ax=axs[1][3])
    axs[1][3].set_title('mesh, cells, showMesh=True')
    pg.show(mesh, mesh.cellMarkers(), label='Cell markers', showBoundary=False, ax=axs[1][4])
    axs[1][4].set_title('mesh, cells, showBoundary=False')

    pg.show(mesh, pg.x(mesh), label='Nodes (x)', ax=axs[2][0])
    axs[2][0].set_title('mesh, nodes, (default)')
    pg.show(mesh, pg.x(mesh), label='Nodes (x)', showMesh=True, ax=axs[2][1])
    axs[2][1].set_title('mesh, nodes, showMesh=True')
    pg.show(mesh, pg.x(mesh), label='Nodes (x)', showBoundary=True, ax=axs[2][2])
    axs[2][2].set_title('mesh, nodes, showBoundary=True')
    pg.show(mesh, pg.y(mesh.cellCenters()), label='Cell center (y)',
            tri=True, shading='flat', ax=axs[2][3])
    axs[2][3].set_title('mesh, cells, tri=True, shading=flat')
    pg.show(mesh, pg.y(mesh.cellCenters()), label='Cell center (y)',
            tri=True, shading='gouraud', ax=axs[2][4])
    axs[2][4].set_title('mesh, cells, tri=True, shading=gouraud')
    ##pg.show(mesh, mesh.cellMarker(), label(markers), axs[1][1])
    axs[2][4].figure.tight_layout()
Exemple #17
0
    def test_region_marker_position_two_ways_v1(self):
        rect1 = mt.createRectangle(
            start=[-2.0, -1.0],
            end=[2.0, 1.0],
            isClosed=True,
            marker=1,
        )

        # scaled version
        rect2 = mt.createRectangle(
            pos=[0.0, 0.0],
            size=[4.0, 2],
            isClosed=True,
            marker=2,
        )
        assert rect1.regionMarkers()[0].x() == -2 + 0.2 * 4
        assert rect1.regionMarkers()[0].y() == -1 + 0.2 * 2

        assert rect1.regionMarkers()[0].marker() == 1
        assert rect2.regionMarkers()[0].marker() == 2

        assert rect1.regionMarkers()[0] == rect2.regionMarkers()[0]
def generate_layered_world(world_dim: list, layer_heights: list):
    """ Creates a layered world.

    Utility function to create a layered world. Region markers are starting at 1 and increasing with depth.

    Parameter:
        world_dim: World dimensions as [x,z].
        layer_heights: Heights of the single layers.

    Returns:
        The created world.
    """
    # Check parameter integrity
    if sum(layer_heights) > world_dim[1]:
        return None
    # Create geometric objects
    world = mt.createWorld(start=[0, 0], end=[world_dim[0], -world_dim[1]])
    current_depth = 0
    layers = []
    for i in range(len(layer_heights)):
        layer = mt.createRectangle(
            start=[0, -current_depth],
            end=[world_dim[0], -(current_depth + layer_heights[i])],
            marker=i + 1,
            boundaryMarker=10)
        current_depth += layer_heights[i]
        layers.append(layer)
    if current_depth != world_dim[1]:
        layer = mt.createRectangle(start=[0, -current_depth],
                                   end=[world_dim[0], -world_dim[1]],
                                   marker=i + 2,
                                   boundaryMarker=10)
        layers.append(layer)
    # Merge geometries
    geom = mt.mergePLC([world] + layers)
    return geom
def generate_tiled_world(world_dim: list, tile_size: list):
    """ Creates a tiled layered world.

    Utility function to create a tiled layered world. Region marker 1 is upper left corner.

    Parameter:
        world_dim: World dimensions as [x,z].
        tile_size: Tile dimensions as [x,z].

    Returns:
        The created world.
    """
    # Create world
    world = mt.createWorld(start=[0, 0], end=[world_dim[0], -world_dim[1]])
    # Create tile counts
    n_tiles_x = int(np.ceil(world_dim[0] / tile_size[0]))
    n_tiles_y = int(np.ceil(world_dim[1] / tile_size[1]))
    # Create and merge tiles
    for j in range(n_tiles_y):
        for i in range(n_tiles_x):
            x_start = int(i * tile_size[0])
            x_end = int((i + 1) * tile_size[0])
            y_start = int(-j * tile_size[1])
            y_end = int(-(j + 1) * tile_size[1])
            if x_end > world_dim[0]:
                x_end = world_dim[0]
            if y_end < -world_dim[1]:
                y_end = -world_dim[1]
            marker = 1
            if ((-1)**i) * ((-1)**j) < 0:
                marker = 2
            tile = mt.createRectangle(start=[x_start, y_start],
                                      end=[x_end, y_end],
                                      marker=marker,
                                      boundaryMarker=10)
            world = mt.mergePLC([world, tile])
    return world
Exemple #20
0
import pygimli as pg
# pg.setTestingMode(True)
import pygimli.meshtools as mt
from pygimli.physics.traveltime import TravelTimeManager

pg.utils.units.quants['vel']['cMap'] = 'inferno_r'
################################################################################
# Next, we build the crosshole acquisition geometry with two shallow boreholes.

# Acquisition parameters
bh_spacing = 20.0
bh_length = 25.0
sensor_spacing = 2.5

world = mt.createRectangle(start=[0, -(bh_length + 3)],
                           end=[bh_spacing, 0.0],
                           marker=0)

depth = -np.arange(sensor_spacing, bh_length + sensor_spacing, sensor_spacing)

sensors = np.zeros((len(depth) * 2, 2))  # two boreholes
sensors[len(depth):, 0] = bh_spacing  # x
sensors[:, 1] = np.hstack([depth] * 2)  # y

###############################################################################
# Traveltime calculations work on unstructured meshes and structured grids. We
# demonstrate this here by simulating the synthetic data on an unstructured
# mesh and inverting it on a simple structured grid.

# Create forward model and mesh
c0 = mt.createCircle(pos=(7.0, -10.0), radius=3, segments=25, marker=1)
                       isClosed=True,
                       area=1,
                       marker=2)
sup2 = mt.createPolygon([[40, 0], [81, 0], [81, -1.5], [38.8, -1.5]],
                        isClosed=True,
                        area=1,
                        marker=4)
sup3 = mt.createPolygon([[30, 0], [40, 0], [39.6, -0.5], [30.4, -0.5]],
                        isClosed=True,
                        area=1,
                        marker=4)
pol = mt.createPolygon([[30, 0], [40, 0], [38, -2.5], [32, -2.5]],
                       isClosed=True,
                       area=1,
                       marker=0)
square = mt.createRectangle(start=[34, -0.5], end=[36, -2.5], area=1, marker=3)
world = mt.mergePLC([background, pol, square, sup, sup2, sup3])
mesh = mt.createMesh(world, quality=33, area=0.1, smooth=[1, 2])

res_model = pg.solver.parseArgToArray(rhomap, mesh.cellCount(), mesh)

#INTERPOLACIÓN MODELO A GRID

nan = 99.9
model_vector_nn = []
for pos in grid.cellCenters():
    cell = mesh.findCell(pos)
    if cell:
        model_vector_nn.append(res_model[cell.id()])
    else:
        model_vector_nn.append(nan)
Exemple #22
0
plc = mt.mergePLC([polygon1, polygon2])

ax, cb = pg.show(plc, markers=True)

fig = ax.get_figure()
for nr, marker in enumerate(plc.regionMarker()):
    print('Position marker number {}:'.format(nr + 1), marker.x(), marker.y(),
          marker.z())
    ax.scatter(marker.x(), marker.y(), s=(4 - nr) * 20, color='k')
ax.set_title('marker positions - working example')
fig.show()
###############################################################################
# And finally, a similar example for rectangles...
rect1 = mt.createRectangle(
    start=[0.0, 0.0],
    end=[2.0, -1.0],
    isClosed=True,
    marker=1,
)

# move the rectangle by changing the center position
rect2 = mt.createRectangle(
    start=[0.0, 0.0],
    end=[1.0, -0.5],
    isClosed=True,
    marker=2,
)

plc = mt.mergePLC([rect1, rect2])

ax, cb = pg.show(plc, markers=True)
    \textbf{C}_{\text{M},ij}=\sigma^{2}\exp{\left(
        -3\sqrt{\left(\frac{\textbf{H}_{x,ij}}{I_{x}}\right)^{2}+
                \left(\frac{\textbf{H}_{y,ij}}{I_{y}}\right)^{2}+
                \left(\frac{\textbf{H}_{z,ij}}{I_{z}}\right)^{2}}\right)}.

It defines the correlation between model cells as a function of correlation
lenghts (ranges) :math:`I_x`, :math:`I_y`, and :math:`I_z`. Of course, the
orientation of the coordinate axes is arbitrary and can be chosen by rotation.
Let us illustrate this by a simple mesh:
"""

# %% create a simple mesh (e.g. a crosshole box geometry)
import pygimli as pg
import pygimli.meshtools as mt
# We create a rectangular domain and mesh it with small triangles
rect = mt.createRectangle(start=[0, -10], end=[10, 0])
mesh = mt.createMesh(rect, quality=34.5, area=0.1)

# %%
# We can compute this covariance matrix by calling
CM = pg.matrix.covarianceMatrix(mesh, I=5)
# We search for the cell where the midpoint (5, -5) is located in
ind = mesh.findCell([5, -5]).id()
# and plot the according column
# col = pg.log10(CM.dot(vec))
pg.show(mesh, CM[:, ind], cMap="magma_r")

# %%
# According to inverse theory, we use the square root of the covariance matrix
# as single-side regularization matrix C. It is computed by using an eigenvalue
# decomposition based on the numpy linalg procedure
@author: Aritz
"""
import numpy as np
import pygimli as pg
import pygimli.meshtools as mt
import matplotlib.pyplot as plt
import pybert as pb

#creación grid para comparación

grid = pg.createGrid(x=pg.utils.grange(start=0, end=71, n=500),
                     y=-pg.utils.grange(0, 15, n=250, log=False))

grid2 = pg.createGrid(x=pg.utils.grange(start=50, end=60, n=500),
                      y=-pg.utils.grange(5.5, 9.5, n=250, log=False))
square = mt.createRectangle(start=[50, -5.5], end=[60, -9.5])

#parametros inversion

quality = 34.5
maxCellArea = 1
robustData = True
paraDX = 0.25
lam = 20

#PARAMETROS MODELADO

noise = 0
rhomap = [[0, 500], [1, 50], [2, 100], [3, 2000]]
#CREACION MODELO GENERAL
Exemple #25
0
def simulateSynth(model,
                  tMax=5000,
                  satSteps=150,
                  ertSteps=10,
                  area=0.1,
                  synthPath='synth/'):
    """Create synthetic example."""

    if not os.path.exists('synth/'):
        os.mkdir(synthPath)

    world = mt.createWorld(start=[-20, 0],
                           end=[20, -16],
                           layers=[-2, -8],
                           worldMarker=False)
    for i, b in enumerate(world.boundaries()):
        b.setMarker(i + 1)

    block = mt.createRectangle(start=[-6, -3.5],
                               end=[6, -6.0],
                               marker=4,
                               boundaryMarker=11,
                               area=area)
    geom = mt.mergePLC([world, block])
    geom.save(synthPath + 'synthGeom')
    # pg.show(geom, boundaryMarker=1)

    paraMesh = pg.meshtools.createMesh(geom,
                                       quality=32,
                                       area=area,
                                       smooth=[1, 10])

    # translate 1 2 3 4 - > 0 1 2 3
    mapMarker = np.array([0, 0, 1, 2, 3], 'float')
    paraMesh.setCellMarkers(mapMarker[np.array(paraMesh.cellMarkers())])
    paraMesh.save(synthPath + 'synth.bms')

    fop = HydroGeophysicalModelling(mesh=paraMesh,
                                    tMax=tMax,
                                    satSteps=satSteps,
                                    ertSteps=ertSteps,
                                    verbose=1)

    # openblas have some problems with to high thread count ..
    # we need to dig into
    print("TC", pg.threadCount())
    pg.setThreadCount(4)

    print('##### Simulate synthetic data ' + '#' * 50)
    pg.tic()
    rhoaR = fop.response(pg.RVector(model)[paraMesh.cellMarkers()])
    pg.toc()
    print('#' * 100)

    # add some noise here
    rand = pg.RVector(len(rhoaR))
    pg.randn(rand)

    rhoaR *= (1.0 + rand * fop.ws.derr.flatten())
    fop.ws.rhoaR = rhoaR.reshape(fop.ws.derr.shape)

    # fop.ws.mesh.save(synthPath + 'synth.bms')
    np.save(synthPath + 'synthK', fop.ws.k)
    np.save(synthPath + 'synthVel', fop.ws.vel)
    np.save(synthPath + 'synthSat', fop.ws.sat)

    fop.ws.scheme.save(synthPath + 'synth.shm', 'a b m n')
    np.save(synthPath + 'synthRhoaRatio', fop.ws.rhoaR)
    np.save(synthPath + 'synthRhoa', fop.ws.rhoa)
    np.save(synthPath + 'synthErr', fop.ws.derr)
Exemple #26
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Minimal example of using pygimli to simulate the steady heat equation.
"""

import pygimli as pg
import pygimli.meshtools as mt

# Create geometry definition for the modelling domain
world = mt.createWorld(start=[-20, 0], end=[20, -16], layers=[-2, -8],
                       worldMarker=False)
# Create a heterogeneous block
block = mt.createRectangle(start=[-6, -3.5], end=[6, -6.0],
                           marker=4,  boundaryMarker=10, area=0.1)
# Merge geometrical entities
geom = mt.mergePLC([world, block])
pg.show(geom, boundaryMarker=True, savefig='geometry.pdf')

# Create a mesh from the geometry definition
mesh = mt.createMesh(geom, quality=33, area=0.2, smooth=[1, 10])
pg.show(mesh, savefig='mesh.pdf')

# $\diverg(a\grad T)=0$ with $T(bottom)=1$, $T(top)=0$
T = pg.solver.solveFiniteElements(mesh,
                                  a=[[1, 1.0], [2, 2.0], [3, 3.0], [4, 0.1]],
                                  uB=[[8, 1.0], [4, 0.0]], verbose=True)

ax, _ = pg.show(mesh, data=T, label='Temperature $T$', cmap="hot_r",
                showBoundary=True, savefig='T_field.pdf')
import pygimli as pg
import pygimli.meshtools as mt
from pygimli.physics.traveltime import Refraction

mpl.rcParams['image.cmap'] = 'inferno_r'

################################################################################
# Next, we build the crosshole acquisition geometry with two shallow boreholes.

# Acquisition parameters
bh_spacing = 20.0
bh_length = 25.0
sensor_spacing = 2.5

world = mt.createRectangle(start=[0, -(bh_length + 3)], end=[bh_spacing, 0.0],
                           marker=0)

depth = -np.arange(sensor_spacing, bh_length + sensor_spacing, sensor_spacing)

sensors = np.zeros((len(depth) * 2, 2))  # two boreholes
sensors[len(depth):, 0] = bh_spacing  # x
sensors[:, 1] = np.hstack([depth] * 2)  # y

################################################################################
# Traveltime calculations work on unstructured meshes and structured grids. We
# demonstrate this here by simulating the synthetic data on an unstructured mesh
# and inverting it on a simple structured grid.

# Create forward model and mesh
c0 = mt.createCircle(pos=(7.0, -10.0), radius=3, segments=25, marker=1)
c1 = mt.createCircle(pos=(12.0, -18.0), radius=4, segments=25, marker=2)
Exemple #28
0
"""
import numpy as np
import pygimli as pg
import pygimli.meshtools as mt
import matplotlib.pyplot as plt
import pybert as pb

#creación grid para comparación

grid = pg.createGrid(x=pg.utils.grange(start=0, end=71, n=500),
                           y=-pg.utils.grange(0, 15, n=250, log=False))

grid2= pg.createGrid(x=pg.utils.grange(start=23.5, end=27.5, n=500),
                           y=-pg.utils.grange(5.5, 9.5
                                              , n=250, log=False))
square=mt.createRectangle(start=[23.5,-5.5],end=[27.5,-9.5])

#parametros inversion

quality=34.5
maxCellArea=1
robustData=True
paraDX=0.25
lam=20

#PARAMETROS MODELADO

noise=0
rhomap= [[0,100],[1,100],[2,200],[3,1000]]

#CREACION MODELO GENERAL
Exemple #29
0
    CorERTBack == 1) + 'ERTscheme' + str(ertSchemeFull == 1)

path_Figures = PathSimu_salt + '/Sens/' + SimName + '/Figures/'
if not os.path.exists(path_Figures):
    os.makedirs(path_Figures)

path_Data = PathSimu_salt + '/Sens/' + SimName + '/Data/'
if not os.path.exists(path_Data):
    os.makedirs(path_Data)

# Create geometry definition for the modelling domain
world = mt.createWorld(start=[-20, 0], end=[20, -16], worldMarker=False)
# Create a heterogeneous block
block = mt.createRectangle(start=[-5, -2.5],
                           end=[5, -5.0],
                           marker=4,
                           boundaryMarker=10,
                           area=0.1)
# block = mt.createRectangle(start=[-5, -5], end=[5, -7.5],
#                             marker=4,  boundaryMarker=10, area=0.1)
# Merge geometrical entities
# geom = mt.mergePLC([world, block])
geom = mt.mergePLC([world, block])

pg.show(geom, boundaryMarker=True, savefig='geometry.pdf')

# Create a mesh from the geometry definition
mesh = mt.createMesh(geom, quality=32, area=0.2, smooth=[1, 10])
# pg.show(mesh, savefig='mesh.pdf')

rMap = [[1, SoilR], [4, AnoR]]
                           paraDepth=depth,
                           paraDX=0.3,
                           boundary=0,
                           paraBoundary=2)

if case == 1:
    for depth in (5, 15):
        start = plc.createNode(mesh.xmin(), -depth, 0.0)
        end = plc.createNode(mesh.xmax(), -depth, 0.0)
        plc.createEdge(start, end, marker=1)

for sensor in ertData.sensorPositions():
    plc.createNode([sensor.x(), sensor.y() - 0.1])

rect = mt.createRectangle([mesh.xmin(), mesh.ymin()],
                          [mesh.xmax(), mesh.ymax()],
                          boundaryMarker=0)
geom = mt.mergePLC([plc, rect])

meshRST = mt.createMesh(geom, quality=34, area=1, smooth=[1, 2])

for cell in meshRST.cells():
    cell.setMarker(2)
for boundary in meshRST.boundaries():
    boundary.setMarker(0)

pg.show(meshRST)
print(meshRST)
# %%
meshRST.save("paraDomain_%d.bms" % case)
Exemple #31
0
#plt.xkcd()

import pygimli as pg
import pygimli.meshtools as mt

# Create geometry definition for the modeling domain
world = mt.createWorld(start=[-10, 0],
                       end=[10, -16],
                       layers=[-8],
                       worldMarker=False)

# Create a heterogeneous block
block = mt.createRectangle(start=[-6, -3.5],
                           end=[6, -6.0],
                           marker=4,
                           boundaryMarker=10,
                           area=0.1)

circ = mt.createCircle(pos=[0, -11], radius=2, boundaryMarker=11, isHole=True)

# Merge geometrical entities
geom = mt.mergePLC([world, block, circ])
mesh = mt.createMesh(geom)

fig, axs = plt.subplots(3, 5)

pg.show(geom, ax=axs[0][0])
axs[0][0].set_title('plc, (default)')
pg.show(geom, fillRegion=False, ax=axs[0][1])
axs[0][1].set_title('plc, fillRegion=False')
Exemple #32
0
shots_id.append(len(sensors_all_xpos) - 1)
print(sens_id)
print(shots_id)

sensors = np.zeros((len(sensors_all_xpos), 2))  # two boreholes
sensors[:, 0] = np.hstack([sensors_all_xpos])  # x
sensors[:, 1] = 0  # y
print()
print("sensors")
print(sensors)

########

# Create forward model and mesh
world = mt.createRectangle(start=[0, 0],
                           end=[ttm_length, -world_width],
                           marker=0)
# c0 = mt.createCircle(pos=(ttm_start + 60.0, -7), radius=7, segments=25, marker=1)
c0 = mt.createRectangle(start=[0, -2], end=[ttm_length, -4], marker=1)
# c1 = mt.createCircle(pos=(ttm_start + 120.0, -10.0), radius=10, segments=25, marker=2)
c1 = mt.createRectangle(start=[0, -4],
                        end=[ttm_length, -world_width],
                        marker=2)
geom = mt.mergePLC([world, c0, c1])

for sen in sensors:
    geom.createNode(sen)

mesh_fwd = mt.createMesh(geom, quality=34, area=1.0)
model = np.array([1000., 2000., 5000.])[mesh_fwd.cellMarkers()]
print("model")
#inversion parameters

quality = 34.5
maxCellArea = 1
robustData = True
lam = 20
paraDX = 0.25
#creación grid para comparación

grid = pg.createGrid(x=pg.utils.grange(start=0.20, end=0.5, n=500),
                     y=-pg.utils.grange(0, 0.12, n=250, log=False))

grid2 = pg.createGrid(x=pg.utils.grange(start=0.33, end=0.35, n=500),
                      y=-pg.utils.grange(0.04, 0.06, n=250, log=False))

square = mt.createRectangle(start=[0.33, -0.04], end=[0.35, -0.06])

#MODELO

rhomap = [[1, 150], [0, 3000]]
background = mt.createWorld(start=[-1, 0], end=[1, -1], area=1, marker=1)
circle = mt.createCircle(pos=[0.34, -0.05], radius=0.01, marker=0)
world = mt.mergePLC([background, circle])
mesh = mt.createMesh(world, quality=33, area=0.1, smooth=[1, 2])

res_model = pg.solver.parseArgToArray(rhomap, mesh.cellCount(), mesh)

#INTERPOLACIÓN MODELO A GRID

nan = 99.9
model_vector_nn = []
Exemple #34
0
plc = mt.mergePLC([polygon1, polygon2])

ax, cb = pg.show(plc, markers=True)

fig = ax.get_figure()
for nr, marker in enumerate(plc.regionMarker()):
    print('Position marker number {}:'.format(nr + 1), marker.x(), marker.y(),
          marker.z())
    ax.scatter(marker.x(), marker.y(), s=(4 - nr) * 20, color='k')
ax.set_title('marker positions - working example')
fig.show()
###############################################################################
# And finally, a similar example for rectangles...
rect1 = mt.createRectangle(
    start=[0.0, 0.0],
    end=[2.0, -1.0],
    isClosed=True,
    marker=1,
)

# move the rectangle by changing the center position
rect2 = mt.createRectangle(
    start=[0.0, 0.0],
    end=[1.0, -0.5],
    isClosed=True,
    marker=2,
)

plc = mt.mergePLC([rect1, rect2])

ax, cb = pg.show(plc, markers=True)