Note
Click here to download the full example code
Incorporating prior data into ERT inversion#
Prior data can often help to overcome ambiguity in the inversion process. Here we demonstrate the use of direct push (DP) data in an ERT inversion of data collected at the surface.
import matplotlib.pyplot as plt
import numpy as np
import pygimli as pg
from pygimli.physics import ert
from pygimli.frameworks import PriorModelling, JointModelling
The prior data#
This field data is from a site with layered sands and clays over a resistive bedrock. We load it from the example repository.
As a position of x=155m (center of the profile) we have a borehole/direct push with known in-situ-data. We load the three-column file using numpy.
x, z, r = pg.getExampleData("ert/bedrock.txt").T
fig, ax = plt.subplots()
ax.semilogx(r, z, "*-")
ax.set_xlabel(r"$\rho$ ($\Omega$m)")
ax.set_ylabel("depth (m)")
ax.grid(True)

We mainly see four layers: 1. a conductive (clayey) overburden of about 17m thickness, 2. a medium resistivity interbedding of silt and sand, about 7m thick 3. again clay with 8m thickness 4. the resistive bedrock with a few hundred :math:`Omega`m
The ERT data#
We load the ERT data from the example repository and plot the pseudosection.
data = pg.getExampleData("ert/bedrock.dat")
print(data)
ax, cb = ert.show(data)

Data: Sensors: 64 data: 1223, nonzero entries: ['a', 'b', 'err', 'm', 'n', 'rhoa', 'valid']
The apparent resistivities show increasing values with larger spacings with no observable noise. We first compute geometric factors and estimate an error model using rather low values for both error parts.
data["k"] = ert.geometricFactors(data)
data["err"] = ert.estimateError(data, relativeError=0.02, absoluteUError=50e-6)
# ax, cb = ert.show(data, data["err"]*100, label="error (%)")
mgr = ert.ERTManager(data, verbose=True)
mgr.invert(paraDepth=80, quality=34.6, paraMaxCellSize=100)
# mgr.showFit()
fop: <pygimli.physics.ert.ertModelling.ERTModelling object at 0x7fa029d1fa40>
Data transformation: <pygimli.core._pygimli_.RTransLogLU object at 0x7fa0145fd130>
Model transformation: <pygimli.core._pygimli_.RTransLog object at 0x7fa004477ef0>
min/max (data): 17.73/154
min/max (error): 2.02%/2.94%
min/max (start model): 48.34/48.34
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
inv.iter 1 ... chi² = 5.12 (dPhi = 98.5%) lam: 20
--------------------------------------------------------------------------------
inv.iter 2 ... chi² = 4.12 (dPhi = 17.77%) lam: 20.0
--------------------------------------------------------------------------------
inv.iter 3 ... chi² = 3.33 (dPhi = 17.18%) lam: 20.0
--------------------------------------------------------------------------------
inv.iter 4 ... chi² = 2.39 (dPhi = 23.21%) lam: 20.0
--------------------------------------------------------------------------------
inv.iter 5 ... chi² = 0.52 (dPhi = 54.26%) lam: 20.0
################################################################################
# Abort criterion reached: chi² <= 1 (0.52) #
################################################################################
1674 [17.343970581365276,...,173.2622780777743]
For reasons of comparability, we define a unique colormap and store all options in a dictionary to be used in subsequent show commands.
We plot the result with these and plot the DP points onto the mesh.

We want to extract the resistivity from the mesh at the positions where
the prior data are available. To this end, we create a list of positions
(pg.Pos
class) and use a forward operator that picks the values from a
model vector according to the cell where the position is in. See the
regularization tutorial for details about that.
We can now use it to retrieve the model values, store it and plot it along with the measured values.
fig, ax = plt.subplots()
ax.semilogx(r, z, label="borehole")
res1 = fopDP(mgr.model)
ax.semilogx(res1, z, label="ERT")
ax.set_xlabel(r"$\rho$ ($\Omega$m)")
ax.set_ylabel("depth (m)")
ax.grid(True)
ax.legend()

<matplotlib.legend.Legend object at 0x7fa074ee8880>
Even though the tomogram looks interesting, the resistivity seems to
follow a simple gradient. This is apparently a lack of resolution. Our
assumption of an overall smooth image is wrong. Therefore we use an
anisotropic smoothness using the vertical weighting factor zWeight
.

fop: <pygimli.physics.ert.ertModelling.ERTModelling object at 0x7fa029d1fa40>
Data transformation: <pygimli.core._pygimli_.RTransLogLU object at 0x7fa0145fd130>
Model transformation (cumulative):
0 <pygimli.core._pygimli_.RTransLogLU object at 0x7fa004423a00>
min/max (data): 17.73/154
min/max (error): 2.02%/2.94%
min/max (start model): 48.34/48.34
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
inv.iter 1 ... chi² = 13.08 (dPhi = 96.82%) lam: 20
--------------------------------------------------------------------------------
inv.iter 2 ... chi² = 12.26 (dPhi = 6.22%) lam: 20.0
--------------------------------------------------------------------------------
inv.iter 3 ... chi² = 11.52 (dPhi = 6.02%) lam: 20.0
--------------------------------------------------------------------------------
inv.iter 4 ... chi² = 10.84 (dPhi = 5.81%) lam: 20.0
--------------------------------------------------------------------------------
inv.iter 5 ... chi² = 10.09 (dPhi = 6.94%) lam: 20.0
--------------------------------------------------------------------------------
inv.iter 6 ... chi² = 9.16 (dPhi = 9.05%) lam: 20.0
--------------------------------------------------------------------------------
inv.iter 7 ... chi² = 7.9 (dPhi = 13.64%) lam: 20.0
--------------------------------------------------------------------------------
inv.iter 8 ... chi² = 5.9 (dPhi = 25.09%) lam: 20.0
--------------------------------------------------------------------------------
inv.iter 9 ... chi² = 0.75 (dPhi = 84.3%) lam: 20.0
################################################################################
# Abort criterion reached: chi² <= 1 (0.75) #
################################################################################
We observe a much more structured result with stronger vertical gradients that are, however, not continuous. In the middle of the profile we can see a short layer of increased resistivity.
As alternative, we can use a geostatistic model. The vertical range can be well estimated from the DP data using a variogram analysis, we guess 5m. For the horizontal one, we can only guess a 10m higher value.

fop: <pygimli.physics.ert.ertModelling.ERTModelling object at 0x7fa029d1fa40>
Data transformation: <pygimli.core._pygimli_.RTransLogLU object at 0x7fa0145fd130>
Model transformation (cumulative):
0 <pygimli.core._pygimli_.RTransLogLU object at 0x7fa0148409a0>
min/max (data): 17.73/154
min/max (error): 2.02%/2.94%
min/max (start model): 48.34/48.34
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
inv.iter 1 ... chi² = 79.28 (dPhi = 81.14%) lam: 20
--------------------------------------------------------------------------------
inv.iter 2 ... chi² = 12.97 (dPhi = 83.46%) lam: 20.0
--------------------------------------------------------------------------------
inv.iter 3 ... chi² = 1.64 (dPhi = 85.6%) lam: 20.0
--------------------------------------------------------------------------------
inv.iter 4 ... chi² = 1.09 (dPhi = 30.12%) lam: 20.0
--------------------------------------------------------------------------------
inv.iter 5 ... chi² = 0.3 (dPhi = 59.83%) lam: 20.0
################################################################################
# Abort criterion reached: chi² <= 1 (0.30) #
################################################################################
Let’s compare the three resistivity soundings with the ground truth.
fig, ax = plt.subplots()
ax.semilogx(r, z, label="borehole")
ax.semilogx(res1, z, label="ERT smooth")
ax.semilogx(res2, z, label="ERT aniso")
ax.semilogx(res3, z, label="ERT geostat")
ax.set_xlabel(r"$\rho$ ($\Omega$m)")
ax.set_ylabel("depth (m)")
ax.grid()
ax.legend()

<matplotlib.legend.Legend object at 0x7fa074ddd0a0>
The anisotropic regularization starts to see the good conductor, but only the geostatistical regularization operator is able to retrieve values that are close to the direct push. Both show the conductor too deep.
One alternative could be to use the interfaces as structural constraints in the neighborhood of the borehole. See ERT with structural constraints example
As the DP data is not only good for comparison, we want to use its values as data in inversion. This is easily accomplished by taking the mapping operator that we already use for interpolation as a forward operator.
We set up an inversion with this mesh, logarithmic transformations and invert the model.
inv = pg.Inversion(fop=fopDP, verbose=True)
inv.mesh = para
tLog = pg.trans.TransLog()
inv.modelTrans = tLog
inv.dataTrans = tLog
# inv.setRegularization(zWeight=0.2)
inv.setRegularization(correlationLengths=[50, 5])
rError = np.ones_like(r)*0.1
model = inv.run(r, rError)
ax, cb = pg.show(para, model, **kw)

fop: <pygimli.frameworks.modelling.PriorModelling object at 0x7fa014b7d450>
Data transformation: <pygimli.core._pygimli_.RTransLog object at 0x7fa074a98e50>
Model transformation (cumulative):
0 <pygimli.core._pygimli_.RTransLogLU object at 0x7fa0044232e0>
min/max (data): 7.52/469
min/max (error): 10%/10%
min/max (start model): 17.84/17.84
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
inv.iter 1 ... chi² = 73.71 (dPhi = 66.17%) lam: 20
--------------------------------------------------------------------------------
inv.iter 2 ... chi² = 73.71 (dPhi = 0.19%) lam: 20.0
--------------------------------------------------------------------------------
inv.iter 3 ... chi² = 73.71 (dPhi = 0.05%) lam: 20.0
--------------------------------------------------------------------------------
inv.iter 4 ... chi² = 73.71 (dPhi = 0.04%) lam: 20.0
################################################################################
# Abort criteria reached: dPhi = 0.04 (< 2.0%) #
################################################################################
Apparently, the geostatistical operator can be used to extrapolate values with given assumptions.
Joint inversion of ERT and DP data#
We now use the framework JointModelling
to combine the ERT and the
DP forward operators. So we set up a new ERT modelling operator and join
it with fopDP
.
# fopERT = ert.ERTModelling()
# fopERT.setMesh(mesh)
# fopERT.setData(data) # not necessary as done by JointModelling
# fopJoint = JointModelling([fopERT, fopDP])
fopJoint = JointModelling([mgr.fop, fopDP])
# fopJoint.setMesh(para)
fopJoint.setData([data, pg.Vector(r)]) # needs to have .size() attribute!
We first test the joint forward operator. We create a modelling vector of constant resistivity and distribute the model response into the two parts that can be looked at individually.
[100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0, 100.0]
The jacobian can be looked up
<class 'pygimli.core._pygimli_.RBlockMatrix'>
RMatrix: 1223 x 1674
For the joint inversion, concatenate the data and error vectors, create a new inversion instance, set logarithmic transformations and run the inversion.
dataVec = np.concatenate((data["rhoa"], r))
errorVec = np.concatenate((data["err"], rError))
inv = pg.Inversion(fop=fopJoint, verbose=True)
transLog = pg.trans.TransLog()
inv.modelTrans = transLog
inv.dataTrans = transLog
inv.run(dataVec, errorVec, startModel=model)
ax, cb = pg.show(para, inv.model, **kw)

fop: <pygimli.frameworks.modelling.JointModelling object at 0x7fa029b3a090>
Data transformation: <pygimli.core._pygimli_.RTransLog object at 0x7fa00d7d7f90>
Model transformation (cumulative):
0 <pygimli.core._pygimli_.RTransLogLU object at 0x7fa029f154c0>
min/max (data): 7.52/469
min/max (error): 2.02%/10%
min/max (start model): 100/100
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
inv.iter 1 ... chi² = 14.75 (dPhi = 98.92%) lam: 20
--------------------------------------------------------------------------------
inv.iter 2 ... chi² = 8.56 (dPhi = 41.6%) lam: 20.0
--------------------------------------------------------------------------------
inv.iter 3 ... chi² = 4.38 (dPhi = 47.28%) lam: 20.0
--------------------------------------------------------------------------------
inv.iter 4 ... chi² = 3.87 (dPhi = 11.02%) lam: 20.0
--------------------------------------------------------------------------------
inv.iter 5 ... chi² = 3.85 (dPhi = 0.47%) lam: 20.0
################################################################################
# Abort criteria reached: dPhi = 0.47 (< 2.0%) #
################################################################################
We have a local improvement of the model in the neighborhood of the borehole. Now we want to use geostatistics to get them further into the model.

fop: <pygimli.frameworks.modelling.JointModelling object at 0x7fa029b3a090>
Data transformation: <pygimli.core._pygimli_.RTransLog object at 0x7fa00d7d7f90>
Model transformation (cumulative):
0 <pygimli.core._pygimli_.RTransLogLU object at 0x7fa074f20c40>
min/max (data): 7.52/469
min/max (error): 2.02%/10%
min/max (start model): 100/100
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
inv.iter 1 ... chi² = 34.07 (dPhi = 97.53%) lam: 20
--------------------------------------------------------------------------------
inv.iter 2 ... chi² = 13.93 (dPhi = 58.69%) lam: 20.0
--------------------------------------------------------------------------------
inv.iter 3 ... chi² = 7.31 (dPhi = 46.34%) lam: 20.0
--------------------------------------------------------------------------------
inv.iter 4 ... chi² = 5.59 (dPhi = 22.63%) lam: 20.0
--------------------------------------------------------------------------------
inv.iter 5 ... chi² = 3.91 (dPhi = 28.18%) lam: 20.0
--------------------------------------------------------------------------------
inv.iter 6 ... chi² = 3.9 (dPhi = 0.27%) lam: 20.0
################################################################################
# Abort criteria reached: dPhi = 0.27 (< 2.0%) #
################################################################################
This model much better resembles the subsurface from all data and our expectations to it.
We split the model response in the ERT part and the DP part. The first is shown as misfit.
respERT = inv.response[:data.size()]
misfit = - respERT / data["rhoa"] * 100 + 100
# ax, cb = ert.show(data, misfit, cMap="bwr", cMin=-5, cMax=5)
The second is shown as depth profile.
respDP = inv.response[data.size():]
fig, ax = plt.subplots()
ax.semilogx(r, z, label="borehole")
# resMesh = pg.interpolate(srcMesh=para, inVec=inv.model, destPos=posVec)
# ax.semilogx(resMesh, z, label="ERT+DP")
ax.semilogx(respDP, z, label="response")
ax.grid(True)
ax.legend()

<matplotlib.legend.Legend object at 0x7fa029e8c340>
The model response can much better resemble the given data compared to pure interpolation.
Note
Take-away messages
(ERT) data inversion is highly ambiguous, particularly for hidden layers
prior data can help to improve regularization
structural data can be of great help, but only if extended
point data improve images, but only locally with smoothness constraints
geostatistical regularization can extrapolate point data
incorporation of prior data with geostatistic regularization is best and simple
Total running time of the script: ( 12 minutes 31.414 seconds)