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 = 10
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.')


600

In [ ]:


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

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.05, 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)

Simple exponential basis

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

In [9]:
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 [10]:
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 [11]:
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 [12]:
# 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[12]:
(-4.5, 4.5)

In [13]:
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[13]:
(0, 1.0)

In [14]:
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 [15]:
temp = np.exp(-time_conv/1e-2)/1e-2
out = CausalConv(temp, currentderiv, time_conv)
# plt.plot(time_conv, currentderiv)

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


Out[16]:
[<matplotlib.lines.Line2D at 0x10a34f310>]

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


Out[17]:
(0.0, 0.015600000000000003)

In [18]:
P.shape


Out[18]:
(23, 1561)

In [19]:
# 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 [20]:
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 [21]:
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 [22]:
from SimPEG import Maps

In [23]:
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 [24]:
plt.semilogx(prob.tau, weightone)


Out[24]:
[<matplotlib.lines.Line2D at 0x10a4d1950>]

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


(67896,)
(67896,)

In [26]:
survey.nD


Out[26]:
67896

In [27]:
reg = Regularization.BaseRegularization(meshreg, mapping=wmap)
# reg = Regularization.BaseRegularization(meshreg)
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.75e-05  1.88e+07  6.52e-15  1.88e+07    8.17e+07      0              
   1  2.75e-05  1.31e+07  1.01e-01  1.31e+07    2.25e+07      0              
   2  2.75e-05  1.02e+07  6.00e-01  1.02e+07    1.06e+07      0   Skip BFGS  
   3  2.75e-05  7.99e+06  7.74e-01  7.99e+06    9.34e+06      0              
   4  2.75e-05  5.78e+06  4.13e+00  5.78e+06    2.48e+06      0              
   5  2.75e-05  4.02e+06  4.59e+00  4.02e+06    6.23e+06      0              
   6  2.75e-05  3.46e+06  5.71e+00  3.46e+06    4.84e+06      0              
   7  2.75e-05  2.59e+06  1.19e+01  2.59e+06    3.55e+06      0   Skip BFGS  
   8  2.75e-05  2.09e+06  1.31e+01  2.09e+06    1.25e+07      0              
   9  2.75e-05  1.98e+06  1.35e+01  1.98e+06    1.09e+07      0              
  10  2.75e-05  1.80e+06  1.55e+01  1.80e+06    1.50e+07      0              
  11  2.75e-05  1.56e+06  2.10e+01  1.56e+06    1.44e+07      0   Skip BFGS  
  12  2.75e-05  1.48e+06  1.93e+01  1.48e+06    1.25e+07      0              
  13  2.75e-05  1.32e+06  2.41e+01  1.32e+06    1.34e+07      0              
  14  2.75e-05  1.23e+06  2.29e+01  1.23e+06    1.33e+07      0              
  15  2.75e-05  1.16e+06  2.66e+01  1.16e+06    1.11e+07      0              
  16  2.75e-05  1.07e+06  2.86e+01  1.07e+06    1.06e+07      0              
  17  2.75e-05  1.06e+06  2.76e+01  1.06e+06    9.93e+06      0   Skip BFGS  
  18  2.75e-05  1.05e+06  2.86e+01  1.05e+06    1.04e+07      0              
  19  2.75e-05  9.27e+05  2.95e+01  9.27e+05    1.07e+07      0              
  20  2.75e-05  8.68e+05  3.27e+01  8.68e+05    8.07e+06      0   Skip BFGS  
  21  2.75e-05  8.40e+05  3.08e+01  8.40e+05    9.69e+06      0              
  22  2.75e-05  7.56e+05  3.63e+01  7.56e+05    8.11e+06      0              
  23  2.75e-05  7.39e+05  3.53e+01  7.39e+05    7.85e+06      0   Skip BFGS  
  24  2.75e-05  7.28e+05  3.71e+01  7.28e+05    7.69e+06      0              
  25  2.75e-05  7.00e+05  3.58e+01  7.00e+05    9.12e+06      0   Skip BFGS  
  26  2.75e-05  6.80e+05  3.77e+01  6.80e+05    7.19e+06      0              
  27  2.75e-05  6.18e+05  4.13e+01  6.18e+05    6.58e+06      0   Skip BFGS  
  28  2.75e-05  5.97e+05  3.95e+01  5.97e+05    6.74e+06      0              
  29  2.75e-05  5.81e+05  4.06e+01  5.81e+05    6.63e+06      0              
  30  2.75e-05  5.75e+05  4.11e+01  5.75e+05    6.36e+06      0   Skip BFGS  
  31  2.75e-05  5.71e+05  4.07e+01  5.71e+05    6.59e+06      0              
  32  2.75e-05  5.66e+05  4.04e+01  5.66e+05    7.41e+06      0   Skip BFGS  
  33  2.75e-05  5.63e+05  4.04e+01  5.63e+05    6.85e+06      0              
  34  2.75e-05  5.06e+05  4.54e+01  5.06e+05    7.62e+06      0   Skip BFGS  
  35  2.75e-05  4.74e+05  4.48e+01  4.74e+05    6.36e+06      0              
  36  2.75e-05  4.55e+05  4.62e+01  4.55e+05    6.16e+06      0              
  37  2.75e-05  4.45e+05  4.56e+01  4.45e+05    7.12e+06      0   Skip BFGS  
  38  2.75e-05  4.39e+05  4.64e+01  4.39e+05    5.91e+06      0              
  39  2.75e-05  4.31e+05  4.58e+01  4.31e+05    6.29e+06      0              
  40  2.75e-05  4.14e+05  4.74e+01  4.14e+05    7.29e+06      0   Skip BFGS  
  41  2.75e-05  4.04e+05  4.73e+01  4.04e+05    6.09e+06      0              
  42  2.75e-05  3.98e+05  4.60e+01  3.98e+05    6.42e+06      0              
  43  2.75e-05  3.90e+05  4.57e+01  3.90e+05    6.49e+06      0   Skip BFGS  
  44  2.75e-05  3.85e+05  4.61e+01  3.85e+05    6.23e+06      0              
  45  2.75e-05  3.77e+05  4.60e+01  3.77e+05    6.28e+06      0              
  46  2.75e-05  3.60e+05  4.70e+01  3.60e+05    7.26e+06      0   Skip BFGS  
  47  2.75e-05  3.49e+05  4.77e+01  3.49e+05    6.19e+06      0              
  48  2.75e-05  3.04e+05  5.30e+01  3.04e+05    6.73e+06      0              
  49  2.75e-05  2.79e+05  5.71e+01  2.79e+05    5.44e+06      0              
  50  2.75e-05  2.75e+05  5.66e+01  2.75e+05    5.73e+06      0   Skip BFGS  
  51  2.75e-05  2.73e+05  5.74e+01  2.73e+05    5.37e+06      0              
  52  2.75e-05  2.59e+05  6.01e+01  2.59e+05    5.69e+06      0              
  53  2.75e-05  2.55e+05  6.03e+01  2.55e+05    5.74e+06      0   Skip BFGS  
  54  2.75e-05  2.53e+05  6.04e+01  2.53e+05    5.53e+06      0              
  55  2.75e-05  2.49e+05  6.22e+01  2.49e+05    5.29e+06      0              
  56  2.75e-05  2.43e+05  6.18e+01  2.43e+05    5.56e+06      0   Skip BFGS  
  57  2.75e-05  2.40e+05  6.26e+01  2.40e+05    5.26e+06      0              
  58  2.75e-05  2.38e+05  6.33e+01  2.38e+05    5.05e+06      0              
  59  2.75e-05  2.36e+05  6.51e+01  2.36e+05    5.13e+06      0   Skip BFGS  
  60  2.75e-05  2.35e+05  6.37e+01  2.35e+05    5.02e+06      0              
  61  2.75e-05  2.29e+05  6.47e+01  2.29e+05    5.42e+06      0   Skip BFGS  
  62  2.75e-05  2.26e+05  6.49e+01  2.26e+05    5.31e+06      0              
  63  2.75e-05  2.25e+05  6.51e+01  2.25e+05    5.25e+06      0   Skip BFGS  
  64  2.75e-05  2.23e+05  6.49e+01  2.23e+05    5.24e+06      0              
  65  2.75e-05  2.18e+05  6.63e+01  2.18e+05    5.46e+06      0              
  66  2.75e-05  2.14e+05  6.58e+01  2.14e+05    5.76e+06      0   Skip BFGS  
  67  2.75e-05  2.12e+05  6.71e+01  2.12e+05    5.33e+06      0              
  68  2.75e-05  2.07e+05  7.05e+01  2.07e+05    5.19e+06      0   Skip BFGS  
  69  2.75e-05  2.04e+05  6.93e+01  2.04e+05    5.28e+06      0              
  70  2.75e-05  2.02e+05  7.05e+01  2.02e+05    5.50e+06      0              
  71  2.75e-05  1.98e+05  7.11e+01  1.98e+05    5.34e+06      0              
  72  2.75e-05  1.96e+05  7.06e+01  1.96e+05    5.34e+06      0   Skip BFGS  
  73  2.75e-05  1.95e+05  7.10e+01  1.95e+05    5.29e+06      0              
  74  2.75e-05  1.91e+05  7.29e+01  1.91e+05    5.74e+06      0   Skip BFGS  
  75  2.75e-05  1.89e+05  7.12e+01  1.89e+05    5.33e+06      0              
  76  2.75e-05  1.81e+05  7.17e+01  1.81e+05    5.55e+06      0   Skip BFGS  
  77  2.75e-05  1.76e+05  7.39e+01  1.76e+05    5.40e+06      0              
  78  2.75e-05  1.72e+05  7.44e+01  1.72e+05    5.24e+06      0              
  79  2.75e-05  1.60e+05  7.82e+01  1.60e+05    5.37e+06      0   Skip BFGS  
  80  2.75e-05  1.55e+05  7.78e+01  1.55e+05    5.18e+06      0              
  81  2.75e-05  1.53e+05  7.99e+01  1.53e+05    5.15e+06      0              
  82  2.75e-05  1.51e+05  8.00e+01  1.51e+05    5.19e+06      0   Skip BFGS  
  83  2.75e-05  1.51e+05  8.04e+01  1.51e+05    5.14e+06      0              
  84  2.75e-05  1.48e+05  8.14e+01  1.48e+05    5.17e+06      0              
  85  2.75e-05  1.46e+05  8.25e+01  1.46e+05    5.15e+06      0   Skip BFGS  
  86  2.75e-05  1.45e+05  8.27e+01  1.45e+05    5.12e+06      0              
  87  2.75e-05  1.43e+05  8.30e+01  1.43e+05    5.12e+06      0   Skip BFGS  
  88  2.75e-05  1.42e+05  8.35e+01  1.42e+05    5.06e+06      0              
  89  2.75e-05  1.41e+05  8.31e+01  1.41e+05    5.20e+06      0   Skip BFGS  
  90  2.75e-05  1.40e+05  8.35e+01  1.40e+05    5.10e+06      0              
  91  2.75e-05  1.36e+05  8.58e+01  1.36e+05    5.13e+06      0   Skip BFGS  
  92  2.75e-05  1.35e+05  8.54e+01  1.35e+05    5.14e+06      0              
  93  2.75e-05  1.34e+05  8.48e+01  1.34e+05    5.22e+06      0   Skip BFGS  
  94  2.75e-05  1.33e+05  8.51e+01  1.33e+05    5.11e+06      0              
  95  2.75e-05  1.32e+05  8.39e+01  1.32e+05    5.23e+06      0   Skip BFGS  
  96  2.75e-05  1.31e+05  8.46e+01  1.31e+05    5.12e+06      0              
  97  2.75e-05  1.28e+05  8.37e+01  1.28e+05    5.33e+06      0              
  98  2.75e-05  1.25e+05  8.42e+01  1.25e+05    5.46e+06      0   Skip BFGS  
  99  2.75e-05  1.23e+05  8.40e+01  1.23e+05    5.28e+06      0              
 100  2.75e-05  1.16e+05  8.58e+01  1.16e+05    4.98e+06      0              
 101  2.75e-05  1.14e+05  8.64e+01  1.14e+05    4.91e+06      0   Skip BFGS  
 102  2.75e-05  1.14e+05  8.63e+01  1.14e+05    4.88e+06      0              
 103  2.75e-05  1.09e+05  8.77e+01  1.09e+05    4.95e+06      0   Skip BFGS  
 104  2.75e-05  1.07e+05  8.76e+01  1.07e+05    4.80e+06      0              
 105  2.75e-05  1.06e+05  8.71e+01  1.06e+05    4.93e+06      0              
 106  2.75e-05  1.03e+05  8.84e+01  1.03e+05    5.12e+06      0   Skip BFGS  
 107  2.75e-05  1.02e+05  8.81e+01  1.02e+05    4.88e+06      0              
 108  2.75e-05  9.88e+04  9.02e+01  9.88e+04    4.77e+06      0              
 109  2.75e-05  9.67e+04  9.10e+01  9.67e+04    4.77e+06      0              
 110  2.75e-05  9.65e+04  9.08e+01  9.65e+04    4.79e+06      0   Skip BFGS  
 111  2.75e-05  9.63e+04  9.10e+01  9.63e+04    4.75e+06      0              
 112  2.75e-05  9.57e+04  9.13e+01  9.57e+04    4.78e+06      0   Skip BFGS  
 113  2.75e-05  9.53e+04  9.10e+01  9.53e+04    4.75e+06      0              
 114  2.75e-05  9.50e+04  9.09e+01  9.50e+04    4.80e+06      0   Skip BFGS  
 115  2.75e-05  9.48e+04  9.11e+01  9.48e+04    4.76e+06      0              
 116  2.75e-05  9.42e+04  9.18e+01  9.42e+04    4.78e+06      0   Skip BFGS  
 117  2.75e-05  9.37e+04  9.13e+01  9.37e+04    4.77e+06      0              
 118  2.75e-05  9.28e+04  9.12e+01  9.28e+04    4.79e+06      0   Skip BFGS  
 119  2.75e-05  9.24e+04  9.18e+01  9.24e+04    4.74e+06      0              
 120  2.75e-05  9.19e+04  9.17e+01  9.19e+04    4.81e+06      0   Skip BFGS  
 121  2.75e-05  9.16e+04  9.17e+01  9.16e+04    4.76e+06      0              
 122  2.75e-05  9.12e+04  9.20e+01  9.12e+04    4.78e+06      0              
 123  2.75e-05  9.04e+04  9.19e+01  9.04e+04    4.89e+06      0   Skip BFGS  
 124  2.75e-05  8.99e+04  9.20e+01  8.99e+04    4.83e+06      0              
 125  2.75e-05  8.94e+04  9.21e+01  8.94e+04    4.83e+06      0              
 126  2.75e-05  8.76e+04  9.32e+01  8.76e+04    4.81e+06      0              
 127  2.75e-05  8.46e+04  9.32e+01  8.46e+04    4.90e+06      0   Skip BFGS  
 128  2.75e-05  8.35e+04  9.36e+01  8.35e+04    4.83e+06      0              
 129  2.75e-05  8.21e+04  9.48e+01  8.21e+04    4.83e+06      0   Skip BFGS  
 130  2.75e-05  8.12e+04  9.39e+01  8.12e+04    4.88e+06      0              
 131  2.75e-05  8.04e+04  9.40e+01  8.04e+04    4.83e+06      0   Skip BFGS  
 132  2.75e-05  8.00e+04  9.38e+01  8.00e+04    4.85e+06      0              
 133  2.75e-05  7.90e+04  9.37e+01  7.90e+04    4.91e+06      0              
 134  2.75e-05  7.86e+04  9.40e+01  7.86e+04    4.85e+06      0              
 135  2.75e-05  7.75e+04  9.37e+01  7.75e+04    4.80e+06      0   Skip BFGS  
 136  2.75e-05  7.69e+04  9.42e+01  7.69e+04    4.74e+06      0              
 137  2.75e-05  7.65e+04  9.38e+01  7.65e+04    4.78e+06      0              
 138  2.75e-05  7.60e+04  9.42e+01  7.60e+04    4.74e+06      0              
 139  2.75e-05  7.60e+04  9.41e+01  7.60e+04    4.74e+06      0   Skip BFGS  
 140  2.75e-05  7.60e+04  9.42e+01  7.60e+04    4.74e+06      0              
 141  2.75e-05  7.56e+04  9.45e+01  7.56e+04    4.73e+06      0   Skip BFGS  
 142  2.75e-05  7.52e+04  9.44e+01  7.52e+04    4.75e+06      0              
 143  2.75e-05  7.49e+04  9.40e+01  7.49e+04    4.81e+06      0   Skip BFGS  
 144  2.75e-05  7.47e+04  9.42e+01  7.47e+04    4.75e+06      0              
 145  2.75e-05  7.43e+04  9.43e+01  7.43e+04    4.79e+06      0              
 146  2.75e-05  7.38e+04  9.40e+01  7.38e+04    4.82e+06      0   Skip BFGS  
 147  2.75e-05  7.35e+04  9.44e+01  7.35e+04    4.76e+06      0              
 148  2.75e-05  7.33e+04  9.46e+01  7.33e+04    4.71e+06      0              
 149  2.75e-05  7.31e+04  9.43e+01  7.31e+04    4.73e+06      0              
 150  2.75e-05  7.25e+04  9.43e+01  7.25e+04    4.72e+06      0   Skip BFGS  
 151  2.75e-05  7.22e+04  9.47e+01  7.22e+04    4.66e+06      0              
 152  2.75e-05  7.21e+04  9.49e+01  7.21e+04    4.65e+06      0   Skip BFGS  
 153  2.75e-05  7.20e+04  9.47e+01  7.20e+04    4.65e+06      0              
 154  2.75e-05  7.17e+04  9.44e+01  7.17e+04    4.69e+06      0   Skip BFGS  
 155  2.75e-05  7.15e+04  9.46e+01  7.15e+04    4.64e+06      0              
 156  2.75e-05  7.12e+04  9.46e+01  7.12e+04    4.65e+06      0              
 157  2.75e-05  7.09e+04  9.48e+01  7.09e+04    4.66e+06      0   Skip BFGS  
 158  2.75e-05  7.07e+04  9.47e+01  7.07e+04    4.66e+06      0              
 159  2.75e-05  7.05e+04  9.52e+01  7.05e+04    4.61e+06      0              
 160  2.75e-05  7.02e+04  9.52e+01  7.02e+04    4.60e+06      0              
 161  2.75e-05  6.98e+04  9.51e+01  6.98e+04    4.62e+06      0   Skip BFGS  
 162  2.75e-05  6.96e+04  9.53e+01  6.96e+04    4.60e+06      0              
 163  2.75e-05  6.93e+04  9.52e+01  6.93e+04    4.64e+06      0              
 164  2.75e-05  6.89e+04  9.53e+01  6.89e+04    4.72e+06      0   Skip BFGS  
 165  2.75e-05  6.85e+04  9.53e+01  6.85e+04    4.66e+06      0              
 166  2.75e-05  6.71e+04  9.61e+01  6.71e+04    4.79e+06      0   Skip BFGS  
 167  2.75e-05  6.64e+04  9.60e+01  6.64e+04    4.75e+06      0              
 168  2.75e-05  6.61e+04  9.64e+01  6.61e+04    4.70e+06      0              
 169  2.75e-05  6.58e+04  9.63e+01  6.58e+04    4.75e+06      0   Skip BFGS  
 170  2.75e-05  6.56e+04  9.65e+01  6.56e+04    4.72e+06      0              
 171  2.75e-05  6.55e+04  9.65e+01  6.55e+04    4.71e+06      0   Skip BFGS  
 172  2.75e-05  6.54e+04  9.66e+01  6.54e+04    4.71e+06      0              
 173  2.75e-05  6.50e+04  9.75e+01  6.50e+04    4.73e+06      0   Skip BFGS  
 174  2.75e-05  6.48e+04  9.72e+01  6.48e+04    4.72e+06      0              
 175  2.75e-05  6.46e+04  9.71e+01  6.46e+04    4.73e+06      0   Skip BFGS  
 176  2.75e-05  6.45e+04  9.73e+01  6.45e+04    4.72e+06      0              
 177  2.75e-05  6.31e+04  9.76e+01  6.31e+04    4.86e+06      0              
 178  2.75e-05  6.21e+04  9.87e+01  6.21e+04    4.79e+06      0   Skip BFGS  
 179  2.75e-05  6.17e+04  9.87e+01  6.17e+04    4.80e+06      0              
 180  2.75e-05  6.12e+04  9.95e+01  6.12e+04    4.77e+06      0   Skip BFGS  
 181  2.75e-05  6.08e+04  9.98e+01  6.08e+04    4.75e+06      0              
 182  2.75e-05  6.01e+04  1.00e+02  6.01e+04    4.76e+06      0              
 183  2.75e-05  5.96e+04  1.01e+02  5.96e+04    4.74e+06      0   Skip BFGS  
 184  2.75e-05  5.93e+04  1.01e+02  5.93e+04    4.71e+06      0              
 185  2.75e-05  5.87e+04  1.02e+02  5.87e+04    4.67e+06      0              
 186  2.75e-05  5.85e+04  1.02e+02  5.85e+04    4.66e+06      0              
 187  2.75e-05  5.80e+04  1.02e+02  5.80e+04    4.67e+06      0   Skip BFGS  
 188  2.75e-05  5.78e+04  1.03e+02  5.78e+04    4.64e+06      0              
 189  2.75e-05  5.76e+04  1.03e+02  5.76e+04    4.64e+06      0   Skip BFGS  
 190  2.75e-05  5.75e+04  1.03e+02  5.75e+04    4.63e+06      0              
 191  2.75e-05  5.73e+04  1.03e+02  5.73e+04    4.64e+06      0              
 192  2.75e-05  5.72e+04  1.03e+02  5.72e+04    4.68e+06      0              
 193  2.75e-05  5.72e+04  1.03e+02  5.72e+04    4.68e+06      0              
 194  2.75e-05  5.71e+04  1.03e+02  5.71e+04    4.67e+06      0   Skip BFGS  
 195  2.75e-05  5.70e+04  1.03e+02  5.70e+04    4.67e+06      0              
 196  2.75e-05  5.69e+04  1.03e+02  5.69e+04    4.67e+06      0   Skip BFGS  
 197  2.75e-05  5.68e+04  1.03e+02  5.68e+04    4.66e+06      0              
 198  2.75e-05  5.67e+04  1.03e+02  5.67e+04    4.63e+06      0   Skip BFGS  
 199  2.75e-05  5.66e+04  1.03e+02  5.66e+04    4.64e+06      0              
 200  2.75e-05  5.64e+04  1.03e+02  5.64e+04    4.66e+06      0              
------------------------- STOP! -------------------------
1 : |fc-fOld| = 1.3627e+02 <= tolF*(1+|f0|) = 1.8763e+06
0 : |xc-x_last| = 4.5692e+05 <= tolX*(1+|x0|) = 1.0000e-01
0 : |proj(x-g)-x|    = 4.6596e+06 <= tolG          = 1.0000e-10
0 : |proj(x-g)-x|    = 4.6596e+06 <= 1e3*eps       = 1.0000e-02
1 : maxIter   =     200    <= iter          =    200
------------------------- DONE! -------------------------

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

In [38]:
survey.nD


Out[38]:
67896

In [39]:
target.target


Out[39]:
33948.0

In [31]:
14*234


Out[31]:
3276

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

In [33]:
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 [34]:
predmap, ticks, ticklabels = mapDat(pred, 1e-4, stretch=3)
obsmap, ticks, ticklabels = mapDat(obs, 1e-4, stretch=3)

In [35]:
itx = 150
fig = plt.figure(figsize=(10,3))
ax = plt.subplot(111)
for i in range(23):
    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)
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[35]:
[<matplotlib.text.Text at 0x10ca5e550>,
 <matplotlib.text.Text at 0x10a304810>,
 <matplotlib.text.Text at 0x10a0f0850>,
 <matplotlib.text.Text at 0x10a0f0b10>,
 <matplotlib.text.Text at 0x10a0d4a90>,
 <matplotlib.text.Text at 0x10a0d4d50>,
 <matplotlib.text.Text at 0x10a07dcd0>,
 <matplotlib.text.Text at 0x10a07d290>,
 <matplotlib.text.Text at 0x10a04f510>,
 <matplotlib.text.Text at 0x10a04fb10>]

In [37]:
figsize(10, 3)
for itau in range(9,41,1):
    plt.semilogy(xyz_line[:,0], mrec[itau,:], 'k.')
xlim(xyz_line[:,0].min(), xyz_line[:,0].max()) 
ylim(1e-1, 1e5)


Out[37]:
(0.1, 100000.0)

In [40]:
# 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 [41]:
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[41]:
(1e-05, 10.0)

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

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


Out[50]:
(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 [51]:
# mfund = mrec.copy()
# mip = mrec.copy()
# mfund[mfund<0.] = 0.
# mip[mip>0.] = 0.
# fund = np.dot(A, mfund)

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


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

ValueError: operands could not be broadcast together with shapes (23,170) (3910,) 

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 [ ]: