Maps: ComboMaps#

Invert synthetic magnetic data with variable background values and a single block anomaly buried at depth. We will use the Sum Map to invert for both the background values and an heterogeneous susceptibiilty model.

1
  • plot sumMap
  • plot sumMap
Running inversion with SimPEG v0.25.2.dev6+gba60041a8
================================================= Projected GNCG =================================================
  #     beta     phi_d     phi_m       f      |proj(x-g)-x|  LS   iter_CG   CG |Ax-b|/|b|  CG |Ax-b|   Comment
-----------------------------------------------------------------------------------------------------------------
   0  6.07e+05  9.11e+06  4.27e-04  9.11e+06                         0           inf          inf
   1  6.07e+05  1.37e+05  7.03e-02  1.80e+05    6.29e+01      0      3        8.28e-04     1.14e+06
   2  3.04e+05  4.95e+04  2.21e-01  1.17e+05    3.51e+01      0      9        6.56e-04     2.78e+04
   3  1.52e+05  2.14e+04  3.51e-01  7.46e+04    4.91e+01      0      10       3.29e-02     5.03e+04
   4  7.59e+04  7.06e+03  4.67e-01  4.25e+04    5.45e+01      0      7        7.82e-04     7.70e+03
   5  3.80e+04  4.20e+03  5.42e-01  2.48e+04    4.81e+01      0      10       7.36e-03     3.95e+03
   6  1.90e+04  1.06e+03  5.97e-01  1.24e+04    3.65e+01      0      4        9.17e-04     1.73e+04
   7  9.49e+03  1.06e+03  5.97e-01  6.72e+03    4.86e+01      6      10       6.01e-02     9.25e+03
   8  4.74e+03  4.75e+02  6.46e-01  3.54e+03    4.97e+01      0      10       4.70e-02     2.09e+04
   9  2.37e+03  4.64e+02  6.49e-01  2.00e+03    3.67e+01      2      10       4.35e-01     6.88e+04
  10  1.19e+03  4.10e+02  6.69e-01  1.20e+03    3.51e+01      0      10       6.68e-02     6.62e+04
  11  5.93e+02  4.10e+02  6.69e-01  8.08e+02    6.10e+01     12      10       2.78e-01     1.69e+05
  12  2.97e+02  4.09e+02  6.69e-01  6.08e+02    6.09e+01      4      10       3.75e-02     2.29e+04
  13  1.48e+02  4.00e+02  6.81e-01  5.01e+02    5.28e+01      1      10       8.35e-02     8.33e+03
Reached starting chifact with l2-norm regularization: Start IRLS steps...
irls_threshold 0.010166219936229097
irls_threshold 0.012817566310528083
  14  1.48e+02  4.00e+02  9.53e-01  5.41e+02    3.75e+01     11      10       9.56e-02     9.05e+04
  15  1.48e+02  3.97e+02  1.02e+00  5.49e+02    3.75e+01      4      10       1.37e-02     1.29e+04
  16  1.48e+02  3.86e+02  1.10e+00  5.50e+02    5.15e+01      0      10       1.02e+00     1.21e+05
  17  1.48e+02  3.86e+02  1.16e+00  5.58e+02    4.39e+01      6      10       1.35e-01     4.67e+04
  18  1.48e+02  3.86e+02  1.17e+00  5.60e+02    4.34e+01      3      10       1.65e-01     6.06e+04
  19  1.48e+02  3.86e+02  1.16e+00  5.58e+02    5.90e+01      1      10       2.47e-02     8.06e+03
  20  1.48e+02  3.86e+02  1.13e+00  5.54e+02    4.49e+01     11      10       1.06e-01     2.75e+04
  21  1.48e+02  3.87e+02  1.09e+00  5.49e+02    4.47e+01      3      10       3.64e-01     9.46e+04
  22  1.48e+02  3.87e+02  1.02e+00  5.38e+02    4.18e+01      1      10       4.10e-01     6.36e+04
  23  1.48e+02  3.85e+02  9.50e-01  5.25e+02    3.76e+01      3      10       2.29e-02     1.71e+04
  24  1.48e+02  3.85e+02  8.90e-01  5.17e+02    5.43e+01      7      10       2.28e-01     7.68e+04
  25  1.48e+02  3.84e+02  8.20e-01  5.06e+02    5.52e+01      4      10       1.45e-01     5.03e+04
  26  1.48e+02  3.84e+02  7.16e-01  4.90e+02    3.53e+01      0      10       2.62e-01     5.02e+04
  27  1.48e+02  3.84e+02  6.36e-01  4.78e+02    5.85e+01      5      10       6.97e-02     3.11e+04
  28  1.48e+02  3.82e+02  5.64e-01  4.66e+02    5.94e+01      2      10       1.54e-01     7.66e+04
  29  1.48e+02  3.80e+02  4.97e-01  4.54e+02    4.29e+01      0      10       5.52e-02     1.15e+04
  30  1.48e+02  3.81e+02  4.33e-01  4.45e+02    3.80e+01      1      10       4.02e-02     2.31e+04
  31  1.48e+02  3.82e+02  3.84e-01  4.39e+02    6.28e+01      2      10       1.16e-01     9.70e+04
  32  1.48e+02  3.82e+02  3.34e-01  4.31e+02    6.28e+01      1      10       2.88e-02     2.59e+04
  33  1.48e+02  3.76e+02  2.94e-01  4.19e+02    4.10e+01      0      10       7.83e-02     4.53e+04
Reach maximum number of IRLS cycles: 20
------------------------- STOP! -------------------------
1 : |fc-fOld| = 6.7319e+00 <= tolF*(1+|f0|) = 9.1067e+05
1 : |xc-x_last| = 5.8536e-03 <= tolX*(1+|x0|) = 1.0075e-01
0 : |proj(x-g)-x|    = 4.1006e+01 <= tolG          = 1.0000e-03
0 : |proj(x-g)-x|    = 4.1006e+01 <= 1e3*eps       = 1.0000e-03
0 : maxIter   =     100    <= iter          =     33
------------------------- DONE! -------------------------

from discretize import TensorMesh
from discretize.utils import active_from_xyz
from simpeg import (
    utils,
    maps,
    regularization,
    data_misfit,
    optimization,
    inverse_problem,
    directives,
    inversion,
)
from simpeg.potential_fields import magnetics
import numpy as np
import matplotlib.pyplot as plt


def run(plotIt=True):
    h0_amplitude, h0_inclination, h0_declination = (50000.0, 90.0, 0.0)

    # Create a mesh
    dx = 5.0

    hxind = [(dx, 5, -1.3), (dx, 10), (dx, 5, 1.3)]
    hyind = [(dx, 5, -1.3), (dx, 10), (dx, 5, 1.3)]
    hzind = [(dx, 5, -1.3), (dx, 10)]

    mesh = TensorMesh([hxind, hyind, hzind], "CCC")

    # Lets create a simple Gaussian topo and set the active cells
    [xx, yy] = np.meshgrid(mesh.nodes_x, mesh.nodes_y)
    zz = -np.exp((xx**2 + yy**2) / 75**2) + mesh.nodes_z[-1]

    # We would usually load a topofile
    topo = np.c_[utils.mkvc(xx), utils.mkvc(yy), utils.mkvc(zz)]

    # Go from topo to array of indices of active cells
    actv = active_from_xyz(mesh, topo, "N")
    nC = int(actv.sum())
    # Create and array of observation points
    xr = np.linspace(-20.0, 20.0, 20)
    yr = np.linspace(-20.0, 20.0, 20)
    X, Y = np.meshgrid(xr, yr)

    # Move the observation points 5m above the topo
    Z = -np.exp((X**2 + Y**2) / 75**2) + mesh.nodes_z[-1] + 5.0

    # Create a MAGsurvey
    rxLoc = np.c_[utils.mkvc(X.T), utils.mkvc(Y.T), utils.mkvc(Z.T)]
    rxLoc = magnetics.Point(rxLoc)
    srcField = magnetics.UniformBackgroundField(
        receiver_list=[rxLoc],
        amplitude=h0_amplitude,
        inclination=h0_inclination,
        declination=h0_declination,
    )
    survey = magnetics.Survey(srcField)

    # We can now create a susceptibility model and generate data
    model = np.zeros(mesh.nC)

    # Change values in half the domain
    model[mesh.gridCC[:, 0] < 0] = 0.01

    # Add a block in half-space
    model = utils.model_builder.add_block(
        mesh.gridCC, model, np.r_[-10, -10, 20], np.r_[10, 10, 40], 0.05
    )

    model = utils.mkvc(model)
    model = model[actv]

    # Create active map to go from reduce set to full
    actvMap = maps.InjectActiveCells(mesh, actv, np.nan)

    # Create reduced identity map
    idenMap = maps.IdentityMap(nP=nC)

    # Create the forward model operator
    prob = magnetics.Simulation3DIntegral(
        mesh,
        survey=survey,
        chiMap=idenMap,
        active_cells=actv,
        store_sensitivities="forward_only",
    )

    # Compute linear forward operator and compute some data
    data = prob.make_synthetic_data(
        model, relative_error=0.0, noise_floor=1, add_noise=True
    )

    # Create a homogenous maps for the two domains
    domains = [mesh.gridCC[actv, 0] < 0, mesh.gridCC[actv, 0] >= 0]
    homogMap = maps.SurjectUnits(domains)

    # Create a wire map for a second model space, voxel based
    wires = maps.Wires(("homo", len(domains)), ("hetero", nC))

    # Create Sum map
    sumMap = maps.SumMap([homogMap * wires.homo, wires.hetero])

    # Create the forward model operator
    prob = magnetics.Simulation3DIntegral(
        mesh, survey=survey, chiMap=sumMap, active_cells=actv, store_sensitivities="ram"
    )

    # Make sensitivity weighting
    # Take the cell number out of the scaling.
    # Want to keep high sens for large volumes
    wr = (
        prob.getJtJdiag(np.ones(sumMap.shape[1]))
        / np.r_[homogMap.P.T * mesh.cell_volumes[actv], mesh.cell_volumes[actv]] ** 2.0
    )
    # Scale the model spaces independently
    wr[wires.homo.index] /= np.max((wires.homo * wr)) * utils.mkvc(
        homogMap.P.sum(axis=0).flatten()
    )
    wr[wires.hetero.index] /= np.max(wires.hetero * wr)
    wr = wr**0.5

    ## Create a regularization
    # For the homogeneous model
    regMesh = TensorMesh([len(domains)])

    reg_m1 = regularization.Sparse(regMesh, mapping=wires.homo)
    reg_m1.set_weights(weights=wires.homo * wr)

    reg_m1.norms = [0, 2]
    reg_m1.reference_model = np.zeros(sumMap.shape[1])

    # Regularization for the voxel model
    reg_m2 = regularization.Sparse(
        mesh, active_cells=actv, mapping=wires.hetero, gradient_type="components"
    )
    reg_m2.set_weights(weights=wires.hetero * wr)

    reg_m2.norms = [0, 0, 0, 0]
    reg_m2.reference_model = np.zeros(sumMap.shape[1])

    reg = reg_m1 + reg_m2

    # Data misfit function
    dmis = data_misfit.L2DataMisfit(simulation=prob, data=data)

    # Add directives to the inversion
    opt = optimization.ProjectedGNCG(
        maxIter=100,
        lower=0.0,
        upper=1.0,
        maxIterLS=20,
        cg_maxiter=10,
        cg_rtol=1e-3,
        tolG=1e-3,
        eps=1e-6,
    )
    invProb = inverse_problem.BaseInvProblem(dmis, reg, opt)
    betaest = directives.BetaEstimate_ByEig(beta0_ratio=1e-2)

    # Here is where the norms are applied
    # Use pick a threshold parameter empirically based on the distribution of
    #  model parameters
    IRLS = directives.UpdateIRLS(f_min_change=1e-3)

    update_Jacobi = directives.UpdatePreconditioner()
    inv = inversion.BaseInversion(invProb, directiveList=[IRLS, betaest, update_Jacobi])

    # Run the inversion
    m0 = np.ones(sumMap.shape[1]) * 1e-4  # Starting model
    prob.model = m0
    mrecSum = inv.run(m0)
    if plotIt:
        mesh.plot_3d_slicer(
            actvMap * model,
            aspect="equal",
            zslice=30,
            pcolor_opts={"cmap": "inferno_r"},
            transparent="slider",
        )

        mesh.plot_3d_slicer(
            actvMap * sumMap * mrecSum,
            aspect="equal",
            zslice=30,
            pcolor_opts={"cmap": "inferno_r"},
            transparent="slider",
        )


if __name__ == "__main__":
    run()
    plt.show()

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

Estimated memory usage: 341 MB

Gallery generated by Sphinx-Gallery