In [1]:
import numpy as np
%pylab inline


Populating the interactive namespace from numpy and matplotlib

In [2]:
def AofT(time,T, ai, taui):
    return ai*np.exp(-time/taui)/(1.+np.exp(-T/(2*taui)))

In [3]:
from SimPEG import *
from simpegem1d.Waveform import CausalConv
import sys
sys.path.append("./DoubleLog/")
from plotting import mapDat
import cPickle as pickle

In [4]:
milligan = pickle.load(open("milligan.p"))

In [5]:
DAT = milligan['DAT']
Header = milligan['header']
time_vtem_mus = np.r_[99,120,141,167,198,234,281,339,406,484,573,682,818,974,1151,1370,1641,1953,2307,2745,3286,3911,4620,5495,6578,7828,9245]
time = time_vtem_mus[4:]*1e-6
obsdata = DAT[:,13:13+27]
xyz = np.c_[DAT[:,0], DAT[:,1], DAT[:,3]]
line = milligan['Line']

In [6]:
linenum = 6
Line = np.unique(line)
indline = line == Line[linenum]
print Line[linenum]
# plt.plot(xyz[:,0], xyz[:,1], '.')
# plt.plot(xyz[indline,0], xyz[indline,1], 'r.')


560

In [7]:
obs_line = obsdata[indline,4:][::10,:]
xyz_line = xyz[indline,:][::10,:]

In [8]:
class LinearSurvey(Survey.BaseSurvey):
    nD = None
    xyz = None
    uncert = None
    def __init__(self, time, xyz,**kwargs): 
        self.time = time        
        self.xyz = xyz
        self.ntime = time.size
        self.ntx = self.xyz.shape[0]
        self.nD = self.ntime*self.ntx
                
    def projectFields(self, u):
        return u
    
    def setUncertainty(self, dobs, perc=0.1, floor=0.):
        self.uncert = np.zeros((self.ntime, self.ntx))
        self.dobs = dobs        
        dobs = dobs.reshape((self.ntime, self.ntx), order='F')
        for itx in range(self.ntx):
            ipind = dobs[:,itx]<0.
            if (ipind).sum() > 3:
                ip = dobs[ipind,itx]
                self.uncert[:,itx] = perc*abs(dobs[:,itx]) + abs(ip).max()
            else:
                self.uncert[:,itx] = perc*abs(dobs[:,itx])+floor
        self.uncert = Utils.mkvc(self.uncert)

        return self.uncert

class LinearProblem(Problem.BaseProblem):

    surveyPair = LinearSurvey
    tau = None
    
    def __init__(self, mesh,**kwargs):
        Problem.BaseProblem.__init__(self, mesh, **kwargs)
        self.setTau()
        
    #TODO: make general (not it works for db/dt)
    def getG(self, currentderiv, timeconv, t0=0.):    
        dt = timeconv[1]-timeconv[0]
        ntime = time_conv.size
        meshtime = Mesh.TensorMesh([dt*np.ones(ntime)], x0=[-dt/2.])
        P = meshtime.getInterpolationMat(time+t0, 'CC')        
        self.G = np.zeros((self.survey.ntime, self.ntau))
        for j in range(self.ntau):
            self.G[:,j] = P*(CausalConv(1./self.tau[j]*np.exp(-time_conv/self.tau[j]), -currentderiv, time_conv))    
            
    def setTau(self, minlogtau=-5, maxlogtau=-2, ntau = 81):
        self.tau = np.logspace(minlogtau, maxlogtau, ntau)
        self.ntau = ntau
        
    def fields(self, m, u=None):
        m = m.reshape((self.ntau, self.survey.ntx), order='F')
        pred = self.G.dot(m)
        return Utils.mkvc(pred)

    def Jvec(self, m, v, u=None):
        v = v.reshape((self.ntau, self.survey.ntx), order='F')
        jvec = self.G.dot(v)   
        return Utils.mkvc(jvec)

    def Jtvec(self, m, v, u=None):
        v = v.reshape((self.survey.ntime, self.survey.ntx), order='F')
        jtvec = self.G.T.dot(v)
        return Utils.mkvc(jtvec)

In [9]:
Regularization.BaseRegularization


Out[9]:
SimPEG.Regularization.BaseRegularization

In [ ]:


In [10]:
meshline = Mesh.TensorMesh([2])
Gx = meshline.cellGradx

In [11]:
Gx.todense()


Out[11]:
matrix([[ 0.,  0.],
        [-2.,  2.],
        [ 0.,  0.]])

Simple exponential basis

$$ \mathbf{A}\mathbf{\alpha} = \mathbf{d}$$

In [12]:
tind = 12
# time = np.load('./exampledata/timevtem.npy')[4:]
# obs = np.load('./exampledata/souding.npy')[4:]
wave = np.loadtxt('/Users/sgkang/Dropbox/Shared/SeogiDikun/Milligan/Data/7042_106_wform.xyz', skiprows=7)
M = 81
tau = np.logspace(-5, -2, M)

In [13]:
twave = (np.arange(10000)+1)*1e-5
indstart = 4439
indend = 6000
t0_wave = twave[indstart:indend].min()
time_conv= twave[indstart:indend]-t0_wave

In [14]:
currentderiv = wave[indstart:indend]
currentderiv[time_conv>4.4e-3] = 0.
current = CausalConv(wave[indstart:indend], np.ones_like(wave[indstart:indend]), time_conv)

In [15]:
# figsize(6, 4)

plt.plot(time_conv, wave[indstart:indend], 'b.', lw=2, ms=4)
plt.plot(time_conv, wave[indstart:indend]*0., 'k--')
plt.plot(np.r_[4.4000000e-03, 4.4000000e-03], np.r_[-4.5, 4.5], 'k:')
plt.ylim(-4.5, 4.5)
# plt.xlim(-2e-4, 5.5e-3)


Out[15]:
(-4.5, 4.5)

In [16]:
figsize(6, 4)
plt.plot(time_conv, current/current.max(), 'k-')
# plt.plot(time_conv, wave[indstart:indend]*0., 'k--')
plt.plot(np.r_[4.4000000e-03, 4.4000000e-03], np.r_[1e-6, 1e-2], 'k:')
plt.plot(time, np.zeros_like(time), 'r.')
plt.ylim(0, 1.)


Out[16]:
(0, 1.0)

In [17]:
from SimPEG import Mesh
from simpegem1d.Waveform import SineFun, SineFunDeriv, CausalConv
dt = 1e-5
t0 = 4.4e-03
ntime = time_conv.size
meshtime = Mesh.TensorMesh([dt*np.ones(ntime)], x0=[-dt/2.])
P = meshtime.getInterpolationMat(time+t0, 'CC')
# time_conv = meshtime.gridN
# currentderiv = SineFunDeriv(time_conv, t0)
# current = SineFun(time_conv, t0)

In [18]:
temp = np.exp(-time_conv/1e-2)/1e-2
out = CausalConv(temp, currentderiv, time_conv)
# plt.plot(time_conv, currentderiv)

In [19]:
plt.plot(time_conv, out)


Out[19]:
[<matplotlib.lines.Line2D at 0x10a224e50>]

In [20]:
time_conv.min(), time_conv.max()


Out[20]:
(0.0, 0.015600000000000003)

In [21]:
P.shape


Out[21]:
(23, 1561)

In [22]:
# N = time.size
# A = np.zeros((N, M))
# for j in range(M):
#     A[:,j] = P*(CausalConv(1./tau[j]*np.exp(-time_conv/tau[j]), -currentderiv, time_conv))

In [23]:
meshline = Mesh.TensorMesh([xyz_line.shape[0]])
prob = LinearProblem(meshline)
survey = LinearSurvey(time, xyz_line)
prob.pair(survey)
prob.getG(currentderiv, time_conv, t0=4.4e-3)
uncert = survey.setUncertainty(obs_line.flatten(), perc=0.03, floor=1e-4)

In [24]:
mtrue = np.zeros(prob.ntau)
np.random.seed(1)
inds = np.random.random_integers(0, 41, size=5)
mtrue[inds] = np.r_[0.1, 2, 1, 4, 5]
m0 = (np.repeat(mtrue.reshape([1,-1]), survey.ntx, axis=0)).flatten()

In [25]:
from SimPEG import Maps

In [26]:
weightone = np.sqrt(np.diag(np.dot(prob.G.T, prob.G)))

weight = (np.repeat(weightone.reshape([1,-1]), survey.ntx, axis=0)).flatten()
meshreg = Mesh.TensorMesh([weight.size])
wmap = Maps.Weighting(meshreg, weights=weight)

In [27]:
plt.semilogx(prob.tau, weightone)


Out[27]:
[<matplotlib.lines.Line2D at 0x10a51ca50>]

In [28]:
print uncert.shape
print survey.dobs.shape


(2691,)
(2691,)

In [44]:
from SimPEG.Regularization import BaseRegularization as BaseRegularization
class SmoothAEMRegularization(BaseRegularization):    
    xyz_line = None
    ntau = 81
    alpha_s = 1e0
    alpha_x = 1e0
    def __init__(self, mesh, mapping=None, **kwargs):
        BaseRegularization.__init__(self, mesh, mapping=mapping, **kwargs)
        
    @property
    def W(self):
        """Regularization matrix W"""
        if getattr(self, '_W', None) is None:
            ntx = self.xyz_line.shape[0]
            meshline = Mesh.TensorMesh([ntx])
            Gx = meshline.cellGradx
            Wx = np.sqrt(self.alpha_x)*sp.kron(Gx, Utils.speye(self.ntau))
            Ws = np.sqrt(self.alpha_s)*Utils.speye(self.ntau*ntx)
            wlist = (Wx, Ws)
            self._W = sp.vstack(wlist)            
        return self._W

In [45]:
meshline = Mesh.TensorMesh([survey.ntx])

In [46]:
meshline.nF*prob.ntau


Out[46]:
9558

In [47]:
# test = reg.W*Utils.mkvc(mrec)
# test = test.reshape((prob.ntau, meshline.nF), order='F')
# itau = 11
# plt.plot(meshline.vectorCCx, mrec[itau,:])
# plt.plot(meshline.vectorNx, test[itau,:])

In [48]:
# reg = Regularization.BaseRegularization(meshreg, mapping=wmap)
# reg = Regularization.BaseRegularization(meshreg)
reg = SmoothAEMRegularization(meshreg, mapping=wmap)
reg.xyz_line = xyz_line
dmis = DataMisfit.l2_DataMisfit(survey)
dmis.Wd = 1./(uncert)
opt = Optimization.ProjectedGNCG(maxIter=200)
# opt = Optimization.InexactGaussNewton(maxIter=20)
opt.lower = 1e-20
# opt.upper = 1e-10
invProb = InvProblem.BaseInvProblem(dmis, reg, opt)
betaest = Directives.BetaEstimate_ByEig(beta0_ratio=1e-12)
beta = Directives.BetaSchedule()
beta.coolingFactor = 1
target = Directives.TargetMisfit()
inv = Inversion.BaseInversion(invProb, directiveList=[beta, target, betaest])
opt.tolG = 1e-10
opt.tolG = 1e-10
m0 = np.ones_like(weight)*1e-10
reg.mref = np.zeros_like(m0)
mrec = inv.run(m0)


SimPEG.InvProblem is setting bfgsH0 to the inverse of the eval2Deriv.
                    ***Done using same solver as the problem***
=============================== Projected GNCG ===============================
  #     beta     phi_d     phi_m       f      |proj(x-g)-x|  LS    Comment   
-----------------------------------------------------------------------------
   0  2.19e-09  7.16e+05  2.58e-16  7.16e+05    1.26e+07      0              
   1  2.19e-09  3.77e+05  5.21e-01  3.77e+05    8.35e+05      0              
   2  2.19e-09  1.12e+05  2.47e+01  1.12e+05    5.20e+05      0              
   3  2.19e-09  1.03e+05  2.93e+01  1.03e+05    5.14e+05      1   Skip BFGS  
   4  2.19e-09  9.89e+04  3.94e+01  9.89e+04    4.27e+05      0   Skip BFGS  
   5  2.19e-09  7.14e+04  4.29e+01  7.14e+04    7.25e+05      0              
   6  2.19e-09  5.45e+04  8.08e+01  5.45e+04    4.87e+05      0              
   7  2.19e-09  4.85e+04  6.61e+01  4.85e+04    5.82e+05      0              
   8  2.19e-09  4.46e+04  8.98e+01  4.46e+04    5.32e+05      0              
   9  2.19e-09  4.15e+04  1.13e+02  4.15e+04    4.76e+05      0   Skip BFGS  
  10  2.19e-09  3.91e+04  8.15e+01  3.91e+04    7.00e+05      0              
  11  2.19e-09  3.60e+04  8.59e+01  3.60e+04    5.67e+05      0              
  12  2.19e-09  3.00e+04  7.86e+01  3.00e+04    1.15e+06      0              
  13  2.19e-09  2.89e+04  7.93e+01  2.89e+04    9.33e+05      0              
  14  2.19e-09  2.57e+04  1.31e+02  2.57e+04    1.39e+06      0              
  15  2.19e-09  2.38e+04  1.83e+02  2.38e+04    1.14e+06      0              
  16  2.19e-09  2.23e+04  2.42e+02  2.23e+04    9.47e+05      0              
  17  2.19e-09  2.19e+04  2.27e+02  2.19e+04    8.49e+05      0   Skip BFGS  
  18  2.19e-09  2.17e+04  2.45e+02  2.17e+04    9.43e+05      0              
  19  2.19e-09  2.09e+04  2.99e+02  2.09e+04    9.55e+05      0   Skip BFGS  
  20  2.19e-09  2.03e+04  2.59e+02  2.03e+04    8.60e+05      0              
  21  2.19e-09  1.97e+04  2.96e+02  1.97e+04    8.61e+05      0              
  22  2.19e-09  1.82e+04  3.10e+02  1.82e+04    8.85e+05      0              
  23  2.19e-09  1.66e+04  4.24e+02  1.66e+04    9.93e+05      0              
  24  2.19e-09  1.61e+04  4.83e+02  1.61e+04    9.33e+05      0              
  25  2.19e-09  1.56e+04  5.86e+02  1.56e+04    9.98e+05      0   Skip BFGS  
  26  2.19e-09  1.54e+04  5.71e+02  1.54e+04    1.00e+06      0              
  27  2.19e-09  1.48e+04  7.19e+02  1.48e+04    1.08e+06      0              
  28  2.19e-09  1.43e+04  7.06e+02  1.43e+04    9.90e+05      0              
  29  2.19e-09  1.36e+04  6.54e+02  1.36e+04    1.04e+06      0   Skip BFGS  
  30  2.19e-09  1.35e+04  6.94e+02  1.35e+04    1.01e+06      0              
  31  2.19e-09  1.33e+04  7.94e+02  1.33e+04    1.04e+06      0   Skip BFGS  
  32  2.19e-09  1.31e+04  7.29e+02  1.31e+04    9.82e+05      0              
  33  2.19e-09  1.29e+04  7.03e+02  1.29e+04    9.79e+05      0   Skip BFGS  
  34  2.19e-09  1.28e+04  7.52e+02  1.28e+04    9.72e+05      0              
  35  2.19e-09  1.26e+04  7.16e+02  1.26e+04    9.26e+05      0              
  36  2.19e-09  1.25e+04  7.18e+02  1.25e+04    9.58e+05      0              
  37  2.19e-09  1.25e+04  7.09e+02  1.25e+04    9.60e+05      0              
  38  2.19e-09  1.22e+04  8.00e+02  1.22e+04    8.61e+05      0   Skip BFGS  
  39  2.19e-09  1.21e+04  8.10e+02  1.21e+04    8.82e+05      0              
  40  2.19e-09  1.21e+04  8.21e+02  1.21e+04    8.98e+05      0   Skip BFGS  
  41  2.19e-09  1.21e+04  8.14e+02  1.21e+04    8.78e+05      0              
  42  2.19e-09  1.20e+04  8.09e+02  1.20e+04    8.95e+05      0   Skip BFGS  
  43  2.19e-09  1.20e+04  8.15e+02  1.20e+04    9.10e+05      0              
  44  2.19e-09  1.20e+04  8.38e+02  1.20e+04    8.88e+05      0   Skip BFGS  
  45  2.19e-09  1.19e+04  8.35e+02  1.19e+04    8.84e+05      0              
  46  2.19e-09  1.19e+04  8.29e+02  1.19e+04    8.65e+05      0   Skip BFGS  
  47  2.19e-09  1.18e+04  8.24e+02  1.18e+04    8.56e+05      0              
  48  2.19e-09  1.18e+04  8.47e+02  1.18e+04    9.25e+05      0   Skip BFGS  
  49  2.19e-09  1.17e+04  8.24e+02  1.17e+04    8.68e+05      0              
  50  2.19e-09  1.17e+04  8.24e+02  1.17e+04    8.77e+05      0              
  51  2.19e-09  1.17e+04  8.08e+02  1.17e+04    8.39e+05      0              
  52  2.19e-09  1.16e+04  8.02e+02  1.16e+04    8.48e+05      0              
  53  2.19e-09  1.14e+04  8.45e+02  1.14e+04    8.31e+05      0              
  54  2.19e-09  1.12e+04  9.24e+02  1.12e+04    8.10e+05      0   Skip BFGS  
  55  2.19e-09  1.12e+04  9.50e+02  1.12e+04    8.27e+05      0              
  56  2.19e-09  1.11e+04  9.37e+02  1.11e+04    8.02e+05      0              
  57  2.19e-09  1.09e+04  9.90e+02  1.09e+04    8.56e+05      0              
  58  2.19e-09  1.07e+04  1.03e+03  1.07e+04    8.51e+05      0   Skip BFGS  
  59  2.19e-09  1.07e+04  1.01e+03  1.07e+04    8.54e+05      0              
  60  2.19e-09  1.06e+04  9.74e+02  1.06e+04    7.96e+05      0   Skip BFGS  
  61  2.19e-09  1.05e+04  1.00e+03  1.05e+04    8.38e+05      0              
  62  2.19e-09  1.04e+04  1.00e+03  1.04e+04    8.52e+05      0   Skip BFGS  
  63  2.19e-09  1.03e+04  9.94e+02  1.03e+04    8.26e+05      0              
  64  2.19e-09  1.02e+04  1.00e+03  1.02e+04    8.67e+05      0              
  65  2.19e-09  9.70e+03  1.03e+03  9.70e+03    8.34e+05      0   Skip BFGS  
  66  2.19e-09  9.58e+03  1.02e+03  9.58e+03    8.08e+05      0              
  67  2.19e-09  9.48e+03  1.05e+03  9.48e+03    7.74e+05      0   Skip BFGS  
  68  2.19e-09  9.37e+03  1.03e+03  9.37e+03    7.90e+05      0              
  69  2.19e-09  9.17e+03  1.07e+03  9.17e+03    7.89e+05      0   Skip BFGS  
  70  2.19e-09  9.07e+03  1.02e+03  9.07e+03    7.71e+05      0              
  71  2.19e-09  8.97e+03  1.03e+03  8.97e+03    7.29e+05      0              
  72  2.19e-09  8.87e+03  1.06e+03  8.87e+03    7.41e+05      0   Skip BFGS  
  73  2.19e-09  8.81e+03  1.05e+03  8.81e+03    7.00e+05      0              
  74  2.19e-09  8.63e+03  9.80e+02  8.63e+03    7.37e+05      0              
  75  2.19e-09  8.54e+03  1.01e+03  8.54e+03    7.82e+05      0   Skip BFGS  
  76  2.19e-09  8.48e+03  9.74e+02  8.48e+03    7.25e+05      0              
  77  2.19e-09  8.31e+03  1.01e+03  8.31e+03    6.89e+05      0   Skip BFGS  
  78  2.19e-09  8.17e+03  9.66e+02  8.17e+03    7.11e+05      0              
  79  2.19e-09  7.55e+03  9.90e+02  7.55e+03    6.70e+05      0              
  80  2.19e-09  7.39e+03  1.05e+03  7.39e+03    6.50e+05      0   Skip BFGS  
  81  2.19e-09  7.29e+03  1.01e+03  7.29e+03    6.95e+05      0              
  82  2.19e-09  7.03e+03  1.02e+03  7.03e+03    7.56e+05      0   Skip BFGS  
  83  2.19e-09  6.91e+03  1.05e+03  6.91e+03    6.74e+05      0              
  84  2.19e-09  6.85e+03  1.05e+03  6.85e+03    6.43e+05      0   Skip BFGS  
  85  2.19e-09  6.80e+03  1.07e+03  6.80e+03    6.80e+05      0              
  86  2.19e-09  6.73e+03  1.09e+03  6.73e+03    6.55e+05      0              
  87  2.19e-09  6.65e+03  1.08e+03  6.65e+03    7.00e+05      0   Skip BFGS  
  88  2.19e-09  6.62e+03  1.09e+03  6.62e+03    6.82e+05      0              
  89  2.19e-09  6.47e+03  1.14e+03  6.47e+03    6.33e+05      0   Skip BFGS  
  90  2.19e-09  6.37e+03  1.13e+03  6.37e+03    6.80e+05      0              
  91  2.19e-09  6.21e+03  1.14e+03  6.21e+03    6.50e+05      0              
  92  2.19e-09  6.08e+03  1.22e+03  6.08e+03    6.97e+05      0   Skip BFGS  
  93  2.19e-09  6.02e+03  1.21e+03  6.02e+03    6.55e+05      0              
  94  2.19e-09  6.00e+03  1.21e+03  6.00e+03    6.65e+05      0              
  95  2.19e-09  5.99e+03  1.21e+03  5.99e+03    6.74e+05      0              
  96  2.19e-09  5.93e+03  1.24e+03  5.93e+03    6.33e+05      0   Skip BFGS  
  97  2.19e-09  5.89e+03  1.24e+03  5.89e+03    6.71e+05      0              
  98  2.19e-09  5.79e+03  1.30e+03  5.79e+03    6.49e+05      0              
  99  2.19e-09  5.76e+03  1.34e+03  5.76e+03    6.53e+05      0              
 100  2.19e-09  5.74e+03  1.35e+03  5.74e+03    6.53e+05      0              
 101  2.19e-09  5.73e+03  1.34e+03  5.73e+03    6.72e+05      0   Skip BFGS  
 102  2.19e-09  5.72e+03  1.34e+03  5.72e+03    6.60e+05      0              
 103  2.19e-09  5.71e+03  1.35e+03  5.71e+03    6.59e+05      0              
 104  2.19e-09  5.70e+03  1.35e+03  5.70e+03    6.42e+05      0              
 105  2.19e-09  5.67e+03  1.36e+03  5.67e+03    6.69e+05      0   Skip BFGS  
 106  2.19e-09  5.64e+03  1.36e+03  5.64e+03    6.70e+05      0              
 107  2.19e-09  5.64e+03  1.36e+03  5.64e+03    6.59e+05      0              
 108  2.19e-09  5.63e+03  1.36e+03  5.63e+03    6.69e+05      0              
 109  2.19e-09  5.60e+03  1.37e+03  5.60e+03    6.62e+05      0              
 110  2.19e-09  5.59e+03  1.39e+03  5.59e+03    6.61e+05      0              
 111  2.19e-09  5.59e+03  1.39e+03  5.59e+03    6.65e+05      0              
 112  2.19e-09  5.58e+03  1.40e+03  5.58e+03    6.70e+05      0   Skip BFGS  
 113  2.19e-09  5.58e+03  1.40e+03  5.58e+03    6.70e+05      0              
 114  2.19e-09  5.56e+03  1.40e+03  5.56e+03    6.96e+05      0   Skip BFGS  
 115  2.19e-09  5.54e+03  1.40e+03  5.54e+03    6.78e+05      0              
 116  2.19e-09  5.52e+03  1.38e+03  5.52e+03    6.72e+05      0   Skip BFGS  
 117  2.19e-09  5.51e+03  1.39e+03  5.51e+03    6.57e+05      0              
 118  2.19e-09  5.48e+03  1.39e+03  5.48e+03    6.35e+05      0   Skip BFGS  
 119  2.19e-09  5.46e+03  1.39e+03  5.46e+03    6.49e+05      0              
 120  2.19e-09  5.46e+03  1.38e+03  5.46e+03    6.55e+05      0              
 121  2.19e-09  5.44e+03  1.38e+03  5.44e+03    6.47e+05      0   Skip BFGS  
 122  2.19e-09  5.42e+03  1.39e+03  5.42e+03    6.49e+05      0              
 123  2.19e-09  5.40e+03  1.38e+03  5.40e+03    6.48e+05      0              
 124  2.19e-09  5.32e+03  1.37e+03  5.32e+03    6.78e+05      0   Skip BFGS  
 125  2.19e-09  5.28e+03  1.36e+03  5.28e+03    6.31e+05      0              
 126  2.19e-09  5.27e+03  1.37e+03  5.27e+03    6.34e+05      0              
 127  2.19e-09  5.25e+03  1.36e+03  5.25e+03    6.38e+05      0   Skip BFGS  
 128  2.19e-09  5.24e+03  1.37e+03  5.24e+03    6.27e+05      0              
 129  2.19e-09  5.18e+03  1.33e+03  5.18e+03    6.27e+05      0              
 130  2.19e-09  5.10e+03  1.33e+03  5.10e+03    6.21e+05      0              
 131  2.19e-09  5.08e+03  1.34e+03  5.08e+03    6.25e+05      0              
 132  2.19e-09  5.07e+03  1.33e+03  5.07e+03    6.45e+05      0              
 133  2.19e-09  5.07e+03  1.34e+03  5.07e+03    6.47e+05      0              
 134  2.19e-09  5.05e+03  1.34e+03  5.05e+03    6.38e+05      0   Skip BFGS  
 135  2.19e-09  5.04e+03  1.34e+03  5.04e+03    6.43e+05      0              
 136  2.19e-09  5.02e+03  1.34e+03  5.02e+03    6.53e+05      0              
 137  2.19e-09  5.02e+03  1.34e+03  5.02e+03    6.47e+05      0              
 138  2.19e-09  5.01e+03  1.34e+03  5.01e+03    6.50e+05      0   Skip BFGS  
 139  2.19e-09  5.01e+03  1.34e+03  5.01e+03    6.42e+05      0              
 140  2.19e-09  5.01e+03  1.34e+03  5.01e+03    6.38e+05      0   Skip BFGS  
 141  2.19e-09  5.01e+03  1.34e+03  5.01e+03    6.41e+05      0              
 142  2.19e-09  5.01e+03  1.34e+03  5.01e+03    6.45e+05      0   Skip BFGS  
 143  2.19e-09  5.01e+03  1.34e+03  5.01e+03    6.43e+05      0              
 144  2.19e-09  5.01e+03  1.34e+03  5.01e+03    6.45e+05      0              
 145  2.19e-09  5.00e+03  1.35e+03  5.00e+03    6.58e+05      0   Skip BFGS  
 146  2.19e-09  5.00e+03  1.35e+03  5.00e+03    6.47e+05      0              
 147  2.19e-09  5.00e+03  1.34e+03  5.00e+03    6.49e+05      0              
 148  2.19e-09  4.98e+03  1.35e+03  4.98e+03    6.40e+05      0   Skip BFGS  
 149  2.19e-09  4.97e+03  1.34e+03  4.97e+03    6.40e+05      0              
 150  2.19e-09  4.95e+03  1.34e+03  4.95e+03    6.44e+05      0   Skip BFGS  
 151  2.19e-09  4.94e+03  1.34e+03  4.94e+03    6.41e+05      0              
 152  2.19e-09  4.92e+03  1.36e+03  4.92e+03    6.42e+05      0              
 153  2.19e-09  4.83e+03  1.39e+03  4.83e+03    6.39e+05      0              
 154  2.19e-09  4.75e+03  1.44e+03  4.75e+03    6.59e+05      0   Skip BFGS  
 155  2.19e-09  4.72e+03  1.43e+03  4.72e+03    6.37e+05      0              
 156  2.19e-09  4.68e+03  1.44e+03  4.68e+03    6.54e+05      0   Skip BFGS  
 157  2.19e-09  4.66e+03  1.44e+03  4.66e+03    6.28e+05      0              
 158  2.19e-09  4.62e+03  1.44e+03  4.62e+03    6.53e+05      0              
 159  2.19e-09  4.53e+03  1.50e+03  4.53e+03    6.32e+05      0              
 160  2.19e-09  4.49e+03  1.54e+03  4.49e+03    6.37e+05      0   Skip BFGS  
 161  2.19e-09  4.48e+03  1.55e+03  4.48e+03    6.35e+05      0              
 162  2.19e-09  4.46e+03  1.57e+03  4.46e+03    6.50e+05      0              
 163  2.19e-09  4.44e+03  1.58e+03  4.44e+03    6.22e+05      0              
 164  2.19e-09  4.43e+03  1.55e+03  4.43e+03    6.24e+05      0   Skip BFGS  
 165  2.19e-09  4.43e+03  1.56e+03  4.43e+03    6.19e+05      0              
 166  2.19e-09  4.42e+03  1.56e+03  4.42e+03    6.27e+05      0              
 167  2.19e-09  4.41e+03  1.57e+03  4.41e+03    6.09e+05      0              
 168  2.19e-09  4.38e+03  1.60e+03  4.38e+03    5.95e+05      0   Skip BFGS  
 169  2.19e-09  4.37e+03  1.58e+03  4.37e+03    6.05e+05      0              
 170  2.19e-09  4.36e+03  1.56e+03  4.36e+03    6.01e+05      0   Skip BFGS  
 171  2.19e-09  4.36e+03  1.56e+03  4.36e+03    6.05e+05      0              
 172  2.19e-09  4.35e+03  1.58e+03  4.35e+03    6.03e+05      0              
 173  2.19e-09  4.34e+03  1.58e+03  4.34e+03    6.08e+05      0              
 174  2.19e-09  4.33e+03  1.58e+03  4.33e+03    5.99e+05      0              
 175  2.19e-09  4.33e+03  1.57e+03  4.33e+03    5.99e+05      0              
 176  2.19e-09  4.32e+03  1.57e+03  4.32e+03    5.99e+05      0   Skip BFGS  
 177  2.19e-09  4.31e+03  1.56e+03  4.31e+03    5.98e+05      0              
 178  2.19e-09  4.28e+03  1.58e+03  4.28e+03    5.94e+05      0   Skip BFGS  
 179  2.19e-09  4.28e+03  1.58e+03  4.28e+03    5.98e+05      0              
 180  2.19e-09  4.27e+03  1.59e+03  4.27e+03    5.99e+05      0   Skip BFGS  
 181  2.19e-09  4.27e+03  1.59e+03  4.27e+03    6.04e+05      0              
 182  2.19e-09  4.27e+03  1.60e+03  4.27e+03    5.99e+05      0              
 183  2.19e-09  4.26e+03  1.60e+03  4.26e+03    5.93e+05      0   Skip BFGS  
 184  2.19e-09  4.26e+03  1.60e+03  4.26e+03    5.97e+05      0              
 185  2.19e-09  4.25e+03  1.60e+03  4.25e+03    5.90e+05      0   Skip BFGS  
 186  2.19e-09  4.25e+03  1.60e+03  4.25e+03    5.91e+05      0              
 187  2.19e-09  4.25e+03  1.60e+03  4.25e+03    5.88e+05      0   Skip BFGS  
 188  2.19e-09  4.25e+03  1.61e+03  4.25e+03    5.89e+05      0              
 189  2.19e-09  4.24e+03  1.60e+03  4.24e+03    5.99e+05      0              
 190  2.19e-09  4.23e+03  1.62e+03  4.23e+03    5.92e+05      0              
 191  2.19e-09  4.23e+03  1.64e+03  4.23e+03    5.84e+05      0   Skip BFGS  
 192  2.19e-09  4.22e+03  1.63e+03  4.22e+03    5.90e+05      0              
 193  2.19e-09  4.22e+03  1.64e+03  4.22e+03    5.87e+05      0   Skip BFGS  
 194  2.19e-09  4.21e+03  1.64e+03  4.21e+03    5.94e+05      0              
 195  2.19e-09  4.20e+03  1.64e+03  4.20e+03    5.92e+05      0   Skip BFGS  
 196  2.19e-09  4.19e+03  1.65e+03  4.19e+03    5.84e+05      0              
 197  2.19e-09  4.18e+03  1.68e+03  4.18e+03    5.79e+05      0   Skip BFGS  
 198  2.19e-09  4.18e+03  1.67e+03  4.18e+03    5.83e+05      0              
 199  2.19e-09  4.17e+03  1.66e+03  4.17e+03    5.76e+05      0              
 200  2.19e-09  4.14e+03  1.71e+03  4.14e+03    5.78e+05      0   Skip BFGS  
------------------------- STOP! -------------------------
1 : |fc-fOld| = 2.6294e+01 <= tolF*(1+|f0|) = 7.1580e+04
0 : |xc-x_last| = 1.4092e+03 <= tolX*(1+|x0|) = 1.0000e-01
0 : |proj(x-g)-x|    = 5.7772e+05 <= tolG          = 1.0000e-10
0 : |proj(x-g)-x|    = 5.7772e+05 <= 1e3*eps       = 1.0000e-02
1 : maxIter   =     200    <= iter          =    200
------------------------- DONE! -------------------------

In [49]:
mrec = mrec.reshape((prob.ntau, survey.ntx), order='F')

In [ ]:


In [50]:
target.target


Out[50]:
1345.5

In [51]:
14*234


Out[51]:
3276

In [52]:
pred = prob.fields(mrec)

In [53]:
pred = pred.reshape((survey.ntime, survey.ntx), order='F')
obs = survey.dobs.reshape((survey.ntime, survey.ntx), order='F')
UNCERT = survey.uncert.reshape((survey.ntime, survey.ntx), order='F')

In [67]:
predmap, ticks, ticklabels = mapDat(pred, 1e-3, stretch=3)
obsmap, ticks, ticklabels = mapDat(obs, 1e-3, stretch=3)

In [79]:
itx = 100
fig = plt.figure(figsize=(10,3))
ax = plt.subplot(111)
for i in range(10):
    ax.plot(xyz_line[:,0], obsmap[i,:], 'k')
    ax.plot(xyz_line[:,0], predmap[i,:], 'b.')
ax.set_xlim(xyz_line[:,0].min(), xyz_line[:,0].max())
ax.set_ylim(ticks.min(), ticks.max())
ax.set_yticks(ticks)
# ax.set_ylim(0., ticks.max())

plt.plot(xyz_line[itx,0]*np.ones(2), np.r_[ticks.min(), ticks.max()],'k-', lw=2)
ax.set_xlabel("Easting (m)")
ax.set_yticklabels(ticklabels)


Out[79]:
[<matplotlib.text.Text at 0x1090f4a90>,
 <matplotlib.text.Text at 0x1090ec890>,
 <matplotlib.text.Text at 0x109285ad0>,
 <matplotlib.text.Text at 0x109291250>,
 <matplotlib.text.Text at 0x109291990>,
 <matplotlib.text.Text at 0x10929b110>,
 <matplotlib.text.Text at 0x10929b850>,
 <matplotlib.text.Text at 0x10929bf90>]

In [80]:
figsize(10, 3)
# for itau in range(9,11,1):
itau = 12
plt.plot(xyz_line[:,0], mrec[itau,:], 'k.')
xlim(xyz_line[:,0].min(), xyz_line[:,0].max()) 
# ylim(1e-1, 1e5)


Out[80]:
(432987.40000000002, 435648.90000000002)

In [81]:
# for itime in range(time.size):
#     plt.semilogy(xyz_line[:,0], obs[itime,:], 'k-')
#     plt.semilogy(xyz_line[:,0], pred[itime,:], 'b-')
# plt.plot(xyz_line[itx,0]*np.ones(2), np.r_[1e-8, 1e1],'k-', lw=2)
# ylim(1e-6, 2e0)
# xlim(xyz_line[:,0].min(), xyz_line[:,0].max())

In [82]:
figsize(6,5)
plt.loglog(time, pred[:,itx], 'b-')
plt.loglog(time, obs[:,itx], 'k.-')
plt.loglog(time, -obs[:,itx], 'k--')
plt.loglog(time, -(obs[:,itx]-pred[:,itx]), 'r--')
plt.loglog(time, UNCERT[:,itx], 'g-')
ylim(1e-5, 1e1)


Out[82]:
(1e-05, 10.0)

In [78]:
# for itx in range(survey.ntx):
#     plt.semilogx(prob.tau, mrec[:,itx], '.')

In [63]:
hist(np.log10(tau), bins=30)


Out[63]:
(array([ 3.,  3.,  3.,  2.,  3.,  3.,  2.,  3.,  2.,  3.,  3.,  2.,  3.,
         3.,  2.,  3.,  3.,  2.,  3.,  3.,  2.,  3.,  3.,  2.,  3.,  3.,
         3.,  2.,  3.,  3.]),
 array([-5. , -4.9, -4.8, -4.7, -4.6, -4.5, -4.4, -4.3, -4.2, -4.1, -4. ,
        -3.9, -3.8, -3.7, -3.6, -3.5, -3.4, -3.3, -3.2, -3.1, -3. , -2.9,
        -2.8, -2.7, -2.6, -2.5, -2.4, -2.3, -2.2, -2.1, -2. ]),
 <a list of 30 Patch objects>)

In [ ]:


In [ ]:


In [64]:
# mfund = mrec.copy()
# mip = mrec.copy()
# mfund[mfund<0.] = 0.
# mip[mip>0.] = 0.
# fund = np.dot(A, mfund)

In [65]:
ip = obs-invProb.dpred


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-65-c484051f467c> in <module>()
----> 1 ip = obs-invProb.dpred

ValueError: operands could not be broadcast together with shapes (23,117) (2691,) 

In [66]:
tind = 7
print obs[tind], invProb.dpred[tind], ip[tind]


[ 0.443857  0.443953  0.443771  0.443109  0.442074  0.4411    0.440456
  0.440027  0.439647  0.439574  0.440582  0.44333   0.447609  0.4526
  0.457863  0.463608  0.470069  0.477098  0.484418  0.491948  0.499463
  0.50613   0.511071  0.514366  0.516805  0.518723  0.519728  0.519205
  0.516242  0.509467  0.498179  0.483926  0.470083  0.459212  0.451047
  0.443332  0.434166  0.423259  0.411439  0.399583  0.388087  0.376913
  0.365832  0.35472   0.343813  0.333573  0.324197  0.315442  0.306914
  0.298298  0.289477  0.280716  0.272475  0.264778  0.257113  0.249027
  0.240477  0.231677  0.222961  0.214638  0.206721  0.198995  0.191415
  0.184149  0.177286  0.170866  0.16504   0.159818  0.154926  0.150205
  0.145789  0.141676  0.13752   0.133101  0.128707  0.12483   0.1216
  0.118721  0.115893  0.113036  0.11012   0.107077  0.10389   0.100616
  0.097336  0.094159  0.091193  0.088457  0.085905  0.083534  0.08141
  0.079615  0.078201  0.077048  0.075826  0.074347  0.072866  0.071735
  0.070898  0.070028  0.068983  0.067868  0.066782  0.06574   0.06472
  0.063696  0.062657  0.06164   0.060692  0.05981   0.058946  0.058071
  0.05719   0.056302  0.055389  0.054478  0.053651  0.052956  0.052331
  0.051668  0.050928  0.050165  0.049444  0.04876   0.048063  0.047371
  0.046791  0.046377  0.04606   0.045743  0.045401  0.045053  0.044703
  0.044329  0.043911  0.04344   0.042909  0.042385  0.04203   0.041908
  0.041813  0.041462  0.040826  0.04008   0.039347  0.038667  0.038089
  0.037647  0.037311  0.037039  0.036823  0.03665   0.036503  0.036371
  0.036257  0.036156  0.03604   0.035874  0.035655  0.0354    0.035085
  0.034663  0.034143  0.033591  0.033041  0.03249   0.031976  0.031592
  0.031368  0.031232  0.031108  0.030987  0.030884  0.030806  0.030755
  0.030716  0.030673  0.030629  0.030603  0.030593  0.030576  0.030541
  0.030503  0.030439  0.030286  0.030013  0.029647  0.0292    0.028669
  0.02816   0.027878  0.027885  0.027994  0.028012  0.027916  0.027722
  0.027409  0.027008  0.026646  0.026438  0.026399  0.02644   0.026429
  0.026301  0.026096  0.025895  0.025704  0.025441  0.025101  0.024844
  0.024797  0.024895  0.025016  0.025114  0.025161  0.025146  0.025145
  0.025239  0.02538   0.025438  0.025347  0.025152  0.024967  0.024897
  0.024939  0.02498   0.024936  0.024813  0.024656  0.024495  0.024342
  0.024188  0.024017  0.023831  0.023656  0.023528  0.023452  0.023392
  0.023314  0.023212  0.023058  0.022779  0.022389  0.02209   0.022084
  0.022306  0.022463  0.022357  0.022058  0.021772  0.021608  0.021526
  0.021432  0.021274  0.021058  0.020836  0.020699  0.020704  0.020804
  0.020883  0.02088   0.020822  0.020758  0.020698  0.02064   0.020583
  0.020514  0.0204    0.020236  0.020061  0.019908  0.019762  0.019585
  0.019383  0.019193  0.01903   0.018878  0.018734  0.018587  0.018341
  0.017926  0.017487  0.017265  0.017283  0.017357  0.017355] 0.410446161815
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-66-72c5091fc602> in <module>()
      1 tind = 7
----> 2 print obs[tind], invProb.dpred[tind], ip[tind]

NameError: name 'ip' is not defined

In [72]:
fig = plt.figure(figsize=(7,4.5))
ax = plt.subplot(111)
ax.plot(time, obs, 'k.-', lw=2)
# ax.set_ylim(1e-4, 1e0)
ax.set_xscale('linear')
ax.set_yscale('linear')
ax.set_xlim(time.min(), time.max())
ax.grid(True)



In [73]:
fig = plt.figure(figsize=(7,4.5))
ax = plt.subplot(111)
ax.plot(time, obs, 'k.-', lw=2)
ax.plot(time, -obs, 'k--', lw=2)
ax.plot(time, invProb.dpred, 'b-', lw=2)
ax.plot(time, -ip, 'r.-', lw=2, ms=10)
ax.plot(time, uncert, 'g.-', lw=2, ms=10)
ax.set_ylim(1e-4, 1e0)
ax.set_xscale('log')
ax.set_yscale('log')
ax.set_xlim(time.min(), time.max())
ax.grid(True)



In [74]:
predmap, ticks, tickLabels = mapDat(invProb.dpred,1e-3, stretch=3)

In [75]:
fig = plt.figure(figsize=(5,4))
ax = plt.subplot(111)

# for i, ind in enumerate(inds):
#     temp, dum, dum = mapDat(mtrue[inds][i]*np.exp(-time/tau[ind]), 1e-5, stretch=2)
#     plt.semilogx(time, temp, 'k', alpha = 0.5)    
outmap, ticks, tickLabels = mapDat(obs,1e-3, stretch=3)    
ax.plot(time*1e6, outmap, 'k', lw=2)
ax.plot(time*1e6, predmap, 'b', lw=2)
ax.plot(time[7:]*1e6, outmap[7:]-predmap[7:], 'r', lw=2)
ax.plot(np.r_[-0.002, 0.]*1e6, np.zeros(2), 'k', lw=2)
ax.plot(np.zeros(2), np.r_[ticks.min(), ticks.max()], 'k--', lw=1)
ax.set_yticks(ticks)
ax.set_yticklabels(tickLabels)
ax.set_ylim(ticks.min(), ticks.max())
ax.plot(np.r_[-0.002, time.max()]*1e6, np.zeros(2), 'k--')
ax.set_xlim(-0.002*1e6, time.max()*1e6)

ax.set_xlabel("Time (micro-s)", fontsize = 16)
ax.set_ylabel("$db_z/dt (pV/A$-$m^4)$ ", fontsize = 16)

# ax.grid(True)


Out[75]:
<matplotlib.text.Text at 0x10b208310>

In [76]:
weight_d = np.sqrt(np.diag(np.dot(np.dot(np.diag(1./uncert), A), (np.dot(np.diag(1./uncert), A)).T)))
# weight_d = np.sqrt(np.diag( np.dot(A, A.T)))
plt.semilogx(time, weight_d)


Out[76]:
[<matplotlib.lines.Line2D at 0x10b0b7b90>]

In [ ]: