Exemplo n.º 1
0
def showWC(ax, thk, wc, wmin=0., wmax=0.45, maxdep=0., dw=0.05, **kwargs):
    """Show water content function nicely."""
    drawModel1D(ax, thk, wc, xlabel=r'$\theta$')
    ax.set_xlim(0., 0.45)
    if maxdep > 0.:
        ax.set_ylim(maxdep, 0.)
    wt = np.arange(wmin, wmax, dw)
    ax.set_xticks(wt)
    ax.set_xticklabels([str(wi) for wi in wt])
Exemplo n.º 2
0
def showT2(ax, thk, t2, maxdep=0., **kwargs):
    """Show T2 function nicely."""
    drawModel1D(ax, thk, t2 * 1e3, xlabel=r'$T_2^*$ [ms]', plot='semilogx')
    tmin = min(20, min(t2) * 0.9e3)
    tmax = max(500, max(t2) * 1.1e3)
    ax.set_xlim(tmin, tmax)
    if maxdep > 0.:
        ax.set_ylim(maxdep, 0.)
    xt = [20, 50, 100, 200, 500]
    ax.set_xticks(xt)
    ax.set_xticklabels([str(ai) for ai in xt])
Exemplo n.º 3
0
    def showModelAndData(self, model, xpos=0, response=None, figsize=(8, 6)):
        """Show both model and data with response in subfigures."""
        fig, ax = plt.subplots(1, 3, figsize=figsize)

        model = np.asarray(model)
        nlay = int((len(model) + 1) / 2)

        thk = model[:nlay - 1]
        res = model[nlay - 1: 2 * nlay - 1]

        drawModel1D(ax[0], thk, res, plotfunction='semilogx')

        self.plotData(xpos, response, ax=ax[1:3], clf=False)
        return fig, ax
Exemplo n.º 4
0
def plotresults(res, thk, ab2, rhoa, rhoaresponse):
    fig, ax = plt.subplots(ncols=2, figsize=(14,6))
    # drawModel1D(ax[0], thk, res, plot='semilogx', color='r', label='Startmodell')
    drawModel1D(ax[0], thk, res, plot='semilogx', color='b', label='Inversionsmodell')
    ax[0].grid(True, which='both')
    ax[0].set_ylabel('Teufe in m')
    ax[0].set_xlabel(r'$\rho$ in $\Omega\cdot m$')
    ax[0].set_xlim((10.0, 2000.0))
    ax[0].legend(loc='best')

    ax[1].loglog(rhoa, ab2, 'rx-', label='Daten')
    ax[1].loglog(rhoaresponse, ab2, 'b-', label='Modellantwort')
    ax[1].set_ylim((max(ab2), min(ab2)))
    ax[1].set_xlim((10.0, 1000.0))
    ax[1].grid(True, which='both')
    ax[1].legend(loc='best')
    ax[1].set_xlabel(r'$\rho_s$ in $\Omega\cdot m$')
    ax[1].set_ylabel('AB/2 in m')

    plt.show()
Exemplo n.º 5
0
    def plotPopulation(self, maxfitness=None, fitratio=1.05, savefile=True):
        """Plot fittest individuals (fitness<maxfitness) as 1d models

        Parameters
        ----------
        maxfitness : float
            maximum fitness value (absolute) OR
        fitratio : float [1.05]
            maximum ratio to minimum fitness
        """
        if maxfitness is None:
            maxfitness = min(self.fits) * fitratio
        fig, ax = plt.subplots(1, 2, sharey=True)
        self.figs['population'] = fig
        maxz = 0
        for ind in self.pop:
            if ind.fitness < maxfitness:
                model = np.asarray(self.genMod(ind.candidate))
                thk = model[:self.nlay - 1]
                wc = model[self.nlay - 1:self.nlay * 2 - 1]
                t2 = model[self.nlay * 2 - 1:]
                drawModel1D(ax[0], thk, wc * 100, color='grey')
                drawModel1D(ax[1], thk, t2 * 1000, color='grey')
                maxz = max(maxz, sum(thk))

        model = np.asarray(self.genMod(self.pop[0].candidate))
        thk = model[:self.nlay - 1]
        wc = model[self.nlay - 1:self.nlay * 2 - 1]
        t2 = model[self.nlay * 2 - 1:]
        drawModel1D(ax[0], thk, wc * 100, color='black', linewidth=3)
        drawModel1D(ax[1],
                    thk,
                    t2 * 1000,
                    color='black',
                    linewidth=3,
                    plotfunction='semilogx')

        ax[0].set_xlim(self.lowerBound[1] * 100, self.upperBound[1] * 100)
        ax[0].set_ylim((maxz * 1.2, 0))
        ax[1].set_xlim(self.lowerBound[2] * 1000, self.upperBound[2] * 1000)
        ax[1].set_ylim((maxz * 1.2, 0))
        xt = [10, 20, 50, 100, 200, 500, 1000]
        ax[1].set_xticks(xt)
        ax[1].set_xticklabels([str(xti) for xti in xt])
        if savefile:
            fig.savefig(self.EAstatfile.replace('.csv', '.pdf'),
                        bbox_inches='tight')

        plt.show()
Exemplo n.º 6
0
# could also be set by inv.setTransData(transRhoa)
###############################################################################
# set error model, regularization strength and Marquardt scheme
inv.setRelativeError(errPerc / 100.0)  # alternative: setAbsoluteError in Ohmm
inv.setLambda(lam)  # (initial) regularization parameter
inv.setMarquardtScheme(0.9)  # decrease lambda by factor 0.9
model = f.createStartVector()  # creates from region start value
model[nlay] *= 1.5  # change default model by changing 2nd layer resistivity
inv.setModel(model)  #
###############################################################################
# run actual inversion and extract resistivity and thickness
model = inv.run()  # result is a pg.Vector, but compatible to numpy array
res, thk = model[nlay-1:nlay*2-1], model[0:nlay-1]
print('rrms={:.2f}%, chi^2={:.3f}'.format(inv.relrms(), inv.chi2()))
###############################################################################
# show estimated&synthetic models and data with model response in 2 subplots
fig, ax = plt.subplots(ncols=2, figsize=(8, 6))  # two-column figure
drawModel1D(ax[0], synthk, synres, plot='semilogx', color='r')
drawModel1D(ax[0], thk, res, color='b')
ax[0].grid(True, which='both')
ax[0].set_ylabel('z (m)')
ax[0].set_xlabel(r'$\rho$ ($\Omega$m)')
ax[1].loglog(rhoa, ab2, 'rx-', label='data')  # sounding curve
ax[1].loglog(inv.response(), ab2, 'b-', label='response')
ax[1].set_ylim((max(ab2), min(ab2)))  # downwards according to penetration
ax[1].grid(True, which='both')
ax[1].set_xlabel(r'$\rho_a$ ($\Omega$m)')
ax[1].set_ylabel('AB/2 (m)')
ax[1].legend(loc='best')
plt.show()
Exemplo n.º 7
0
invDCEM.setMarquardtScheme(0.9)
modelDCEM = invDCEM.run()
respDCEM = invDCEM.response()

###############################################################################
# The results of the inversion are plotted for comparison.

for inv in [invEM, invDC, invDCEM]:
    inv.echoStatus()
print([invEM.chi2(), invDC.chi2(), invDCEM.chi2()])  # chi-square values

###############################################################################
# %% We finally plot the results
fig = plt.figure(1, figsize=(10, 5))
ax1 = fig.add_subplot(131)
drawModel1D(ax1, thk, res, plot='semilogx', color='blue')
drawModel1D(ax1,
            modelEM[0:nlay - 1],
            modelEM[nlay - 1:nlay * 2 - 1],
            color='green')
drawModel1D(ax1,
            modelDC[0:nlay - 1],
            modelDC[nlay - 1:nlay * 2 - 1],
            color='cyan')
drawModel1D(ax1,
            modelDCEM[0:nlay - 1],
            modelDCEM[nlay - 1:nlay * 2 - 1],
            color='red')
ax1.legend(('syn', 'EM', 'DC', 'JI'))
ax1.set_xlim((10., 1000.))
ax1.set_ylim((40., 0.))
Exemplo n.º 8
0
# Decrease the regularization (smoothness) and start (from old result)
print("inversion with lam=20")
inv.setLambda(10)
res10 = inv.run()  # result is a pg.Vector, but compatible to numpy array
print('rrms={:.2f}%, chi^2={:.3f}'.format(inv.relrms(), inv.chi2()))
# We now optimize lambda such that data are fitted within noise (chi^2=1)
print("chi^2=1 optimized inversion")
resChi = inv.runChi1()  # ends up in a lambda of about 3
print("optimized lambda value:", inv.getLambda())
print('rrms={:.2f}%, chi^2={:.3f}'.format(inv.relrms(), inv.chi2()))
###############################################################################
# Show model (inverted and synthetic) as well as model response and data
fig, ax = plt.subplots(ncols=2, figsize=(8, 6))  # two-column figure
drawModel1D(ax[0],
            synthk,
            synres,
            color='b',
            label='synthetic',
            plot='semilogx')
drawModel1D(ax[0], thk, res100, color='g', label=r'$\lambda$=100')
drawModel1D(ax[0], thk, res10, color='c', label=r'$\lambda$=10')
drawModel1D(ax[0],
            thk,
            resChi,
            color='r',
            label=r'$\chi$={:.2f}'.format(inv.getLambda()))
ax[0].grid(True, which='both')
ax[0].legend(loc='best')
ax[1].loglog(rhoa, ab2, 'rx-', label='measured')
ax[1].loglog(inv.response(), ab2, 'b-', label='fitted')
ax[1].set_ylim((max(ab2), min(ab2)))
ax[1].grid(True, which='both')
Exemplo n.º 9
0
invDCEM.setMarquardtScheme(0.9)
modelDCEM = invDCEM.run()
respDCEM = invDCEM.response()

###############################################################################
# The results of the inversion are plotted for comparison.

for inv in [invEM, invDC, invDCEM]:
    inv.echoStatus()
print([invEM.chi2(), invDC.chi2(), invDCEM.chi2()])  # chi-square values

###############################################################################
# %% We finally plot the results
fig = plt.figure(1, figsize=(10, 5))
ax1 = fig.add_subplot(131)
drawModel1D(ax1, thk, res, plot='semilogx', color='blue')
drawModel1D(ax1,
            modelEM(0, nlay - 1),
            modelEM(nlay - 1, nlay * 2 - 1),
            color='green')
drawModel1D(ax1,
            modelDC(0, nlay - 1),
            modelDC(nlay - 1, nlay * 2 - 1),
            color='cyan')
drawModel1D(ax1,
            modelDCEM(0, nlay - 1),
            modelDCEM(nlay - 1, nlay * 2 - 1),
            color='red')
ax1.legend(('syn', 'EM', 'DC', 'JI'))
ax1.set_xlim((10., 1000.))
ax1.set_ylim((40., 0.))