def test_ERT(self, showProgress=False): dat = pg.getExampleFile('ert/gallery.dat', load=True, verbose=True) mesh = pg.meshtools.createParaMesh(dat.sensors(), quality=33.4, paraDX=0.3, paraMaxCellSize=0.5, paraDepth=8) #with SR ert = ERTManager(sr=True, useBert=True, verbose=False, debug=False) mod = ert.invert(dat, mesh=mesh, maxIter=20, lam=10) np.testing.assert_approx_equal(ert.inv.chi2(), 1.003, significant=3) #without SR ert = ERTManager(sr=False, useBert=True, verbose=False, debug=False) mod = ert.invert(dat, mesh=mesh, maxIter=20, lam=10)
def test_VTK_DataRead(self): grid = pg.createGrid(np.arange(4), np.arange(3), np.arange(2)) cM = np.arange(grid.cellCount()) grid.setCellMarkers(cM) import tempfile as tmp _, fn = tmp.mkstemp(suffix='.vtk') grid.exportVTK(fn) mesh = pg.load(fn) np.testing.assert_array_equal(mesh.cellMarkers(), cM) np.testing.assert_array_equal(mesh['Marker'], cM) mesh = pg.meshtools.readMeshIO(fn) np.testing.assert_array_equal(mesh['Marker'], cM) fn = pg.getExampleFile('meshes/test_tetgen_dataCol.vtk') mesh = pg.load(fn) np.testing.assert_array_equal(mesh.cellMarkers(), cM) np.testing.assert_array_equal(mesh['Marker'], cM) mesh = pg.meshtools.readMeshIO(fn) np.testing.assert_array_equal(mesh['Marker'], cM)
# In contrast to field measurements, experimental tanks have well-defined # spatial dimensions and need different boundary conditions (BC). # # As there is no current flow through the tanks boundary at all, homogeneous # (Neumann) BC are defined for the whole boundary. # Neumann BC are natural (intrinsic) for the finite element simulations. # \link{tutorial:fem:bc}, so we just need to define a cube geometry including # region markers. plc = mt.createCube(size=[0.99, 0.5, 1.0], pos=[0.495, 0.25], boundaryMarker=1) ############################################################################### # We first read the measuring scheme file and add the electrodes as nodes with # the marker -99 to the geometry. filename = pg.getExampleFile("ert/modeltank.shm") shm = pg.DataContainerERT(filename) for s in shm.sensors(): plc.createNode(s, marker=-99) ############################################################################### # There are two small problems to overcome for simulating Neumann bodies. # # First, we always need dipole current injection since there can be no current # flow out of the closed boundaries of our experimental tank. # (Note that by default single poles are simulated and superpositioned.) # Therefore we define a reference electrode position inside the PLC, with a # marker -999, somewhere away from the electrodes. plc.createNode([0.5, 0.5, -0.5], marker=-999)
J_re = np.array(J_block.mat(0)) J_im = np.array(J_block.mat(1)) J0 = J_re + 1j * J_im ############################################################################### # Regularization matrix rm = fop.regionManager() rm.setVerbose(True) rm.setConstraintType(2) Wm = pg.matrix.SparseMapMatrix() rm.fillConstraints(Wm) Wm = pg.utils.sparseMatrix2coo(Wm) ############################################################################### # read-in data and determine error parameters filename = pg.getExampleFile( 'CR/synthetic_modeling/data_rre_rim.dat', load=False, verbose=True) data_rre_rim = np.loadtxt(filename) N = int(data_rre_rim.size / 2) d_rcomplex = data_rre_rim[:N] + 1j * data_rre_rim[N:] dmag = np.abs(d_rcomplex) dpha = np.arctan2(d_rcomplex.imag, d_rcomplex.real) * 1000 fig, axes = plt.subplots(1, 2, figsize=(20 / 2.54, 10 / 2.54)) k = np.array(ert.createGeometricFactors(scheme)) ert.showERTData( scheme, vals=dmag * k, ax=axes[0], label=r'$|\rho_a|~[\Omega$m]') ert.showERTData(scheme, vals=dpha, ax=axes[1], label=r'$\phi_a~[mrad]$') # real part: log-magnitude # imaginary part: phase [rad]
Simple example of data measured over a slagdump demonstrating: - 2D inversion with topography - geometric factor generation - topography effect """ # sphinx_gallery_thumbnail_number = 3 import numpy as np import pygimli as pg from pygimli.physics.ert import ERTManager, createGeometricFactors ############################################################################### # Get some example data with topography # data = pg.getExampleFile('ert/slagdump.ohm', load=True, verbose=True) print(data) ############################################################################### # The data file does not contain geometric factors (token field 'k'), # so we create them based on the given topography. data['k'] = createGeometricFactors(data, numerical=True) ############################################################################### # We initialize the ERTManager for further steps and eventually inversion. ert = ERTManager(sr=False, useBert=True, verbose=True, debug=False) ############################################################################### # It might be interesting to see the topography effect, i.e the ratio between # the numerically computed geometry factor and the analytical formula k0 = createGeometricFactors(data)
""" # sphinx_gallery_thumbnail_number = 2 ################################################################################ # 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. 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)
# gmsh -2 -o mesh.msh mesh.geo # # Import to GIMLi # --------------- # # Any Gmsh output (2D and 3D) can be imported using pygimli and subsequently # saved to the binary format. import subprocess import matplotlib.pyplot as plt import pygimli as pg from pygimli.meshtools import readGmsh filename = pg.getExampleFile("gmsh/2d_tutorial.geo") try: subprocess.call( ["gmsh", "-format", "msh2", "-2", "-o", "mesh.msh", filename]) gmsh = True except OSError: print("Gmsh needs to be installed for this example.") gmsh = False fig, ax = plt.subplots() if gmsh: mesh = readGmsh("mesh.msh", verbose=True) pg.show(mesh, ax=ax, markers=True, hold=True) ax.set_xlim(0, 50) ax.set_ylim(-50, 0)
# converted to `Python # scripts <https://gitlab.onelab.info/gmsh/gmsh/-/tree/master/tutorial/python>`_ # and additional # `demos <https://gitlab.onelab.info/gmsh/gmsh/-/tree/master/demos/api>`_ # are also provided. I will mention or provide links to relevant # tutorials and demos, have a look at these for extra context. # # Let's start by importing our geometry into Gmsh: import numpy as np import pygimli as pg gmsh = pg.optImport("gmsh", "do this tutorial. Install by running: pip install gmsh") # Download all nessesary files geom_filename = pg.getExampleFile("cad/dike_mod.brep") elec_pos_filename = pg.getExampleFile("cad/elec_pos.csv") if gmsh: # Starting it up (tutorial t1.py) gmsh.initialize() gmsh.option.setNumber("General.Terminal", 1) gmsh.model.add("dike_mod") # Load a BREP file (t20.py & demo step_assembly.py) # .brep files don't contain info about units, so scaling has to be applied gmsh.option.setNumber("Geometry.OCCScaling", 0.001) volumes = gmsh.model.occ.importShapes(geom_filename) ############################################################################### # Before diving into local mesh refinement, putting the electrodes in # the mesh and assigning region, boundary and electrode markers, the
and some high-velocity bedrock. The data file can be found in the `pyGIMLi example data repository <https://github.com/gimli-org/example-data/blob/master/traveltime/koenigsee.sgt>`_. """ ################################################################################ # 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 ################################################################################