コード例 #1
0
    def simulate(synmodel, ab2=None, mn2=None, errPerc=3.):
        """Forward calculation with optional noise

        Simulates a synthetic data set of a vertical electric sounding and
        appends gaussian distributed noise.
        Block only for now.

        Parameters
        ----------

        ab2: array_like
            Vector of distances between the point of the sounding and the
            current electrodes.

        mn2: array_like [ab2/3]
            Vector of distances between the point of the sounding and the
            potential electrodes.

        errPerc: float [3.]
            Percentage Value for the gaussian noise. Default are 3 %.

        """
        thk = synmodel[0]
        res = synmodel[1]
        if mn2 is None:
            mn2 = ab2 / 3
        FOP = pg.DC1dModelling(len(res), ab2, mn2)
        syndata = FOP.response(thk + res)
        syndata = syndata * (pg.randn(len(syndata)) * errPerc / 100. + 1.)
        return syndata
コード例 #2
0
ファイル: plot_1_dcem.py プロジェクト: ziogibom/gimli
 def __init__(self, nlay, ab2, mn2, freq, coilspacing, verbose=False):
     """Init number of layers, AB/2, MN/2, frequencies & coil spacing."""
     pg.ModellingBase.__init__(self, verbose)
     self.nlay_ = nlay
     self.fDC_ = pg.DC1dModelling(nlay, ab2, mn2, verbose)
     self.fEM_ = pg.FDEM1dModelling(nlay, freq, coilspacing, verbose)
     self.mesh_ = pg.createMesh1DBlock(nlay)
     self.setMesh(self.mesh_)
コード例 #3
0
    def response_mt(self, par, i=0):

        if self.am is not None and self.bm is not None:
            nLayer = (len(par) + 1) // 2
            fop = pg.DC1dModelling(nLayer, self.am, self.bm, self.an, self.bn)
        else:
            raise Exception("I have no data basis .. "
                            "don't know what to calculate.")

        return fop.response(par)
コード例 #4
0
    def createFOP(self):
        """Creates the forward operator instance."""
        if self.type == 'block':
            self.FOP = pg.DC1dModelling(self.Z, self.ab2, self.mn2)
            mesh1D = pg.createMesh1DBlock(self.Z)

        if self.type == 'smooth':
            self.FOP = pg.DC1dRhoModelling(self.Z, self.ab2, self.mn2)
            mesh1D = pg.createMesh1D(nCells=len(self.Z) + 1)

        self.FOP.setMesh(mesh1D)
        self.applyModelTrans()
コード例 #5
0
import numpy as np
import matplotlib.pyplot as plt

import pygimli as pg
from pygimli.mplviewer import drawModel1D

###############################################################################
# some definitions before (model, data and error)
nlay = 4  # number of layers
lam = 200.  # (initial) regularization parameter
errPerc = 10.  # relative error of 3 percent
ab2 = np.logspace(-1, 2, 50)  # AB/2 distance (current electrodes)
mn2 = ab2 / 3.  # MN/2 distance (potential electrodes)
###############################################################################
# initialize the forward modelling operator
f = pg.DC1dModelling(nlay, ab2, mn2)
###############################################################################
# other ways are by specifying a Data Container or am/an/bm/bn distances
synres = [100., 500., 20., 800.]  # synthetic resistivity
synthk = [0.5, 3.5, 6.]  # synthetic thickness (nlay-th layer is infinite)
###############################################################################
# the forward operator can be called by f.response(model) or simply f(model)
rhoa = f(synthk + synres)
rhoa = rhoa * (pg.randn(len(rhoa)) * errPerc / 100. + 1.)
###############################################################################
# create some transformations used for inversion
transThk = pg.RTransLog()  # log-transform ensures thk>0
transRho = pg.RTransLogLU(1, 1000)  # lower and upper bound
transRhoa = pg.RTransLog()  # log transformation for data
###############################################################################
# set model transformation for thickness and resistivity
コード例 #6
0
ファイル: plot-4-dc1dsmooth.py プロジェクト: ziogibom/gimli
###############################################################################
# We import numpy numerics, mpl plotting, pygimli and the 1D plotting function
import numpy as np
import matplotlib.pyplot as plt

import pygimli as pg
from pygimli.mplviewer import drawModel1D

###############################################################################
###############################################################################
# initialize the forward modelling operator and compute synthetic noisy data
synres = [100., 500., 20., 800.]  # synthetic resistivity
synthk = [4, 6, 10]  # synthetic thickness (lay layer is infinite)
ab2 = np.logspace(-1, 2, 25)  # 0.1 to 100 in 25 steps (8 points per decade)
fBlock = pg.DC1dModelling(len(synres), ab2, ab2 / 3)
rhoa = fBlock(synthk + synres)
# The data are noisified using a
errPerc = 3.  # relative error of 3 percent
rhoa = rhoa * (pg.randn(len(rhoa)) * errPerc / 100. + 1.)
###############################################################################
# The forward operator can be called by f.response(model) or simply f(model)
thk = np.logspace(-0.5, 0.5, 30)
f = pg.DC1dRhoModelling(thk, ab2, ab2 / 3)
###############################################################################
# Create some transformations used for inversion
transRho = pg.RTransLogLU(1, 1000)  # lower and upper bound
transRhoa = pg.RTransLog()  # log transformation also for data
###############################################################################
# Set up inversion
inv = pg.RInversion(rhoa, f, transRhoa, transRho, False)  # data vector, f, ...
コード例 #7
0
ファイル: dcem.py プロジェクト: jchavezolalla/gimli
invEM = g.RInversion(dataEM, fEM, transEM, verbose)
modelEM = g.RVector(nlay * 2 - 1, 50.)
invEM.setModel(modelEM)
invEM.setAbsoluteError(noiseEM)
invEM.setLambda(lamEM)
invEM.setMarquardtScheme(0.9)
modelEM = invEM.run()
respEM = invEM.response()

# DC forward operator and synthetic data
ab2 = g.RVector(20, 3.)
na = len(ab2)
mn2 = g.RVector(na, 1.0)
for i in range(na - 1):
    ab2[i + 1] = ab2[i] * 1.3
fDC = g.DC1dModelling(nlay, ab2, mn2)
dataDC = fDC(model)
for i in range(len(dataDC)):
    dataDC[i] *= 1. + P.randn(1)[0] * noiseDC / 100.
fDC.region(0).setTransModel(transThk)
fDC.region(1).setTransModel(transRes)

# independent DC inversion
invDC = g.RInversion(dataDC, fDC, transRhoa, verbose)
modelDC = g.RVector(nlay * 2 - 1, 20.)
invDC.setModel(modelDC)
invDC.setRelativeError(noiseDC / 100.)
invDC.setLambda(lamDC)
invDC.setMarquardtScheme(0.9)
modelDC = invDC.run()
respDC = invDC.response()
コード例 #8
0
ファイル: mrsves.py プロジェクト: jchavezolalla/gimli
 def __init__(self, nlay, K, z, t, ab2, mn2, verbose=False):
     self.nlay_ = nlay
     mesh = pg.createMesh1DBlock(nlay, 3)  # 3 paramaters: thk,wc,t2,res
     pg.ModellingBase.__init__(self, mesh)
     self.fMRS = MRS1dBlockQTModelling(nlay, K, z, t)
     self.fVES = pg.DC1dModelling(nlay, ab2, mn2)
コード例 #9
0
ファイル: mrsves.py プロジェクト: jchavezolalla/gimli
    def runEMO(self, nlay=5, pop_size=100, max_generations=100):
        """
            Run evolutionary multi-objective optimization (EMO)

            Run EMO using inspyred for now fixed to NSGA-II algorithm
            after Deb (2002) TODO (cite correctly)
            (non-dominated sorting genetic algorithm)
        """
        import inspyred

        def genMods(individual):
            """generate MRS and VES models from unit vector"""
            model = individual * (self.lUB - self.lLB) + self.lLB
            #            model = pg.asvector(individual) * (self.lUB - self.lLB) + self.lLB
            if self.logpar:
                model = pg.exp(model)

            modMRS = model(0, nlay * 3 - 1)
            modVES = pg.cat(model(0, nlay - 1),
                            model(nlay * 3 - 1, nlay * 4 - 1))
            return modMRS, modVES

        def mygenerate(random, args):
            """generate a random vector of model size"""
            return [random.random() for i in range(nlay * 4 - 1)]

        @inspyred.ec.evaluators.evaluator
        def datafit(individual, args):
            """return data fits for MRS and VES as Pareto object"""
            modMRS, modVES = genMods(individual)
            MRSmisfit = (self.data - self.f(modMRS)) / self.error
            VESmisfit = (np.log(self.rhoa) -
                         np.log(self.fVES(modVES))) / np.log(1.02)
            return inspyred.ec.emo.Pareto(
                [np.mean(MRSmisfit**2),
                 np.mean(VESmisfit**2)])

        self.createFOP(nlay)
        self.fVES = pg.DC1dModelling(nlay, self.ab2, self.mn2)

        lowerBound = pg.cat(
            pg.cat(pg.RVector(nlay - 1, self.lowerBound[0]),
                   pg.RVector(nlay, self.lowerBound[1])),
            pg.cat(pg.RVector(nlay, self.lowerBound[2]),
                   pg.RVector(nlay, self.lowerBound[3])))
        upperBound = pg.cat(
            pg.cat(pg.RVector(nlay - 1, self.upperBound[0]),
                   pg.RVector(nlay, self.upperBound[1])),
            pg.cat(pg.RVector(nlay, self.upperBound[2]),
                   pg.RVector(nlay, self.upperBound[3])))
        if self.logpar:
            self.lLB, self.lUB = pg.log(lowerBound), pg.log(
                upperBound)  # ready mapping functions
        else:
            self.lLB, self.lUB = lowerBound, upperBound

        rand = random.Random()
        rand.seed(int(time.time()))
        ea = inspyred.ec.emo.NSGA2(rand)
        ea.variator = [
            inspyred.ec.variators.blend_crossover,
            inspyred.ec.variators.gaussian_mutation
        ]
        ea.terminator = inspyred.ec.terminators.generation_termination
        ea.observer = [
            inspyred.ec.observers.stats_observer,
            inspyred.ec.observers.file_observer
        ]
        self.pop = ea.evolve(evaluator=datafit,
                             generator=mygenerate,
                             maximize=False,
                             bounder=inspyred.ec.Bounder(0., 1.),
                             pop_size=pop_size,
                             max_generations=max_generations)