mirror of
https://github.com/wassname/simpeg.git
synced 2026-07-15 11:26:09 +08:00
524 KiB
524 KiB
In [5]:
from SimPEG import *
from simpegPF import BaseMag
from scipy.constants import mu_0
from simpegPF.MagAnalytics import spheremodel, CongruousMagBC
from simpegPF.Magnetics import MagneticsDiffSecondary, MagneticsDiffSecondaryInv
# import SeogiUtils as SeUtils
# import simpegEM.Utils.Solver.Mumps as Mumps
%pylab inlinePopulating the interactive namespace from numpy and matplotlib
WARNING: pylab import has clobbered these variables: ['linalg'] `%matplotlib` prevents importing * from pylab and numpy
In [5]:
cs = 25.
hxind = [(cs,5,-1.3), (cs, 31),(cs,5,1.3)]
hyind = [(cs,5,-1.3), (cs, 31),(cs,5,1.3)]
hzind = [(cs,5,-1.3), (cs, 30),(cs,5,1.3)]
mesh = Mesh.TensorMesh([hxind, hyind, hzind], 'CCC')In [6]:
chibkg = 1e-5
chiblk = 0.1
chi = np.ones(mesh.nC)*chibkg
sph_ind = spheremodel(mesh, 0., 0., -150., 80)
chi[sph_ind] = chiblk
active = mesh.gridCC[:,2]<0
actMap = Maps.ActiveCells(mesh, active, chibkg)
dweight = np.ones(mesh.nC)
dweight[active] = (1/abs(mesh.gridCC[active, 2]-13.)**1.5)
baseMap = BaseMag.BaseMagMap(mesh)
depthMap = BaseMag.WeightMap(mesh, dweight)
dmap = baseMap*actMap
rmap = depthMap*actMap
model = (chi)[active]In [12]:
sph_ind_ini = spheremodel(mesh, 0., 0., -200., 150)In [8]:
chi_ini = np.ones_like(chi)*chibkg
chi_ini[sph_ind_ini] = chiblk*0.1In [15]:
fig, ax = plt.subplots(1,1, figsize = (5, 5))
dat1 = mesh.plotSlice(chi, ax = ax, normal = 'X')
plt.colorbar(dat1[0], orientation="horizontal", ax = ax)
ax.set_ylim(-500, 0)Out [15]:
(-500, 0)
In [16]:
print model.shape
print chi.shape(33620L,) (67240L,)
In [17]:
survey = BaseMag.BaseMagSurvey()
const = 20
Inc = 90.
Dec = 0.
Btot = 51000
survey.setBackgroundField(Inc, Dec, Btot)
In [ ]:
xr = np.linspace(-300, 300, 81)
yr = np.linspace(-300, 300, 81)
X, Y = np.meshgrid(xr, yr)
Z = np.ones((xr.size, yr.size))*(0.)
rxLoc = np.c_[Utils.mkvc(X), Utils.mkvc(Y), Utils.mkvc(Z)]
survey.rxLoc = rxLoc
prob = MagneticsDiffSecondary(mesh, mapping = dmap)
prob.pair(survey)
prob.Solver = Utils.SolverUtils.SolverWrapD(Mumps, factorize=True)In [7]:
dsyn = survey.dpred(model)In [8]:
survey.dtrue = Utils.mkvc(dsyn)
std = 0.05
noise = std*abs(survey.dtrue)*np.random.randn(*survey.dtrue.shape)
survey.dobs = survey.dtrue+noise
survey.std = survey.dobs*0 + stdIn [9]:
fig, ax = plt.subplots(1,2, figsize = (8,5) )
dat = ax[0].imshow(np.reshape(noise, (xr.size, yr.size), order='F'), extent=[min(xr), max(xr), min(yr), max(yr)])
plt.colorbar(dat, ax = ax[0], orientation="horizontal")
dat2 = ax[1].imshow(np.reshape(survey.dobs, (xr.size, yr.size), order='F'), extent=[min(xr), max(xr), min(yr), max(yr)])
plt.colorbar(dat2, ax = ax[1], orientation="horizontal")
plt.show()In [36]:
# m0 = (1e-5*np.ones(mesh.nC))[active]
m0 = chi_ini[active]/dweight[active]
dmisfit = DataMisfit.l2_DataMisfit(survey)
valmin = abs(survey.dobs).max()
dmisfit.Wd = 1/(np.ones(survey.dobs.size)*valmin)In [37]:
d_ini = survey.dpred(m0)
fig, ax = plt.subplots(1,2, figsize = (8,5) )
dat1 = ax[0].imshow(np.reshape(d_ini, (xr.size, yr.size), order='F'), extent=[min(xr), max(xr), min(yr), max(yr)])
vmin = d_ini.min()
vmax = d_ini.max()
plt.colorbar(dat1, ax = ax[0], orientation="horizontal", ticks=[np.linspace(vmin, vmax, 3)], format = FormatStrFormatter('$%5.5f$'))
dat2 = ax[1].imshow(np.reshape(survey.dobs, (xr.size, yr.size), order='F'), extent=[min(xr), max(xr), min(yr), max(yr)])
vmin = survey.dobs.min()
vmax = survey.dobs.max()
plt.colorbar(dat2, ax = ax[1], orientation="horizontal", ticks=[np.linspace(vmin, vmax, 5)])
plt.show()In [40]:
reg = Regularization.Tikhonov(mesh, mapping = rmap)
opt = Optimization.ProjectedGNCG(maxIter = 30)
opt.lower = 1e-10
opt.maxIterLS = 50
invProb = InvProblem.BaseInvProblem(dmisfit, reg, opt)
beta = Directives.BetaSchedule(coolingFactor=8, coolingRate=2)
betaest = Directives.BetaEstimate_ByEig(beta0_ratio=10**0)
inv = Inversion.BaseInversion(invProb, directiveList=[beta,betaest])
opt.tolG = 1e-20
opt.eps = 1e-20
reg.alpha_s = 1e-9
reg.alpha_x = 1.
reg.alpha_y = 1.
reg.alpha_z = 1.
prob.counter = opt.counter = Utils.Counter()
opt.LSshorten = 0.1
opt.remember('xc')In [41]:
mopt = inv.run(m0)SimPEG.InvProblem will set Regularization.mref to 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 -8.78e+04 1.08e+06 2.70e-01 1.06e+06 1.38e+05 0
1 -8.78e+04 3.89e+05 1.52e+09 -1.34e+14 1.57e+08 0
2 -1.10e+04 2.49e+05 1.52e+09 -1.67e+13 1.96e+07 15 Skip BFGS
3 -1.10e+04 2.49e+05 1.52e+09 -1.67e+13 1.96e+07 19 Skip BFGS
4 -1.37e+03 2.49e+05 1.52e+09 -2.09e+12 2.45e+06 19 Skip BFGS
[1;31m---------------------------------------------------------------------------[0m [1;31mKeyboardInterrupt[0m Traceback (most recent call last) [1;32m<ipython-input-41-e70b86582598>[0m in [0;36m<module>[1;34m()[0m [1;32m----> 1[1;33m [0mmopt[0m [1;33m=[0m [0minv[0m[1;33m.[0m[0mrun[0m[1;33m([0m[0mm0[0m[1;33m)[0m[1;33m[0m[0m [0m [1;32m/home/seogi/Documents/simpeg/SimPEG/Utils/CounterUtils.pyc[0m in [0;36mwrapper[1;34m(self, *args, **kwargs)[0m [0;32m 90[0m [0mcounter[0m [1;33m=[0m [0mgetattr[0m[1;33m([0m[0mself[0m[1;33m,[0m[1;34m'counter'[0m[1;33m,[0m[0mNone[0m[1;33m)[0m[1;33m[0m[0m [0;32m 91[0m [1;32mif[0m [0mtype[0m[1;33m([0m[0mcounter[0m[1;33m)[0m [1;32mis[0m [0mCounter[0m[1;33m:[0m [0mcounter[0m[1;33m.[0m[0mcountTic[0m[1;33m([0m[0mself[0m[1;33m.[0m[0m__class__[0m[1;33m.[0m[0m__name__[0m[1;33m+[0m[1;34m'.'[0m[1;33m+[0m[0mf[0m[1;33m.[0m[0m__name__[0m[1;33m)[0m[1;33m[0m[0m [1;32m---> 92[1;33m [0mout[0m [1;33m=[0m [0mf[0m[1;33m([0m[0mself[0m[1;33m,[0m[1;33m*[0m[0margs[0m[1;33m,[0m[1;33m**[0m[0mkwargs[0m[1;33m)[0m[1;33m[0m[0m [0m[0;32m 93[0m [1;32mif[0m [0mtype[0m[1;33m([0m[0mcounter[0m[1;33m)[0m [1;32mis[0m [0mCounter[0m[1;33m:[0m [0mcounter[0m[1;33m.[0m[0mcountToc[0m[1;33m([0m[0mself[0m[1;33m.[0m[0m__class__[0m[1;33m.[0m[0m__name__[0m[1;33m+[0m[1;34m'.'[0m[1;33m+[0m[0mf[0m[1;33m.[0m[0m__name__[0m[1;33m)[0m[1;33m[0m[0m [0;32m 94[0m [1;32mreturn[0m [0mout[0m[1;33m[0m[0m [1;32m/home/seogi/Documents/simpeg/SimPEG/Inversion.pyc[0m in [0;36mrun[1;34m(self, m0)[0m [0;32m 60[0m [0mself[0m[1;33m.[0m[0minvProb[0m[1;33m.[0m[0mstartup[0m[1;33m([0m[0mm0[0m[1;33m)[0m[1;33m[0m[0m [0;32m 61[0m [0mself[0m[1;33m.[0m[0mdirectiveList[0m[1;33m.[0m[0mcall[0m[1;33m([0m[1;34m'initialize'[0m[1;33m)[0m[1;33m[0m[0m [1;32m---> 62[1;33m [0mself[0m[1;33m.[0m[0mm[0m [1;33m=[0m [0mself[0m[1;33m.[0m[0mopt[0m[1;33m.[0m[0mminimize[0m[1;33m([0m[0mself[0m[1;33m.[0m[0minvProb[0m[1;33m.[0m[0mevalFunction[0m[1;33m,[0m [0mself[0m[1;33m.[0m[0minvProb[0m[1;33m.[0m[0mcurModel[0m[1;33m)[0m[1;33m[0m[0m [0m[0;32m 63[0m [0mself[0m[1;33m.[0m[0mdirectiveList[0m[1;33m.[0m[0mcall[0m[1;33m([0m[1;34m'finish'[0m[1;33m)[0m[1;33m[0m[0m [0;32m 64[0m [1;33m[0m[0m [1;32m/home/seogi/Documents/simpeg/SimPEG/Utils/CounterUtils.pyc[0m in [0;36mwrapper[1;34m(self, *args, **kwargs)[0m [0;32m 90[0m [0mcounter[0m [1;33m=[0m [0mgetattr[0m[1;33m([0m[0mself[0m[1;33m,[0m[1;34m'counter'[0m[1;33m,[0m[0mNone[0m[1;33m)[0m[1;33m[0m[0m [0;32m 91[0m [1;32mif[0m [0mtype[0m[1;33m([0m[0mcounter[0m[1;33m)[0m [1;32mis[0m [0mCounter[0m[1;33m:[0m [0mcounter[0m[1;33m.[0m[0mcountTic[0m[1;33m([0m[0mself[0m[1;33m.[0m[0m__class__[0m[1;33m.[0m[0m__name__[0m[1;33m+[0m[1;34m'.'[0m[1;33m+[0m[0mf[0m[1;33m.[0m[0m__name__[0m[1;33m)[0m[1;33m[0m[0m [1;32m---> 92[1;33m [0mout[0m [1;33m=[0m [0mf[0m[1;33m([0m[0mself[0m[1;33m,[0m[1;33m*[0m[0margs[0m[1;33m,[0m[1;33m**[0m[0mkwargs[0m[1;33m)[0m[1;33m[0m[0m [0m[0;32m 93[0m [1;32mif[0m [0mtype[0m[1;33m([0m[0mcounter[0m[1;33m)[0m [1;32mis[0m [0mCounter[0m[1;33m:[0m [0mcounter[0m[1;33m.[0m[0mcountToc[0m[1;33m([0m[0mself[0m[1;33m.[0m[0m__class__[0m[1;33m.[0m[0m__name__[0m[1;33m+[0m[1;34m'.'[0m[1;33m+[0m[0mf[0m[1;33m.[0m[0m__name__[0m[1;33m)[0m[1;33m[0m[0m [0;32m 94[0m [1;32mreturn[0m [0mout[0m[1;33m[0m[0m [1;32m/home/seogi/Documents/simpeg/SimPEG/Optimization.pyc[0m in [0;36mminimize[1;34m(self, evalFunction, x0)[0m [0;32m 179[0m [0mself[0m[1;33m.[0m[0mprintIter[0m[1;33m([0m[1;33m)[0m[1;33m[0m[0m [0;32m 180[0m [1;32mif[0m [0mself[0m[1;33m.[0m[0mstoppingCriteria[0m[1;33m([0m[1;33m)[0m[1;33m:[0m [1;32mbreak[0m[1;33m[0m[0m [1;32m--> 181[1;33m [0mself[0m[1;33m.[0m[0msearchDirection[0m [1;33m=[0m [0mself[0m[1;33m.[0m[0mfindSearchDirection[0m[1;33m([0m[1;33m)[0m[1;33m[0m[0m [0m[0;32m 182[0m [1;32mdel[0m [0mself[0m[1;33m.[0m[0mH[0m [1;31m#: Doing this saves memory, as it is not needed in the rest of the computations.[0m[1;33m[0m[0m [0;32m 183[0m [0mp[0m [1;33m=[0m [0mself[0m[1;33m.[0m[0mscaleSearchDirection[0m[1;33m([0m[0mself[0m[1;33m.[0m[0msearchDirection[0m[1;33m)[0m[1;33m[0m[0m [1;32m/home/seogi/Documents/simpeg/SimPEG/Utils/CounterUtils.pyc[0m in [0;36mwrapper[1;34m(self, *args, **kwargs)[0m [0;32m 90[0m [0mcounter[0m [1;33m=[0m [0mgetattr[0m[1;33m([0m[0mself[0m[1;33m,[0m[1;34m'counter'[0m[1;33m,[0m[0mNone[0m[1;33m)[0m[1;33m[0m[0m [0;32m 91[0m [1;32mif[0m [0mtype[0m[1;33m([0m[0mcounter[0m[1;33m)[0m [1;32mis[0m [0mCounter[0m[1;33m:[0m [0mcounter[0m[1;33m.[0m[0mcountTic[0m[1;33m([0m[0mself[0m[1;33m.[0m[0m__class__[0m[1;33m.[0m[0m__name__[0m[1;33m+[0m[1;34m'.'[0m[1;33m+[0m[0mf[0m[1;33m.[0m[0m__name__[0m[1;33m)[0m[1;33m[0m[0m [1;32m---> 92[1;33m [0mout[0m [1;33m=[0m [0mf[0m[1;33m([0m[0mself[0m[1;33m,[0m[1;33m*[0m[0margs[0m[1;33m,[0m[1;33m**[0m[0mkwargs[0m[1;33m)[0m[1;33m[0m[0m [0m[0;32m 93[0m [1;32mif[0m [0mtype[0m[1;33m([0m[0mcounter[0m[1;33m)[0m [1;32mis[0m [0mCounter[0m[1;33m:[0m [0mcounter[0m[1;33m.[0m[0mcountToc[0m[1;33m([0m[0mself[0m[1;33m.[0m[0m__class__[0m[1;33m.[0m[0m__name__[0m[1;33m+[0m[1;34m'.'[0m[1;33m+[0m[0mf[0m[1;33m.[0m[0m__name__[0m[1;33m)[0m[1;33m[0m[0m [0;32m 94[0m [1;32mreturn[0m [0mout[0m[1;33m[0m[0m [1;32m/home/seogi/Documents/simpeg/SimPEG/Optimization.pyc[0m in [0;36mfindSearchDirection[1;34m(self)[0m [0;32m 974[0m [1;33m[0m[0m [0;32m 975[0m [1;31m# Form product Hessian*pc.[0m[1;33m[0m[1;33m[0m[0m [1;32m--> 976[1;33m [0mHp[0m [1;33m=[0m [0mself[0m[1;33m.[0m[0mH[0m[1;33m*[0m[0mpc[0m[1;33m[0m[0m [0m[0;32m 977[0m [0mHp[0m [1;33m=[0m [1;33m([0m[1;36m1[0m[1;33m-[0m[0mActive[0m[1;33m)[0m[1;33m*[0m[0mHp[0m[1;33m[0m[0m [0;32m 978[0m [1;33m[0m[0m [1;32m/usr/local/lib/python2.7/dist-packages/scipy/sparse/linalg/interface.pyc[0m in [0;36m__mul__[1;34m(self, x)[0m [0;32m 201[0m [1;33m[0m[0m [0;32m 202[0m [1;32mif[0m [0mx[0m[1;33m.[0m[0mndim[0m [1;33m==[0m [1;36m1[0m [1;32mor[0m [0mx[0m[1;33m.[0m[0mndim[0m [1;33m==[0m [1;36m2[0m [1;32mand[0m [0mx[0m[1;33m.[0m[0mshape[0m[1;33m[[0m[1;36m1[0m[1;33m][0m [1;33m==[0m [1;36m1[0m[1;33m:[0m[1;33m[0m[0m [1;32m--> 203[1;33m [1;32mreturn[0m [0mself[0m[1;33m.[0m[0mmatvec[0m[1;33m([0m[0mx[0m[1;33m)[0m[1;33m[0m[0m [0m[0;32m 204[0m [1;32melif[0m [0mx[0m[1;33m.[0m[0mndim[0m [1;33m==[0m [1;36m2[0m[1;33m:[0m[1;33m[0m[0m [0;32m 205[0m [1;32mreturn[0m [0mself[0m[1;33m.[0m[0mmatmat[0m[1;33m([0m[0mx[0m[1;33m)[0m[1;33m[0m[0m [1;32m/usr/local/lib/python2.7/dist-packages/scipy/sparse/linalg/interface.pyc[0m in [0;36mmatvec[1;34m(self, x)[0m [0;32m 132[0m [1;32mraise[0m [0mValueError[0m[1;33m([0m[1;34m'dimension mismatch'[0m[1;33m)[0m[1;33m[0m[0m [0;32m 133[0m [1;33m[0m[0m [1;32m--> 134[1;33m [0my[0m [1;33m=[0m [0mself[0m[1;33m.[0m[0m_matvec[0m[1;33m([0m[0mx[0m[1;33m)[0m[1;33m[0m[0m [0m[0;32m 135[0m [1;33m[0m[0m [0;32m 136[0m [1;32mif[0m [0misinstance[0m[1;33m([0m[0mx[0m[1;33m,[0m [0mnp[0m[1;33m.[0m[0mmatrix[0m[1;33m)[0m[1;33m:[0m[1;33m[0m[0m [1;32m/home/seogi/Documents/simpeg/SimPEG/InvProblem.pyc[0m in [0;36mH_fun[1;34m(v)[0m [0;32m 132[0m [1;32mif[0m [0mreturn_H[0m[1;33m:[0m[1;33m[0m[0m [0;32m 133[0m [1;32mdef[0m [0mH_fun[0m[1;33m([0m[0mv[0m[1;33m)[0m[1;33m:[0m[1;33m[0m[0m [1;32m--> 134[1;33m [0mphi_d2Deriv[0m [1;33m=[0m [0mself[0m[1;33m.[0m[0mdmisfit[0m[1;33m.[0m[0meval2Deriv[0m[1;33m([0m[0mm[0m[1;33m,[0m [0mv[0m[1;33m,[0m [0mu[0m[1;33m=[0m[0mu[0m[1;33m)[0m[1;33m[0m[0m [0m[0;32m 135[0m [0mphi_m2Deriv[0m [1;33m=[0m [0mself[0m[1;33m.[0m[0mreg[0m[1;33m.[0m[0meval2Deriv[0m[1;33m([0m[0mm[0m[1;33m,[0m [0mv[0m[1;33m=[0m[0mv[0m[1;33m)[0m[1;33m[0m[0m [0;32m 136[0m [1;33m[0m[0m [1;32m/home/seogi/Documents/simpeg/SimPEG/Utils/CounterUtils.pyc[0m in [0;36mwrapper[1;34m(self, *args, **kwargs)[0m [0;32m 90[0m [0mcounter[0m [1;33m=[0m [0mgetattr[0m[1;33m([0m[0mself[0m[1;33m,[0m[1;34m'counter'[0m[1;33m,[0m[0mNone[0m[1;33m)[0m[1;33m[0m[0m [0;32m 91[0m [1;32mif[0m [0mtype[0m[1;33m([0m[0mcounter[0m[1;33m)[0m [1;32mis[0m [0mCounter[0m[1;33m:[0m [0mcounter[0m[1;33m.[0m[0mcountTic[0m[1;33m([0m[0mself[0m[1;33m.[0m[0m__class__[0m[1;33m.[0m[0m__name__[0m[1;33m+[0m[1;34m'.'[0m[1;33m+[0m[0mf[0m[1;33m.[0m[0m__name__[0m[1;33m)[0m[1;33m[0m[0m [1;32m---> 92[1;33m [0mout[0m [1;33m=[0m [0mf[0m[1;33m([0m[0mself[0m[1;33m,[0m[1;33m*[0m[0margs[0m[1;33m,[0m[1;33m**[0m[0mkwargs[0m[1;33m)[0m[1;33m[0m[0m [0m[0;32m 93[0m [1;32mif[0m [0mtype[0m[1;33m([0m[0mcounter[0m[1;33m)[0m [1;32mis[0m [0mCounter[0m[1;33m:[0m [0mcounter[0m[1;33m.[0m[0mcountToc[0m[1;33m([0m[0mself[0m[1;33m.[0m[0m__class__[0m[1;33m.[0m[0m__name__[0m[1;33m+[0m[1;34m'.'[0m[1;33m+[0m[0mf[0m[1;33m.[0m[0m__name__[0m[1;33m)[0m[1;33m[0m[0m [0;32m 94[0m [1;32mreturn[0m [0mout[0m[1;33m[0m[0m [1;32m/home/seogi/Documents/simpeg/SimPEG/DataMisfit.pyc[0m in [0;36meval2Deriv[1;34m(self, m, v, u)[0m [0;32m 135[0m [0mprob[0m [1;33m=[0m [0mself[0m[1;33m.[0m[0mprob[0m[1;33m[0m[0m [0;32m 136[0m [1;32mif[0m [0mu[0m [1;32mis[0m [0mNone[0m[1;33m:[0m [0mu[0m [1;33m=[0m [0mprob[0m[1;33m.[0m[0mfields[0m[1;33m([0m[0mm[0m[1;33m)[0m[1;33m[0m[0m [1;32m--> 137[1;33m [1;32mreturn[0m [0mprob[0m[1;33m.[0m[0mJtvec_approx[0m[1;33m([0m[0mm[0m[1;33m,[0m [0mself[0m[1;33m.[0m[0mWd[0m [1;33m*[0m [1;33m([0m[0mself[0m[1;33m.[0m[0mWd[0m [1;33m*[0m [0mprob[0m[1;33m.[0m[0mJvec_approx[0m[1;33m([0m[0mm[0m[1;33m,[0m [0mv[0m[1;33m,[0m [0mu[0m[1;33m=[0m[0mu[0m[1;33m)[0m[1;33m)[0m[1;33m,[0m [0mu[0m[1;33m=[0m[0mu[0m[1;33m)[0m[1;33m[0m[0m [0m [1;32m/home/seogi/Documents/simpeg/SimPEG/Utils/CounterUtils.pyc[0m in [0;36mwrapper[1;34m(self, *args, **kwargs)[0m [0;32m 90[0m [0mcounter[0m [1;33m=[0m [0mgetattr[0m[1;33m([0m[0mself[0m[1;33m,[0m[1;34m'counter'[0m[1;33m,[0m[0mNone[0m[1;33m)[0m[1;33m[0m[0m [0;32m 91[0m [1;32mif[0m [0mtype[0m[1;33m([0m[0mcounter[0m[1;33m)[0m [1;32mis[0m [0mCounter[0m[1;33m:[0m [0mcounter[0m[1;33m.[0m[0mcountTic[0m[1;33m([0m[0mself[0m[1;33m.[0m[0m__class__[0m[1;33m.[0m[0m__name__[0m[1;33m+[0m[1;34m'.'[0m[1;33m+[0m[0mf[0m[1;33m.[0m[0m__name__[0m[1;33m)[0m[1;33m[0m[0m [1;32m---> 92[1;33m [0mout[0m [1;33m=[0m [0mf[0m[1;33m([0m[0mself[0m[1;33m,[0m[1;33m*[0m[0margs[0m[1;33m,[0m[1;33m**[0m[0mkwargs[0m[1;33m)[0m[1;33m[0m[0m [0m[0;32m 93[0m [1;32mif[0m [0mtype[0m[1;33m([0m[0mcounter[0m[1;33m)[0m [1;32mis[0m [0mCounter[0m[1;33m:[0m [0mcounter[0m[1;33m.[0m[0mcountToc[0m[1;33m([0m[0mself[0m[1;33m.[0m[0m__class__[0m[1;33m.[0m[0m__name__[0m[1;33m+[0m[1;34m'.'[0m[1;33m+[0m[0mf[0m[1;33m.[0m[0m__name__[0m[1;33m)[0m[1;33m[0m[0m [0;32m 94[0m [1;32mreturn[0m [0mout[0m[1;33m[0m[0m [1;32m/home/seogi/Documents/simpeg/SimPEG/Problem.pyc[0m in [0;36mJtvec_approx[1;34m(self, m, v, u)[0m [0;32m 399[0m [1;33m:[0m[1;32mreturn[0m[1;33m:[0m [0mJTv[0m[1;33m[0m[0m [0;32m 400[0m """ [1;32m--> 401[1;33m [1;32mreturn[0m [0mself[0m[1;33m.[0m[0mJtvec[0m[1;33m([0m[0mm[0m[1;33m,[0m [0mv[0m[1;33m,[0m [0mu[0m[1;33m)[0m[1;33m[0m[0m [0m[0;32m 402[0m [1;33m[0m[0m [0;32m 403[0m [1;32mdef[0m [0mfields[0m[1;33m([0m[0mself[0m[1;33m,[0m [0mm[0m[1;33m)[0m[1;33m:[0m[1;33m[0m[0m [1;32m/home/seogi/Documents/simpeg/SimPEG/Utils/CounterUtils.pyc[0m in [0;36mwrapper[1;34m(self, *args, **kwargs)[0m [0;32m 90[0m [0mcounter[0m [1;33m=[0m [0mgetattr[0m[1;33m([0m[0mself[0m[1;33m,[0m[1;34m'counter'[0m[1;33m,[0m[0mNone[0m[1;33m)[0m[1;33m[0m[0m [0;32m 91[0m [1;32mif[0m [0mtype[0m[1;33m([0m[0mcounter[0m[1;33m)[0m [1;32mis[0m [0mCounter[0m[1;33m:[0m [0mcounter[0m[1;33m.[0m[0mcountTic[0m[1;33m([0m[0mself[0m[1;33m.[0m[0m__class__[0m[1;33m.[0m[0m__name__[0m[1;33m+[0m[1;34m'.'[0m[1;33m+[0m[0mf[0m[1;33m.[0m[0m__name__[0m[1;33m)[0m[1;33m[0m[0m [1;32m---> 92[1;33m [0mout[0m [1;33m=[0m [0mf[0m[1;33m([0m[0mself[0m[1;33m,[0m[1;33m*[0m[0margs[0m[1;33m,[0m[1;33m**[0m[0mkwargs[0m[1;33m)[0m[1;33m[0m[0m [0m[0;32m 93[0m [1;32mif[0m [0mtype[0m[1;33m([0m[0mcounter[0m[1;33m)[0m [1;32mis[0m [0mCounter[0m[1;33m:[0m [0mcounter[0m[1;33m.[0m[0mcountToc[0m[1;33m([0m[0mself[0m[1;33m.[0m[0m__class__[0m[1;33m.[0m[0m__name__[0m[1;33m+[0m[1;34m'.'[0m[1;33m+[0m[0mf[0m[1;33m.[0m[0m__name__[0m[1;33m)[0m[1;33m[0m[0m [0;32m 94[0m [1;32mreturn[0m [0mout[0m[1;33m[0m[0m [1;32m/home/seogi/Documents/simpegpf/simpegPF/Magnetics.pyc[0m in [0;36mJtvec[1;34m(self, m, v, u)[0m [0;32m 328[0m [0mAtemp[0m [1;33m=[0m [0mUtils[0m[1;33m.[0m[0msdiag[0m[1;33m([0m[0mself[0m[1;33m.[0m[0mMfMu0[0m[1;33m*[0m[0mB0[0m[1;33m)[0m[1;33m*[0m[1;33m([0m[0mdMfMuI[0m [1;33m*[0m [1;33m([0m[0mdmudm[0m[1;33m)[0m[1;33m)[0m[1;33m[0m[0m [0;32m 329[0m [0mBtemp[0m [1;33m=[0m [0mUtils[0m[1;33m.[0m[0msdiag[0m[1;33m([0m[0mDiv[0m[1;33m.[0m[0mT[0m[1;33m*[0m[0mu[0m[1;33m)[0m[1;33m*[0m[1;33m([0m[0mdMfMuI[0m[1;33m*[0m [1;33m([0m[0mdmudm[0m[1;33m)[0m[1;33m)[0m[1;33m[0m[0m [1;32m--> 330[1;33m [0mJtv[0m [1;33m=[0m [0mAtemp[0m[1;33m.[0m[0mT[0m[1;33m*[0m[1;33m([0m[0mP[0m[1;33m.[0m[0mT[0m[1;33m*[0m[0mv[0m[1;33m)[0m [1;33m-[0m [0mBtemp[0m[1;33m.[0m[0mT[0m[1;33m*[0m[1;33m([0m[0mP[0m[1;33m.[0m[0mT[0m[1;33m*[0m[0mv[0m[1;33m)[0m [1;33m-[0m [0mCtv[0m[1;33m[0m[0m [0m[0;32m 331[0m [1;33m[0m[0m [0;32m 332[0m [1;32mreturn[0m [0mUtils[0m[1;33m.[0m[0mmkvc[0m[1;33m([0m[0mJtv[0m[1;33m)[0m[1;33m[0m[0m [1;32m/usr/local/lib/python2.7/dist-packages/scipy/sparse/base.pyc[0m in [0;36m__mul__[1;34m(self, other)[0m [0;32m 294[0m [1;31m# Fast path for the most common case[0m[1;33m[0m[1;33m[0m[0m [0;32m 295[0m [1;32mif[0m [0mother[0m[1;33m.[0m[0mshape[0m [1;33m==[0m [1;33m([0m[0mN[0m[1;33m,[0m[1;33m)[0m[1;33m:[0m[1;33m[0m[0m [1;32m--> 296[1;33m [1;32mreturn[0m [0mself[0m[1;33m.[0m[0m_mul_vector[0m[1;33m([0m[0mother[0m[1;33m)[0m[1;33m[0m[0m [0m[0;32m 297[0m [1;32melif[0m [0mother[0m[1;33m.[0m[0mshape[0m [1;33m==[0m [1;33m([0m[0mN[0m[1;33m,[0m [1;36m1[0m[1;33m)[0m[1;33m:[0m[1;33m[0m[0m [0;32m 298[0m [1;32mreturn[0m [0mself[0m[1;33m.[0m[0m_mul_vector[0m[1;33m([0m[0mother[0m[1;33m.[0m[0mravel[0m[1;33m([0m[1;33m)[0m[1;33m)[0m[1;33m.[0m[0mreshape[0m[1;33m([0m[0mM[0m[1;33m,[0m [1;36m1[0m[1;33m)[0m[1;33m[0m[0m [1;32m/usr/local/lib/python2.7/dist-packages/scipy/sparse/compressed.pyc[0m in [0;36m_mul_vector[1;34m(self, other)[0m [0;32m 445[0m [1;31m# csr_matvec or csc_matvec[0m[1;33m[0m[1;33m[0m[0m [0;32m 446[0m [0mfn[0m [1;33m=[0m [0mgetattr[0m[1;33m([0m[0m_sparsetools[0m[1;33m,[0m[0mself[0m[1;33m.[0m[0mformat[0m [1;33m+[0m [1;34m'_matvec'[0m[1;33m)[0m[1;33m[0m[0m [1;32m--> 447[1;33m [0mfn[0m[1;33m([0m[0mM[0m[1;33m,[0m [0mN[0m[1;33m,[0m [0mself[0m[1;33m.[0m[0mindptr[0m[1;33m,[0m [0mself[0m[1;33m.[0m[0mindices[0m[1;33m,[0m [0mself[0m[1;33m.[0m[0mdata[0m[1;33m,[0m [0mother[0m[1;33m,[0m [0mresult[0m[1;33m)[0m[1;33m[0m[0m [0m[0;32m 448[0m [1;33m[0m[0m [0;32m 449[0m [1;32mreturn[0m [0mresult[0m[1;33m[0m[0m [1;31mKeyboardInterrupt[0m:
In [20]:
opt.counter.summary()
xc = opt.recall('xc')Counters: ProjectedGNCG.activeSet : 30 ProjectedGNCG.doEndIteration : 30 ProjectedGNCG.doStartIteration : 31 ProjectedGNCG.projection : 394 ProjectedGNCG.scaleSearchDirection : 30 Times: mean sum MagneticsDiffSecondary.Jtvec : 3.10e-01, 5.64e+01, 182x MagneticsDiffSecondary.Jtvec_approx : 3.48e-01, 5.26e+01, 151x MagneticsDiffSecondary.Jvec : 3.48e-01, 5.26e+01, 151x MagneticsDiffSecondary.Jvec_approx : 3.48e-01, 5.26e+01, 151x ProjectedGNCG.findSearchDirection : 3.66e+00, 1.10e+02, 30x ProjectedGNCG.minimize : 2.57e+02, 2.57e+02, 1x ProjectedGNCG.modifySearchDirection : 4.71e+00, 1.41e+02, 30x
In [21]:
from JSAnimation import IPython_display
from matplotlib import animation
from SimPEG import *
fig, ax = subplots(1,2, figsize = (16, 5))
ax[0].set_xlabel('Easting (m)')
ax[0].set_ylabel('Depth (m)')
ax[1].set_xlabel('Easting (m)')
ax[1].set_ylabel('Depth (m)')
def animate(i_id):
indx = 18
temp = dmap*(xc[i_id])
minval = (temp).min()
maxval = (temp).max()
frame1 = mesh.plotSlice(temp, vType='CC', ind=indx, normal='X',ax = ax[1], grid=False, gridOpts={'color':'b','lw':0.3, 'alpha':0.5}, )
frame2 = mesh.plotSlice(chi, vType='CC', ind=indx, normal='X',ax = ax[0], grid=False, gridOpts={'color':'b','lw':0.3, 'alpha':0.5}, );
ax[0].set_title('True model', fontsize = 16)
ax[1].set_title('Estimated model at iteration = ' + str(i_id+1), fontsize = 16)
ax[0].set_ylim(-500, 0)
ax[1].set_ylim(-500, 0)
return frame1[0]
animation.FuncAnimation(fig, animate, frames=10, interval=40, blit=True)Out [21]:
– + Once Loop Reflect
In [16]:
import matplotlib
matplotlib.rcParams.update({'font.size': 14, 'text.usetex': True, 'font.family': 'arial'})In [17]:
indx = 18
iteration = 9
fig, axes = subplots(1,2, figsize = (12, 5))
vmin = chi.min()
vmax = chi.max()
ps1 = mesh.plotSlice(chi, vType='CC', ind=indx, normal='X',ax = axes[0], grid=True, gridOpts={'color':'b','lw':0.3, 'alpha':0.5});
axes[0].set_title('$\chi_{true}$', fontsize = 16)
axes[0].set_ylim(-500, 0.)
cb1 = colorbar(ps1[0], ax = axes[0], orientation="horizontal", ticks=[np.linspace(vmin, vmax, 5)], format = FormatStrFormatter('$%5.3f$'))
axes[0].set_xlabel('Easting (m)')
axes[0].set_ylabel('Depth (m)')
vmin = (actMap*xc[iteration]).min()
vmax = (actMap*xc[iteration]).max()
ps2 = mesh.plotSlice(actMap*xc[iteration], vType='CC', ind=indx, normal='X', ax = axes[1], grid=True, gridOpts={'color':'b','lw':0.3, 'alpha':0.5});
axes[1].set_title('$\chi_{pred}$', fontsize = 16)
axes[1].set_ylim(-500, 0.)
cb2 = colorbar(ps2[0], ax = axes[1], orientation="horizontal", ticks=[np.linspace(vmin, vmax, 5)], format = FormatStrFormatter('$%5.3f$'))
cb1.set_label('Susceptibility (dimensionless)')
cb2.set_label('Susceptibility (dimensionless)')
axes[1].set_xlabel('Easting (m)')
axes[1].set_ylabel('Depth (m)')
fig.savefig('model.png', dpi = 200)/usr/local/lib/python2.7/dist-packages/matplotlib/lines.py:503: RuntimeWarning: invalid value encountered in greater_equal return np.alltrue(x[1:] - x[0:-1] >= 0)
In [18]:
dpred_xc = survey.dpred(xc[iteration])
fig, ax = plt.subplots(1,2, figsize = (12,7) )
vmin = survey.dobs.min()
vmax = survey.dobs.max()
dat2 = ax[0].imshow(np.reshape(survey.dobs, (xr.size, yr.size), order='F'), extent=[min(xr), max(xr), min(yr), max(yr)], vmin = vmin, vmax = vmax)
cb1 = plt.colorbar(dat2, ax = ax[0], orientation="horizontal", ticks=[np.linspace(vmin, vmax, 5)])
dat = ax[1].imshow(np.reshape(dpred_xc, (xr.size, yr.size), order='F'), extent=[min(xr), max(xr), min(yr), max(yr)], vmin = vmin, vmax = vmax)
cb2 = plt.colorbar(dat, ax = ax[1], orientation="horizontal", ticks=[np.linspace(vmin, vmax, 5)])
ax[0].plot(rxLoc[:,0],rxLoc[:,1],'w.', ms=1)
ax[1].plot(rxLoc[:,0],rxLoc[:,1],'w.', ms=1)
ax[0].set_title('Observed', fontsize = 16)
ax[1].set_title('Predicted', fontsize = 16)
ax[0].set_xlabel('Easting (m)')
ax[0].set_ylabel('Northing (m)')
ax[1].set_xlabel('Easting (m)')
ax[1].set_ylabel('Northing (m)')
cb1.set_label('Total magnetic intensity (nT)')
cb2.set_label('Total magnetic intensity (nT)')
fig.savefig('obspred.png', dpi = 200)In [18]: