2.5D DC inversion of with Iterative Reweighted Least SquaresΒΆ

This is an example for 2.5D DC Inversion with Iterative Reweighted Least Squares (IRLS). Earth includes a topography, and below the topography conductive and resistive cylinders are embedded. User is promoted to try different p, qx, qz. For instance a set of paraemters (default):

  • p=0 (sparse model, m)
  • qx=2 (smooth model, m in x-direction)
  • qz=2 (smooth model, m in z-direction)

But if you want share edges of the model, you can try:

  • p=0 (sparse model, m)
  • qx=0 (smooth model, m in x-direction)
  • qz=2 (smooth model, m in z-direction)
  • ../../../_images/sphx_glr_plot_dipoledipole_2_5Dinversion_irls_001.png
  • ../../../_images/sphx_glr_plot_dipoledipole_2_5Dinversion_irls_002.png
  • ../../../_images/sphx_glr_plot_dipoledipole_2_5Dinversion_irls_003.png
  • ../../../_images/sphx_glr_plot_dipoledipole_2_5Dinversion_irls_004.png

Out:

Using a seed of:  37
Compute fields
SimPEG.DataMisfit.l2_DataMisfit assigning default eps of 1e-5 * ||dobs||
SimPEG.InvProblem will set Regularization.mref to m0.

    SimPEG.InvProblem is setting bfgsH0 to the inverse of the eval2Deriv.
    ***Done using same Solver and solverOpts as the problem***
Compute fields
Calculating J and storing
model has any nan: 0
============================ Inexact Gauss Newton ============================
  #     beta     phi_d     phi_m       f      |proj(x-g)-x|  LS    Comment
-----------------------------------------------------------------------------
x0 has any nan: 0
   0  4.54e+00  4.59e+03  0.00e+00  4.59e+03    9.35e+02      0
Compute fields
Calculating J and storing
   1  2.27e+00  5.63e+02  7.87e+01  7.42e+02    1.14e+02      0
Compute fields
Calculating J and storing
   2  1.14e+00  1.69e+02  1.55e+02  3.45e+02    2.53e+01      0   Skip BFGS
Compute fields
Calculating J and storing
   3  5.68e-01  8.86e+01  2.02e+02  2.03e+02    1.51e+01      0   Skip BFGS
Compute fields
Reached starting chifact with l2-norm regularization: Start IRLS steps...
eps_p: 2.4637080077456677 eps_q: 2.4637080077456677
>> Fix Jmatrix
Eps_p: 2.053090006454723
Eps_q: 2.053090006454723
delta phim:    inf
Calculating J and storing
   4  2.84e-01  5.32e+01  4.14e+02  1.71e+02    8.51e+00      0   Skip BFGS
Compute fields
>> Fix Jmatrix
Eps_p: 1.7109083387122692
Eps_q: 1.7109083387122692
delta phim: 6.686e-01
   5  4.84e-01  4.78e+01  5.03e+02  2.91e+02    1.35e+01      0
Compute fields
>> Fix Jmatrix
Eps_p: 1.425756948926891
Eps_q: 1.425756948926891
delta phim: 1.925e-01
   6  8.60e-01  4.35e+01  5.96e+02  5.56e+02    5.07e+01      0
Compute fields
>> Fix Jmatrix
Eps_p: 1.1881307907724092
Eps_q: 1.1881307907724092
delta phim: 1.641e-01
   7  6.70e-01  8.36e+01  5.43e+02  4.47e+02    6.06e+01      0
Compute fields
>> Fix Jmatrix
Eps_p: 0.9901089923103411
Eps_q: 0.9901089923103411
delta phim: 2.634e-02
   8  1.11e+00  5.20e+01  5.91e+02  7.05e+02    8.62e+01      0
Compute fields
>> Fix Jmatrix
Eps_p: 0.8250908269252842
Eps_q: 0.8250908269252842
delta phim: 1.962e-01
   9  7.22e-01  1.21e+02  4.95e+02  4.79e+02    9.22e+01      0
Compute fields
>> Fix Jmatrix
Eps_p: 0.6875756891044036
Eps_q: 0.6875756891044036
delta phim: 8.285e-03
  10  5.26e-01  9.52e+01  4.86e+02  3.51e+02    5.99e+01      0
Compute fields
>> Fix Jmatrix
Eps_p: 0.5729797409203363
Eps_q: 0.5729797409203363
delta phim: 1.289e-01
  11  4.21e-01  7.95e+01  4.57e+02  2.72e+02    4.30e+01      0
Compute fields
>> Fix Jmatrix
Eps_p: 0.4774831174336136
Eps_q: 0.4774831174336136
delta phim: 5.148e-02
  12  3.32e-01  8.14e+01  4.45e+02  2.29e+02    2.80e+01      0
Compute fields
>> Fix Jmatrix
Eps_p: 0.3979025978613447
Eps_q: 0.3979025978613447
delta phim: 1.091e-01
  13  3.32e-01  7.35e+01  4.27e+02  2.15e+02    2.73e+01      0
Compute fields
>> Fix Jmatrix
Eps_p: 0.33158549821778727
Eps_q: 0.33158549821778727
delta phim: 7.688e-02
  14  2.74e-01  7.50e+01  3.84e+02  1.80e+02    2.22e+01      0
Compute fields
>> Fix Jmatrix
Eps_p: 0.27632124851482276
Eps_q: 0.27632124851482276
delta phim: 4.534e-02
  15  2.74e-01  6.82e+01  3.65e+02  1.68e+02    1.80e+01      0
Compute fields
>> Fix Jmatrix
Eps_p: 0.23026770709568564
Eps_q: 0.23026770709568564
delta phim: 7.510e-02
  16  2.74e-01  6.38e+01  3.11e+02  1.49e+02    1.58e+01      0
Compute fields
>> Fix Jmatrix
Eps_p: 0.19188975591307136
Eps_q: 0.19188975591307136
delta phim: 9.814e-03
Minimum decrease in regularization. End of IRLS
------------------------- STOP! -------------------------
1 : |fc-fOld| = 0.0000e+00 <= tolF*(1+|f0|) = 4.5906e+02
1 : |xc-x_last| = 1.4310e+00 <= tolX*(1+|x0|) = 2.6208e+01
0 : |proj(x-g)-x|    = 1.5773e+01 <= tolG          = 1.0000e-01
0 : |proj(x-g)-x|    = 1.5773e+01 <= 1e3*eps       = 1.0000e-02
0 : maxIter   =      40    <= iter          =     17
------------------------- DONE! -------------------------

from SimPEG import DC
from SimPEG import (Maps, Utils, DataMisfit, Regularization,
                    Optimization, Inversion, InvProblem, Directives)
import matplotlib.pyplot as plt
from matplotlib import colors
import numpy as np
from pylab import hist
try:
    from pymatsolver import Pardiso as Solver
except ImportError:
    from SimPEG import SolverLU as Solver


def run(plotIt=True, survey_type="dipole-dipole", p=0., qx=2., qz=2.):
    np.random.seed(1)
    # Initiate I/O class for DC
    IO = DC.IO()
    # Obtain ABMN locations

    xmin, xmax = 0., 200.
    ymin, ymax = 0., 0.
    zmin, zmax = 0, 0
    endl = np.array([[xmin, ymin, zmin], [xmax, ymax, zmax]])
    # Generate DC survey object
    survey = DC.Utils.gen_DCIPsurvey(endl, survey_type=survey_type, dim=2,
                                     a=10, b=10, n=10)
    survey.getABMN_locations()
    survey = IO.from_ambn_locations_to_survey(
        survey.a_locations, survey.b_locations,
        survey.m_locations, survey.n_locations,
        survey_type, data_dc_type='volt'
    )

    # Obtain 2D TensorMesh
    mesh, actind = IO.set_mesh()
    topo, mesh1D = DC.Utils.genTopography(mesh, -10, 0, its=100)
    actind = Utils.surface2ind_topo(mesh, np.c_[mesh1D.vectorCCx, topo])
    survey.drapeTopo(mesh, actind, option="top")

    # Build a conductivity model
    blk_inds_c = Utils.ModelBuilder.getIndicesSphere(
        np.r_[60., -25.], 12.5, mesh.gridCC
    )
    blk_inds_r = Utils.ModelBuilder.getIndicesSphere(
        np.r_[140., -25.], 12.5, mesh.gridCC
    )
    layer_inds = mesh.gridCC[:, 1] > -5.
    sigma = np.ones(mesh.nC)*1./100.
    sigma[blk_inds_c] = 1./10.
    sigma[blk_inds_r] = 1./1000.
    sigma[~actind] = 1./1e8
    rho = 1./sigma

    # Show the true conductivity model
    if plotIt:
        fig = plt.figure(figsize=(12, 3))
        ax = plt.subplot(111)
        temp = rho.copy()
        temp[~actind] = np.nan
        out = mesh.plotImage(
            temp, grid=True, ax=ax, gridOpts={'alpha': 0.2},
            clim=(10, 1000),
            pcolorOpts={"cmap": "viridis", "norm": colors.LogNorm()}
        )
        ax.plot(
            survey.electrode_locations[:, 0],
            survey.electrode_locations[:, 1], 'k.'
        )
        ax.set_xlim(IO.grids[:, 0].min(), IO.grids[:, 0].max())
        ax.set_ylim(-IO.grids[:, 1].max(), IO.grids[:, 1].min())
        cb = plt.colorbar(out[0])
        cb.set_label("Resistivity (ohm-m)")
        ax.set_aspect('equal')
        plt.show()

    # Use Exponential Map: m = log(rho)
    actmap = Maps.InjectActiveCells(
        mesh, indActive=actind, valInactive=np.log(1e8)
    )
    mapping = Maps.ExpMap(mesh) * actmap

    # Generate mtrue
    mtrue = np.log(rho[actind])

    # Generate 2.5D DC problem
    # "N" means potential is defined at nodes
    prb = DC.Problem2D_N(
        mesh, rhoMap=mapping, storeJ=True,
        Solver=Solver, verbose=True
    )
    # Pair problem with survey
    try:
        prb.pair(survey)
    except:
        survey.unpair()
        prb.pair(survey)

    # Make synthetic DC data with 5% Gaussian noise
    dtrue = survey.makeSyntheticData(mtrue, std=0.05, force=True)

    IO.data_dc = dtrue
    # Show apparent resisitivty pseudo-section
    if plotIt:
        IO.plotPseudoSection(
            data=survey.dobs/IO.G, data_type='apparent_resistivity'
        )

    # Show apparent resisitivty histogram
    if plotIt:
        fig = plt.figure()
        out = hist(survey.dobs/IO.G, bins=20)
        plt.xlabel("Apparent Resisitivty ($\Omega$m)")
        plt.show()

    # Set initial model based upon histogram
    m0 = np.ones(actmap.nP)*np.log(100.)

    # Set uncertainty
    # floor
    eps = 10**(-3.2)
    # percentage
    std = 0.05
    dmisfit = DataMisfit.l2_DataMisfit(survey)
    uncert = abs(survey.dobs) * std + eps
    dmisfit.W = 1./uncert

    # Map for a regularization
    regmap = Maps.IdentityMap(nP=int(actind.sum()))

    # Related to inversion
    reg = Regularization.Sparse(
        mesh, indActive=actind, mapping=regmap,
        gradientType='components'
    )
    #     gradientType = 'components'
    reg.norms = np.c_[p, qx, qz, 0.]
    IRLS = Directives.Update_IRLS(
        maxIRLSiter=20, minGNiter=1,
        betaSearch=False, fix_Jmatrix=True
    )

    opt = Optimization.InexactGaussNewton(maxIter=40)
    invProb = InvProblem.BaseInvProblem(dmisfit, reg, opt)
    beta = Directives.BetaSchedule(coolingFactor=5, coolingRate=2)
    betaest = Directives.BetaEstimate_ByEig(beta0_ratio=1e0)
    target = Directives.TargetMisfit()
    update_Jacobi = Directives.UpdatePreconditioner()
    inv = Inversion.BaseInversion(
        invProb, directiveList=[
            betaest, IRLS
        ]
        )
    prb.counter = opt.counter = Utils.Counter()
    opt.LSshorten = 0.5
    opt.remember('xc')

    # Run inversion
    mopt = inv.run(m0)

    rho_est = mapping*mopt
    rho_est_l2 = mapping*invProb.l2model
    rho_est[~actind] = np.nan
    rho_est_l2[~actind] = np.nan
    rho_true = rho.copy()
    rho_true[~actind] = np.nan

    # show recovered conductivity
    if plotIt:
        vmin, vmax = rho.min(), rho.max()
        fig, ax = plt.subplots(3, 1, figsize=(20, 9))
        out1 = mesh.plotImage(
                rho_true, clim=(10, 1000),
                pcolorOpts={"cmap": "viridis", "norm": colors.LogNorm()},
                ax=ax[0]
        )
        out2 = mesh.plotImage(
            rho_est_l2, clim=(10, 1000),
            pcolorOpts={"cmap": "viridis", "norm": colors.LogNorm()},
            ax=ax[1]
        )
        out3 = mesh.plotImage(
            rho_est, clim=(10, 1000),
            pcolorOpts={"cmap": "viridis", "norm": colors.LogNorm()},
            ax=ax[2]
        )

        out = [out1, out2, out3]
        titles = ["True", "L2", ("L%d, Lx%d, Lz%d")%(p, qx, qz)]
        for i in range(3):
            ax[i].plot(
                survey.electrode_locations[:, 0],
                survey.electrode_locations[:, 1], 'kv'
            )
            ax[i].set_xlim(IO.grids[:, 0].min(), IO.grids[:, 0].max())
            ax[i].set_ylim(-IO.grids[:, 1].max(), IO.grids[:, 1].min())
            cb = plt.colorbar(out[i][0], ax=ax[i])
            cb.set_label("Resistivity ($\Omega$m)")
            ax[i].set_xlabel("Northing (m)")
            ax[i].set_ylabel("Elevation (m)")
            ax[i].set_aspect('equal')
            ax[i].set_title(titles[i])
        plt.tight_layout()
        plt.show()


if __name__ == '__main__':
    run()

Total running time of the script: ( 0 minutes 22.995 seconds)

Gallery generated by Sphinx-Gallery