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


Populating the interactive namespace from numpy and matplotlib
WARNING: pylab import has clobbered these variables: ['linalg', 'beta', 'inv']
`%matplotlib` prevents importing * from pylab and numpy

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

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

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

In [109]:
DAT = milligan['DAT']
Header = milligan['header']
tindst = 0
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[tindst:]*1e-6
obsdata = DAT[:,13:13+27]
xyz = np.c_[DAT[:,0], DAT[:,1], DAT[:,3]]
line = milligan['Line']

In [110]:
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 [111]:
obs_line = obsdata[indline,tindst:][::10,:]
xyz_line = xyz[indline,:][::10,:]

In [112]:
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 [113]:
Regularization.BaseRegularization


Out[113]:
SimPEG.Regularization.BaseRegularization

In [ ]:


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

In [115]:
Gx.todense()


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

Simple exponential basis

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

In [116]:
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 [117]:
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 [118]:
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 [119]:
# 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[119]:
(-4.5, 4.5)

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

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

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


Out[123]:
[<matplotlib.lines.Line2D at 0x10c703990>]

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


Out[124]:
(0.0, 0.015600000000000003)

In [125]:
P.shape


Out[125]:
(27, 1561)

In [126]:
# 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 [210]:
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.1, floor=1e-4)

In [211]:
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 [212]:
from SimPEG import Maps

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


Out[214]:
[<matplotlib.lines.Line2D at 0x10e439210>]

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


(3159,)
(3159,)

In [216]:
from SimPEG.Regularization import BaseRegularization as BaseRegularization
class SmoothAEMRegularization(BaseRegularization):    
    xyz_line = None
    ntau = 81
    alpha_s = 1e0
    alpha_x = 1e-2
    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 [217]:
meshline = Mesh.TensorMesh([survey.ntx])

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


Out[218]:
9558

In [219]:
# 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 [232]:
# 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, maxIterLS = 40)
# 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 and solverOpts as the problem***
=============================== Projected GNCG ===============================
  #     beta     phi_d     phi_m       f      |proj(x-g)-x|  LS    Comment   
-----------------------------------------------------------------------------
   0  3.46e-08  1.03e+05  4.79e-16  1.03e+05    2.09e+06      0              
   1  3.46e-08  9.64e+04  1.75e-02  9.64e+04    2.29e+05      0              
   2  3.46e-08  8.25e+04  1.26e-01  8.25e+04    7.64e+04      0   Skip BFGS  
   3  3.46e-08  5.83e+04  4.67e-01  5.83e+04    4.26e+04      0   Skip BFGS  
   4  3.46e-08  3.77e+04  1.70e+00  3.77e+04    1.95e+05      0   Skip BFGS  
   5  3.46e-08  2.16e+04  4.80e+00  2.16e+04    2.98e+05      0   Skip BFGS  
   6  3.46e-08  1.39e+04  7.04e+00  1.39e+04    4.14e+05      0   Skip BFGS  
   7  3.46e-08  1.14e+04  8.74e+00  1.14e+04    3.67e+05      0              
   8  3.46e-08  7.33e+03  1.89e+01  7.33e+03    1.66e+05      0              
   9  3.46e-08  5.54e+03  2.01e+01  5.54e+03    2.04e+05      0              
  10  3.46e-08  4.79e+03  2.63e+01  4.79e+03    1.41e+05      0              
  11  3.46e-08  4.39e+03  3.01e+01  4.39e+03    1.68e+05      0              
  12  3.46e-08  4.23e+03  3.04e+01  4.23e+03    1.64e+05      0              
  13  3.46e-08  3.97e+03  3.35e+01  3.97e+03    1.80e+05      0              
  14  3.46e-08  3.78e+03  3.46e+01  3.78e+03    1.77e+05      0              
  15  3.46e-08  3.68e+03  3.63e+01  3.68e+03    1.81e+05      0              
  16  3.46e-08  3.63e+03  3.61e+01  3.63e+03    1.84e+05      0              
  17  3.46e-08  3.53e+03  3.90e+01  3.53e+03    1.78e+05      0              
  18  3.46e-08  3.37e+03  3.86e+01  3.37e+03    1.84e+05      0   Skip BFGS  
  19  3.46e-08  3.33e+03  3.73e+01  3.33e+03    1.90e+05      0              
  20  3.46e-08  3.26e+03  3.77e+01  3.26e+03    1.76e+05      0   Skip BFGS  
  21  3.46e-08  3.23e+03  3.84e+01  3.23e+03    1.78e+05      0              
  22  3.46e-08  3.22e+03  3.83e+01  3.22e+03    1.81e+05      0   Skip BFGS  
  23  3.46e-08  3.22e+03  3.83e+01  3.22e+03    1.78e+05      0              
  24  3.46e-08  3.20e+03  3.86e+01  3.20e+03    1.65e+05      0   Skip BFGS  
  25  3.46e-08  3.18e+03  3.87e+01  3.18e+03    1.70e+05      0              
  26  3.46e-08  3.06e+03  3.79e+01  3.06e+03    1.62e+05      0              
  27  3.46e-08  2.93e+03  3.97e+01  2.93e+03    1.63e+05      0              
  28  3.46e-08  2.88e+03  4.09e+01  2.88e+03    1.43e+05      0              
  29  3.46e-08  2.76e+03  4.30e+01  2.76e+03    1.29e+05      0   Skip BFGS  
  30  3.46e-08  2.75e+03  4.26e+01  2.75e+03    1.34e+05      0              
  31  3.46e-08  2.74e+03  4.28e+01  2.74e+03    1.39e+05      0              
  32  3.46e-08  2.73e+03  4.37e+01  2.73e+03    1.40e+05      0   Skip BFGS  
  33  3.46e-08  2.72e+03  4.33e+01  2.72e+03    1.40e+05      0              
  34  3.46e-08  2.70e+03  4.41e+01  2.70e+03    1.57e+05      0              
  35  3.46e-08  2.69e+03  4.56e+01  2.69e+03    1.59e+05      0   Skip BFGS  
  36  3.46e-08  2.68e+03  4.47e+01  2.68e+03    1.60e+05      0              
  37  3.46e-08  2.62e+03  4.47e+01  2.62e+03    1.89e+05      0              
  38  3.46e-08  2.57e+03  4.54e+01  2.57e+03    1.91e+05      0              
  39  3.46e-08  2.53e+03  4.54e+01  2.53e+03    1.96e+05      0   Skip BFGS  
  40  3.46e-08  2.50e+03  4.49e+01  2.50e+03    1.74e+05      0              
  41  3.46e-08  2.48e+03  4.54e+01  2.48e+03    1.65e+05      0   Skip BFGS  
  42  3.46e-08  2.47e+03  4.56e+01  2.47e+03    1.75e+05      0              
  43  3.46e-08  2.43e+03  4.47e+01  2.43e+03    1.94e+05      0              
  44  3.46e-08  2.42e+03  4.44e+01  2.42e+03    1.85e+05      0   Skip BFGS  
  45  3.46e-08  2.41e+03  4.47e+01  2.41e+03    1.92e+05      0              
  46  3.46e-08  2.40e+03  4.52e+01  2.40e+03    1.99e+05      0              
  47  3.46e-08  2.36e+03  4.57e+01  2.36e+03    1.81e+05      0   Skip BFGS  
  48  3.46e-08  2.34e+03  4.53e+01  2.34e+03    1.88e+05      0              
  49  3.46e-08  2.33e+03  4.58e+01  2.33e+03    2.00e+05      0   Skip BFGS  
  50  3.46e-08  2.32e+03  4.57e+01  2.32e+03    1.86e+05      0              
  51  3.46e-08  2.30e+03  4.66e+01  2.30e+03    1.74e+05      0   Skip BFGS  
  52  3.46e-08  2.29e+03  4.64e+01  2.29e+03    1.82e+05      0              
  53  3.46e-08  2.28e+03  4.74e+01  2.28e+03    1.70e+05      0              
  54  3.46e-08  2.28e+03  4.79e+01  2.28e+03    1.69e+05      0   Skip BFGS  
  55  3.46e-08  2.27e+03  4.77e+01  2.27e+03    1.71e+05      0              
  56  3.46e-08  2.25e+03  4.81e+01  2.25e+03    1.80e+05      0              
  57  3.46e-08  2.18e+03  5.12e+01  2.18e+03    1.78e+05      0              
  58  3.46e-08  2.14e+03  5.10e+01  2.14e+03    2.11e+05      0   Skip BFGS  
  59  3.46e-08  2.12e+03  5.19e+01  2.12e+03    1.95e+05      0              
  60  3.46e-08  2.07e+03  5.22e+01  2.07e+03    1.66e+05      0   Skip BFGS  
  61  3.46e-08  2.05e+03  5.28e+01  2.05e+03    1.79e+05      0              
  62  3.46e-08  1.97e+03  5.52e+01  1.97e+03    2.02e+05      0              
  63  3.46e-08  1.92e+03  5.47e+01  1.92e+03    2.15e+05      0   Skip BFGS  
  64  3.46e-08  1.90e+03  5.65e+01  1.90e+03    1.99e+05      0              
  65  3.46e-08  1.87e+03  5.64e+01  1.87e+03    2.08e+05      0              
  66  3.46e-08  1.85e+03  5.56e+01  1.85e+03    2.15e+05      0              
  67  3.46e-08  1.83e+03  5.77e+01  1.83e+03    2.14e+05      0              
  68  3.46e-08  1.82e+03  5.68e+01  1.82e+03    2.13e+05      0              
  69  3.46e-08  1.80e+03  5.61e+01  1.80e+03    2.07e+05      0   Skip BFGS  
  70  3.46e-08  1.78e+03  5.68e+01  1.78e+03    2.02e+05      0              
  71  3.46e-08  1.77e+03  5.61e+01  1.77e+03    1.97e+05      0   Skip BFGS  
  72  3.46e-08  1.76e+03  5.60e+01  1.76e+03    1.97e+05      0              
  73  3.46e-08  1.76e+03  5.57e+01  1.76e+03    1.98e+05      0              
  74  3.46e-08  1.75e+03  5.55e+01  1.75e+03    1.94e+05      0   Skip BFGS  
  75  3.46e-08  1.75e+03  5.58e+01  1.75e+03    1.97e+05      0              
  76  3.46e-08  1.75e+03  5.56e+01  1.75e+03    1.98e+05      0              
  77  3.46e-08  1.74e+03  5.55e+01  1.74e+03    2.05e+05      0   Skip BFGS  
  78  3.46e-08  1.74e+03  5.57e+01  1.74e+03    1.98e+05      0              
  79  3.46e-08  1.73e+03  5.57e+01  1.73e+03    2.09e+05      0              
  80  3.46e-08  1.71e+03  5.61e+01  1.71e+03    2.23e+05      0   Skip BFGS  
  81  3.46e-08  1.69e+03  5.63e+01  1.69e+03    2.05e+05      0              
  82  3.46e-08  1.69e+03  5.63e+01  1.69e+03    2.05e+05      0   Skip BFGS  
  83  3.46e-08  1.69e+03  5.62e+01  1.69e+03    2.08e+05      0              
  84  3.46e-08  1.60e+03  5.74e+01  1.60e+03    2.07e+05      0   Skip BFGS  
  85  3.46e-08  1.58e+03  5.76e+01  1.58e+03    2.04e+05      0              
------------------------- STOP! -------------------------
1 : |fc-fOld| = 0.0000e+00 <= tolF*(1+|f0|) = 1.0328e+04
0 : |xc-x_last| = 5.7509e+03 <= tolX*(1+|x0|) = 1.0000e-01
0 : |proj(x-g)-x|    = 2.0420e+05 <= tolG          = 1.0000e-10
0 : |proj(x-g)-x|    = 2.0420e+05 <= 1e3*eps       = 1.0000e-02
0 : maxIter   =     200    <= iter          =     86
------------------------- DONE! -------------------------

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

In [ ]:


In [234]:
target.target


Out[234]:
1579.5

In [235]:
14*234


Out[235]:
3276

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

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

In [239]:
itx = 80
fig = plt.figure(figsize=(10,3))
ax = plt.subplot(111)
for i in range(20):
    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[239]:
[<matplotlib.text.Text at 0x10e5e9090>,
 <matplotlib.text.Text at 0x10e543310>,
 <matplotlib.text.Text at 0x10e5c06d0>,
 <matplotlib.text.Text at 0x109fc7bd0>,
 <matplotlib.text.Text at 0x109f7e750>,
 <matplotlib.text.Text at 0x10e50b3d0>,
 <matplotlib.text.Text at 0x10e502dd0>,
 <matplotlib.text.Text at 0x10e502fd0>]

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


Out[240]:
(432987.40000000002, 435648.90000000002)

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

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

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


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

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


[  7.60604000e-01   7.26329000e-01   6.80340000e-01   6.24583000e-01
   5.48354000e-01   4.68402000e-01   3.92005000e-01   3.34371000e-01
   2.97125000e-01   2.69030000e-01   2.45893000e-01   2.24842000e-01
   2.07039000e-01   1.91000000e-01   1.74821000e-01   1.58980000e-01
   1.43608000e-01   1.28770000e-01   1.15012000e-01   1.01858000e-01
   9.01520000e-02   8.10460000e-02   7.47230000e-02   6.96800000e-02
   6.53180000e-02   6.20010000e-02   5.89470000e-02   5.60200000e-02
   5.45900000e-02   5.31310000e-02   5.12580000e-02   4.95650000e-02
   4.78640000e-02   4.59500000e-02   4.42770000e-02   4.27680000e-02
   4.19300000e-02   4.07070000e-02   3.88250000e-02   3.67210000e-02
   3.42300000e-02   3.15160000e-02   2.94770000e-02   2.73120000e-02
   2.59510000e-02   2.57160000e-02   2.58880000e-02   2.68680000e-02
   2.90590000e-02   3.15140000e-02   3.39410000e-02   3.57290000e-02
   3.72280000e-02   3.89600000e-02   4.06790000e-02   4.16540000e-02
   4.25370000e-02   4.36090000e-02   4.48920000e-02   4.59300000e-02
   4.65240000e-02   4.67220000e-02   4.72410000e-02   4.81350000e-02
   4.87050000e-02   4.92500000e-02   4.96300000e-02   4.92060000e-02
   4.80210000e-02   4.57970000e-02   4.38700000e-02   4.20450000e-02
   3.92430000e-02   3.65530000e-02   3.08800000e-02   2.31610000e-02
   1.43300000e-02   3.67800000e-03   6.68000000e-04   4.38100000e-03
   1.08510000e-02   1.72890000e-02   2.36760000e-02   2.99920000e-02
   3.60090000e-02   4.13130000e-02   4.66560000e-02   5.21970000e-02
   5.60430000e-02   5.88940000e-02   6.08740000e-02   6.19800000e-02
   6.29150000e-02   6.38310000e-02   6.46280000e-02   6.56800000e-02
   6.68940000e-02   6.70220000e-02   6.71450000e-02   6.76990000e-02
   6.78280000e-02   6.75790000e-02   6.69410000e-02   6.64090000e-02
   6.59030000e-02   6.49310000e-02   6.35600000e-02   6.22320000e-02
   6.15300000e-02   6.14200000e-02   6.17140000e-02   6.13560000e-02
   6.08940000e-02   6.00550000e-02   5.87760000e-02   5.78440000e-02
   5.78060000e-02] 0.730382074188
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-58-72c5091fc602> in <module>()
      1 tind = 7
----> 2 print obs[tind], invProb.dpred[tind], ip[tind]

NameError: name 'ip' is not defined

In [59]:
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 [60]:
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)


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-60-4595e27ac989> in <module>()
      3 ax.plot(time, obs, 'k.-', lw=2)
      4 ax.plot(time, -obs, 'k--', lw=2)
----> 5 ax.plot(time, invProb.dpred, 'b-', lw=2)
      6 ax.plot(time, -ip, 'r.-', lw=2, ms=10)
      7 ax.plot(time, uncert, 'g.-', lw=2, ms=10)

/Users/sgkang/anaconda/lib/python2.7/site-packages/matplotlib/axes/_axes.pyc in plot(self, *args, **kwargs)
   1371         lines = []
   1372 
-> 1373         for line in self._get_lines(*args, **kwargs):
   1374             self.add_line(line)
   1375             lines.append(line)

/Users/sgkang/anaconda/lib/python2.7/site-packages/matplotlib/axes/_base.pyc in _grab_next_args(self, *args, **kwargs)
    302                 return
    303             if len(remaining) <= 3:
--> 304                 for seg in self._plot_args(remaining, kwargs):
    305                     yield seg
    306                 return

/Users/sgkang/anaconda/lib/python2.7/site-packages/matplotlib/axes/_base.pyc in _plot_args(self, tup, kwargs)
    280             x = np.arange(y.shape[0], dtype=float)
    281 
--> 282         x, y = self._xy_from_xy(x, y)
    283 
    284         if self.command == 'plot':

/Users/sgkang/anaconda/lib/python2.7/site-packages/matplotlib/axes/_base.pyc in _xy_from_xy(self, x, y)
    221         y = np.atleast_1d(y)
    222         if x.shape[0] != y.shape[0]:
--> 223             raise ValueError("x and y must have same first dimension")
    224         if x.ndim > 2 or y.ndim > 2:
    225             raise ValueError("x and y can be no greater than 2-D")

ValueError: x and y must have same first dimension

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

In [62]:
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)


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-62-add5da45daaa> in <module>()
      7 outmap, ticks, tickLabels = mapDat(obs,1e-3, stretch=3)
      8 ax.plot(time*1e6, outmap, 'k', lw=2)
----> 9 ax.plot(time*1e6, predmap, 'b', lw=2)
     10 ax.plot(time[7:]*1e6, outmap[7:]-predmap[7:], 'r', lw=2)
     11 ax.plot(np.r_[-0.002, 0.]*1e6, np.zeros(2), 'k', lw=2)

/Users/sgkang/anaconda/lib/python2.7/site-packages/matplotlib/axes/_axes.pyc in plot(self, *args, **kwargs)
   1371         lines = []
   1372 
-> 1373         for line in self._get_lines(*args, **kwargs):
   1374             self.add_line(line)
   1375             lines.append(line)

/Users/sgkang/anaconda/lib/python2.7/site-packages/matplotlib/axes/_base.pyc in _grab_next_args(self, *args, **kwargs)
    302                 return
    303             if len(remaining) <= 3:
--> 304                 for seg in self._plot_args(remaining, kwargs):
    305                     yield seg
    306                 return

/Users/sgkang/anaconda/lib/python2.7/site-packages/matplotlib/axes/_base.pyc in _plot_args(self, tup, kwargs)
    280             x = np.arange(y.shape[0], dtype=float)
    281 
--> 282         x, y = self._xy_from_xy(x, y)
    283 
    284         if self.command == 'plot':

/Users/sgkang/anaconda/lib/python2.7/site-packages/matplotlib/axes/_base.pyc in _xy_from_xy(self, x, y)
    221         y = np.atleast_1d(y)
    222         if x.shape[0] != y.shape[0]:
--> 223             raise ValueError("x and y must have same first dimension")
    224         if x.ndim > 2 or y.ndim > 2:
    225             raise ValueError("x and y can be no greater than 2-D")

ValueError: x and y must have same first dimension

In [63]:
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)


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-63-918d8466d9a4> in <module>()
----> 1 weight_d = np.sqrt(np.diag(np.dot(np.dot(np.diag(1./uncert), A), (np.dot(np.diag(1./uncert), A)).T)))
      2 # weight_d = np.sqrt(np.diag( np.dot(A, A.T)))
      3 plt.semilogx(time, weight_d)

NameError: name 'A' is not defined

In [ ]:


In [ ]: