In [16]:
from SimPEG import *
%pylab inline
In [17]:
import matplotlib
from IPython.display import set_matplotlib_formats
set_matplotlib_formats('png')
matplotlib.rcParams['savefig.dpi'] = 100
In [18]:
cs, ncx, ncy, ncz, npad = 20., 30, 20, 30, 12
hx = [(cs,npad,-1.4), (cs,ncx), (cs,npad,1.4)]
hy = [(cs,npad,-1.4), (cs,ncy), (cs,npad,1.4)]
hz = [(cs,npad,-1.4), (cs,ncz), (cs,npad,1.4)]
mesh = Mesh.TensorMesh([hx,hy,hz], 'CCC')
print ("Padding distance x: %10.5f m") % (np.sum(mesh.hx[:npad]))
print ("Padding distance z: %10.5f m") % (np.sum(mesh.hz[:npad]))
print ("Min dx: %10.5f m") % (mesh.hx.min())
print ("Min dz: %10.5f m") % (mesh.hz.min())
In [19]:
cs, ncx, ncy, ncz, npad = 20., 30, 20, 15, 12
hx = [(cs,npad,-1.4), (cs,ncx), (cs,npad,1.4)]
hy = [(cs,npad,-1.4), (cs,ncy), (cs,npad,1.4)]
hz = [(cs,npad,-1.4), (cs,ncz)]
meshact = Mesh.TensorMesh([hx,hy,hz], 'CCN')
In [20]:
def circfun(xc, yc, r, npoint):
theta = np.linspace(np.pi, -np.pi, npoint)
x = r*np.cos(theta)
y = r*np.sin(theta)
return x+xc, y+yc
In [20]:
In [21]:
xcirc1, ycirc1 = circfun(-150., 0., 250., 60)
xcirc2, ycirc2 = circfun(150., 0., 250., 60)
In [22]:
Utils.meshutils.writeUBCTensorMesh(mesh, 'mesh.msh')
In [23]:
sigma = Utils.meshutils.readUBCTensorModel('sigma_realistic.con', mesh)
In [38]:
mopt = np.load('./inv3D_realistic_ref2D/model_8.npy')
active = mesh.gridCC[:,2] < 0.
actMap = Maps.ActiveCells(mesh, active, np.log(1e-8), nC=mesh.nC)
actMapreg = Maps.ActiveCells(mesh, active, 0., nC=mesh.nC)
mapping = Maps.ExpMap(mesh) * actMap
regmap = Maps.IdentityMap(meshact)
In [39]:
print meshact.nC
print np.count_nonzero(active)
In [40]:
sigma_est = mapping*mopt
In [41]:
Utils.meshutils.writeUBCTensorModel(mesh, sigma_est, 'sigest3D_realistic.con')
In [42]:
x1 = np.arange(30)*10 - 300.
y1 = np.arange(30)*10 - 150.
xyz1 = Utils.ndgrid(x1, y1, np.r_[0.])
x2 = np.arange(30)*10 + 10.
y2 = np.arange(30)*10 - 150.
xyz2 = Utils.ndgrid(x2, y2, np.r_[0.])
In [43]:
fig, ax = plt.subplots(1,2, figsize=(18,6))
indz1 = 21
indz2 = indz1
print mesh.vectorCCz[indz1]
mesh.plotSlice(np.log10(sigma), ind = indz1, ax = ax[0], clim=(-3, -0.5))
mesh.plotSlice(np.log10(sigma_est), ind = indz2, ax = ax[1], clim=(-3, -0.5))
for i in range(2):
ax[i].plot(xyz1[:,0], xyz1[:,1], 'r.')
ax[i].plot(xyz2[:,0], xyz2[:,1], 'b.')
# ax[i].plot(xcirc1, ycirc1, 'r-')
# ax[i].plot(xcirc2, ycirc2, 'b-')
ax[i].set_xlim(-320, 320)
ax[i].set_ylim(-150, 150)
In [44]:
indy=23
fig, ax = plt.subplots(1,2, figsize=(16,4))
print mesh.vectorCCy[indy]
dat0 = mesh.plotSlice(np.log10(sigma), normal='Y', ind = indy, ax = ax[0], clim=(-3, -0.5))
dat1 = mesh.plotSlice(np.log10(sigma_est), normal='Y', ind = indy, ax = ax[1], clim=(-3, -0.5))
for i in range(2):
plt.colorbar(dat0[0], ax = ax[i])
ax[i].set_xlim(-300, 300)
ax[i].set_ylim(-700, 0.)
In [45]:
import simpegEM as EM
# mapping = Maps.IdentityMap(mesh)
In [46]:
ntx = 2
nrx1 = xyz1.shape[0]
time = np.logspace(-4, -2, 31)
In [47]:
a = True
if a != None:
print 'a'
In [48]:
for maps in mapping.maps:
print maps
In [49]:
rx1 = EM.TDEM.RxTDEM(xyz1, time, 'bz')
tx1 = EM.TDEM.TxTDEM(np.array([0., -150., 0.]), 'CircularLoop_MVP', [rx1])
tx1.radius = 250.
rx2 = EM.TDEM.RxTDEM(xyz2, time, 'bz')
tx2 = EM.TDEM.TxTDEM(np.array([0., 150., 0.]), 'CircularLoop_MVP', [rx2])
tx2.radius = 250.
In [50]:
# survey = EM.TDEM.SurveyTDEM([tx1, tx2])
survey = EM.TDEM.SurveyTDEM([tx1])
prb = EM.TDEM.ProblemTDEM_b(mesh, mapping=mapping, verbose=True)
# prb.solver = MumpsSolver
# prb.solverOpts = {"symmetric":True}
# prb.timeSteps = [(1e-4/15, 10), (1e-3/15, 10), (1e-2/15, 5)]
prb.timeSteps = [(1e-4/15, 10)]
if prb.ispaired:
prb.unpair()
if survey.ispaired:
survey.unpair()
prb.pair(survey)
In [51]:
dpred = np.load('bz_realistic.npy')
In [52]:
noise = abs(dpred)*np.random.randn(dpred.size)*0.05
dobs = dpred+noise
survey.dobs = dpred
std = 0.05
In [53]:
Imap = Maps.IdentityMap(mesh)
In [54]:
sigtest = np.load('invTEM2D.npy')
sighalf = np.ones_like(sigma)*1e-3
m0 = np.log(sigtest[active])
mref = np.log(sighalf[active])
dmis = DataMisfit.l2_DataMisfit(survey)
dmis.Wd = 1/(abs(survey.dobs)*std)
opt = Optimization.InexactGaussNewton(maxIter = 15)
reg = Regularization.Tikhonov(mesh, mapping=Imap)
reg.active = active
#betaest = Directives.BetaEstimate_ByEig(beta0_ratio = 1e2)
beta = Directives.BetaSchedule(coolingFactor = 8, coolingRate = 3)
invprb = InvProblem.BaseInvProblem(dmis, reg, opt)
# inv = Inversion.BaseInversion(invprb, directiveList = [beta,RememberXC()])
#inv = Inversion.BaseInversion(invprb, directiveList = [beta, ])
reg.alpha_s = 1e-5
reg.alpha_x = 1.
reg.alpha_y = 1.
reg.alpha_z = 1.
reg.mref = mref
C = Utils.Counter()
prb.counter = C
opt.counter = C
opt.LSshorten = 0.5
In [55]:
print reg.Wx.shape
print meshact.nC
In [56]:
# test = reg.evalDeriv(mref)
# test_1 = reg.evalDeriv(m0)
In [59]:
dest = np.load('inv3D_realistic_ref2D/dpred_5.npy')
In [60]:
Dpred = dobs.reshape((900, 31, 2), order='F')
Dpred1 = Dpred[:,:,0]
Dpred2 = Dpred[:,:,1]
Dest = dest.reshape((900, 31, 2), order='F')
Dest1 = Dest[:,:,0]
Dest2 = Dest[:,:,1]
In [61]:
itime = 28
fig, ax = plt.subplots(1,2, figsize = (12, 7))
vmin = Utils.mkvc(Dpred[:,itime,0]).min()
vmax = Utils.mkvc(Dpred[:,itime,0]).max()
dat1 = ax[0].contourf(xyz1[:,0].reshape((30, 30), order='F'), xyz1[:,1].reshape((30, 30), order='F'), Dpred[:,itime,0].reshape((30, 30), order='F'), 30, vmin=vmin, vmax=vmax)
dat1 = ax[1].contourf(xyz2[:,0].reshape((30, 30), order='F'), xyz2[:,1].reshape((30, 30), order='F'), Dest[:,itime,0].reshape((30, 30), order='F'), 30, vmin=vmin, vmax=vmax)
for i in range(2):
ax[i].set_xlabel('Easting (m)', fontsize = 16)
ax[i].set_ylabel('Northing (m)', fontsize = 16)
cb = plt.colorbar(dat1, ax=ax[i], orientation='horizontal')
cb.set_label('Magnetic flux density (Wb/m$^2$)', fontsize = 14)
ax[0].set_title('Observed data from Tx#1', fontsize = 16)
ax[1].set_title('Predicted data from Tx#1', fontsize = 16)
fig.savefig('./figures/obspredTD_7_3mstx1.png')
In [62]:
itime = 9
fig, ax = plt.subplots(1,2, figsize = (12, 7))
vmin = Utils.mkvc(Dpred[:,itime,1]).min()
vmax = Utils.mkvc(Dpred[:,itime,1]).max()
dat1 = ax[0].contourf(xyz1[:,0].reshape((30, 30), order='F'), xyz1[:,1].reshape((30, 30), order='F'), Dpred[:,itime,1].reshape((30, 30), order='F'), 30)
dat1 = ax[1].contourf(xyz2[:,0].reshape((30, 30), order='F'), xyz2[:,1].reshape((30, 30), order='F'), Dest[:,itime,1].reshape((30, 30), order='F'), 30)
for i in range(2):
ax[i].set_xlabel('Easting (m)', fontsize = 16)
ax[i].set_ylabel('Northing (m)', fontsize = 16)
cb = plt.colorbar(dat1, ax=ax[i], orientation='horizontal')
cb.set_label('Magnetic flux density (Wb/m$^2$)', fontsize = 14)
ax[0].set_title('Observed data from Tx#2', fontsize = 16)
ax[1].set_title('Predicted data from Tx#2', fontsize = 16)
fig.savefig('./figures/obspredTD_7_3mstx2.png')
In [32]:
rxind = 20
plt.loglog(time, Dpred[rxind,:,0])
plt.loglog(time, Dest[rxind,:,0])
Out[32]:
In [33]:
itime = 0
fig, ax = plt.subplots(1,2, figsize = (10, 4))
ax[0].hist(Dpred1[:,itime])
ax[1].hist(Dpred2[:,itime])
Out[33]:
In [35]:
# from JSAnimation import IPython_display
# from matplotlib import animation
# fig, ax = plt.subplots(1,2, figsize = (12, 5))
# for i in range(2):
# ax[i].set_xlabel('x (m)', fontsize = 16)
# ax[i].set_ylabel('y (m)', fontsize = 16)
# def animate(itime):
# frame1 = ax[0].contourf(xyz1[:,0].reshape((30, 30), order='F'), xyz1[:,1].reshape((30, 30), order='F'), Dpred[:,itime,0].reshape((30, 30), order='F'), 30)
# frame2 = ax[1].contourf(xyz2[:,0].reshape((30, 30), order='F'), xyz2[:,1].reshape((30, 30), order='F'), Dpred[:,itime,1].reshape((30, 30), order='F'), 30)
# # cb1 = plt.colorbar(frame1, ax = ax[0])
# # cb2 = plt.colorbar(frame2, ax = ax[1])
# return frame1, frame2
# animation.FuncAnimation(fig, animate, frames=31, interval=40, blit=True)
In [ ]:
# np.save('bzobs_realistic', dobs)
# dmis = DataMisfit.l2_DataMisfit(survey)
In [ ]: