mirror of
https://github.com/wassname/simpeg.git
synced 2026-08-09 12:30:41 +08:00
678 KiB
678 KiB
In [1]:
from SimPEG import *
import matplotlib.pyplot as plt
import simpegPF as PF
import matplotlib
#from get_UBC_mesh import get_UBC_mesh
from read_MAG_obs import read_MAG_obs
from get_T_mat import get_T_matIn [26]:
#mesh = Utils.meshutils.readUBCTensorMesh("Tile1.msh")
cs = 25.
hxind = [(cs,5,-1.3), (cs/2.0, 21),(cs,5,1.3)]
hyind = [(cs,5,-1.3), (cs/2.0, 21),(cs,5,1.3)]
hzind = [(cs,5,-1.3),(cs/2.0, 20)]
mesh = Mesh.TensorMesh([hxind, hyind, hzind], 'CCC')
xn = mesh.vectorNx
yn = mesh.vectorNy
zn = mesh.vectorNz
mcell = (xn.size-1) * (yn.size-1) * (zn.size-1)
N = mesh.gridN
Utils.meshutils.writeUBCTensorMesh('Mesh.msh',mesh)
In [28]:
aa.size
print N[0],N[-1]
Utils.mkvc?[-425.15075 -425.15075 -271.950375] [ 425.15075 425.15075 271.950375]
In [25]:
sph_ind = PF.MagAnalytics.spheremodel(mesh, 0, 0, 175, 50)
Utils.meshutils.writeUBCTensorModel('Mesh.dat',mesh,sph_ind)In [30]:
# Load in obsfile
#Decl, Incl, B0, Mdec, Minc, obsx, obsy, obsz, data, unct = read_MAG_obs('Obs_RAW_REM_GRID_TMI.obs')
Incl = 90.
Decl = 00.
B0 = 50000
# Or create juste a plane grid
xr = np.linspace(-125, 125, 25)
yr = np.linspace(-125, 125, 25)
X, Y = np.meshgrid(xr, yr)
Z = np.ones((xr.size, yr.size))*280
rxLoc = np.c_[Utils.mkvc(X), Utils.mkvc(Y), Utils.mkvc(Z)]
# Write obsfile in UBC format
fid = open('Obs_loc.dat','w')
fid.write('%6.2f %6.2f %6.2f\n' %(Incl, Decl, B0) )
fid.write('%6.2f %6.2f %6.2f\n' %(Incl, Decl, 1) )
fid.close();In [6]:
# Create magnetization matrix
mx = np.cos(np.deg2rad(Incl)) * np.cos(np.deg2rad(Decl))
my = np.cos(np.deg2rad(Incl)) * np.sin(np.deg2rad(Decl))
mz = np.sin(np.deg2rad(Incl))In [7]:
Mx = scipy.sparse.diags(np.ones([mcell])*mx*B0,0)In [8]:
type(Mx)Out [8]:
scipy.sparse.dia.dia_matrix
In [9]:
Mx1 = Utils.sdiag(np.ones([mcell])*mx*B0)In [10]:
type(Mx1)Out [10]:
scipy.sparse.csr.csr_matrix
In [11]:
Mx = Utils.sdiag(np.ones([mcell])*mx*B0)
My = Utils.sdiag(np.ones([mcell])*my*B0)
Mz = Utils.sdiag(np.ones([mcell])*mz*B0)
#matplotlib.pyplot.spy(scipy.sparse.csr_matrix(Mx))
#plt.show()
M = sp.vstack((Mx,My,Mz));
In [13]:
# Call the function to build tensor matrix
Tx, Ty, Tz = get_T_mat(xn,yn,zn,obsx[0],obsy[0],obsz[0])
print Tx[0,0],Ty[0,0],Tz[0,0]
0 24 1 24 2 24 3 24 4 24 5 24 6 24 7 24
[1;31m---------------------------------------------------------------------------[0m [1;31mKeyboardInterrupt[0m Traceback (most recent call last) [1;32m<ipython-input-13-0ffb93de4fd3>[0m in [0;36m<module>[1;34m()[0m [0;32m 1[0m [1;31m# Call the function to build tensor matrix[0m[1;33m[0m[1;33m[0m[0m [1;32m----> 2[1;33m [0mTx[0m[1;33m,[0m [0mTy[0m[1;33m,[0m [0mTz[0m [1;33m=[0m [0mget_T_mat[0m[1;33m([0m[0mxn[0m[1;33m,[0m[0myn[0m[1;33m,[0m[0mzn[0m[1;33m,[0m[0mobsx[0m[1;33m[[0m[1;36m0[0m[1;33m][0m[1;33m,[0m[0mobsy[0m[1;33m[[0m[1;36m0[0m[1;33m][0m[1;33m,[0m[0mobsz[0m[1;33m[[0m[1;36m0[0m[1;33m][0m[1;33m)[0m[1;33m[0m[0m [0m[0;32m 3[0m [1;33m[0m[0m [0;32m 4[0m [1;32mprint[0m [0mTx[0m[1;33m[[0m[1;36m0[0m[1;33m,[0m[1;36m0[0m[1;33m][0m[1;33m,[0m[0mTy[0m[1;33m[[0m[1;36m0[0m[1;33m,[0m[1;36m0[0m[1;33m][0m[1;33m,[0m[0mTz[0m[1;33m[[0m[1;36m0[0m[1;33m,[0m[1;36m0[0m[1;33m][0m[1;33m[0m[0m [1;32mC:\Users\dominiquef.MIRAGEOSCIENCE\Documents\GIT\SimPEG\Source\SimPEGpf\simpegPF\notebooks\get_T_mat.py[0m in [0;36mget_T_mat[1;34m(xn, yn, zn, obsx, obsy, obsz)[0m [0;32m 103[0m [1;33m[0m[0m [0;32m 104[0m [0mR1[0m [1;33m=[0m [1;33m([0m[0mdx2[0m[1;33m**[0m[1;36m2[0m [1;33m+[0m [0mdz1[0m[1;33m**[0m[1;36m2[0m[1;33m)[0m[1;33m;[0m[1;33m[0m[0m [1;32m--> 105[1;33m [0mR2[0m [1;33m=[0m [1;33m([0m[0mdx2[0m[1;33m**[0m[1;36m2[0m [1;33m+[0m [0mdz2[0m[1;33m**[0m[1;36m2[0m[1;33m)[0m[1;33m;[0m[1;33m[0m[0m [0m[0;32m 106[0m [0mR3[0m [1;33m=[0m [1;33m([0m[0mdx1[0m[1;33m**[0m[1;36m2[0m [1;33m+[0m [0mdz1[0m[1;33m**[0m[1;36m2[0m[1;33m)[0m[1;33m;[0m[1;33m[0m[0m [0;32m 107[0m [0mR4[0m [1;33m=[0m [1;33m([0m[0mdx1[0m[1;33m**[0m[1;36m2[0m [1;33m+[0m [0mdz2[0m[1;33m**[0m[1;36m2[0m[1;33m)[0m[1;33m;[0m[1;33m[0m[0m [1;31mKeyboardInterrupt[0m:
In [16]:
x = np.ones(10)
y = np.ones(10)*3In [19]:
x.dot(y)Out [19]:
30.0
In [15]:
Gx = Tx*MIn [10]:
cs = 25.
hxind = [(cs,5,-1.3), (cs/2.0, 41),(cs,5,1.3)]
hyind = [(cs,5,-1.3), (cs/2.0, 41),(cs,5,1.3)]
hzind = [(cs,5,-1.3), (cs/2.0, 40),(cs,5,1.3)]
M3 = Mesh.TensorMesh([hxind, hyind, hzind], 'CCC')In [11]:
mu0 = 4*np.pi*1e-7
chibkg = 0.
chiblk = 0.01
chi = np.ones(M3.nC)*chibkgIn [12]:
sph_ind = spheremodel(M3, 0, 0, 0, 100)
chi[sph_ind] = chiblk
mu = (1.+chi)*mu0[1;31m---------------------------------------------------------------------------[0m [1;31mNameError[0m Traceback (most recent call last) [1;32m<ipython-input-12-72465b2c3978>[0m in [0;36m<module>[1;34m()[0m [1;32m----> 1[1;33m [0msph_ind[0m [1;33m=[0m [0mspheremodel[0m[1;33m([0m[0mM3[0m[1;33m,[0m [1;36m0[0m[1;33m,[0m [1;36m0[0m[1;33m,[0m [1;36m0[0m[1;33m,[0m [1;36m100[0m[1;33m)[0m[1;33m[0m[0m [0m[0;32m 2[0m [0mchi[0m[1;33m[[0m[0msph_ind[0m[1;33m][0m [1;33m=[0m [0mchiblk[0m[1;33m[0m[0m [0;32m 3[0m [0mmu[0m [1;33m=[0m [1;33m([0m[1;36m1.[0m[1;33m+[0m[0mchi[0m[1;33m)[0m[1;33m*[0m[0mmu0[0m[1;33m[0m[0m [1;31mNameError[0m: name 'spheremodel' is not defined
In [8]:
figsize(10,10)
M3.plotGrid()C:\Users\SEOGI\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.0.1.1189.win-x86_64\lib\site-packages\matplotlib\lines.py:483: RuntimeWarning: invalid value encountered in greater_equal return np.alltrue(x[1:]-x[0:-1]>=0)
In [9]:
M3.plotImage(np.log10(mu), imageType='CC')Out [9]:
<matplotlib.collections.QuadMesh at 0xaa7f390>
In [15]:
print info
print M3.nC0 119646
In [16]:
B = -MfmuI*D.T*phi
rhsa = A*phi
print info
print np.linalg.norm(rhs-rhsa)/np.linalg.norm(rhs)0 7.65372604673e-07
In [17]:
figsize(16,5)
M3.plotImage(B, imageType='F')In [18]:
xr = np.linspace(-300, 300, 41)
yr = np.linspace(-300, 300, 41)
X, Y = np.meshgrid(xr, yr)
Z = np.ones((size(xr), size(yr)))*0.In [19]:
rxLoc = np.c_[Utils.mkvc(X), Utils.mkvc(Y), Utils.mkvc(Z)]
Qfx = M3.getInterpolationMat(rxLoc,'Fx')
Qfy = M3.getInterpolationMat(rxLoc,'Fy')
Qfz = M3.getInterpolationMat(rxLoc,'Fz')In [20]:
Bxr = np.reshape(Qfx*B, (size(xr), size(yr)), order='F')
Byr = np.reshape(Qfy*B, (size(xr), size(yr)), order='F')
Bzr = np.reshape(Qfz*B, (size(xr), size(yr)), order='F')
H0 = Box/mu0
flag = 'secondary'
if flag=='secondary':
Bxr = Bxr-Box
# Bxra, Byra, Bzra = MagSphereAnalFun(X, Y, Z, 100, 0., 0., 0., mu0, mu0*(1+chiblk), H0, flag)
Bxra, Byra, Bzra = MagSphereAnalFunA(X, Y, Z, 100., 0., 0., 0., chiblk, np.array([1., 0., 0.]), flag)
Bxra = np.reshape(Bxra, (size(xr), size(yr)), order='F')
Byra = np.reshape(Byra, (size(xr), size(yr)), order='F')
Bzra = np.reshape(Bzra, (size(xr), size(yr)), order='F')100.0 kang
In [22]:
figsize(10, 4)
plot(Utils.mkvc(Bxra))
plot(Utils.mkvc(Bxr), 'k:')
plot(Utils.mkvc(Byra))
plot(Utils.mkvc(Byr), 'k:')
plot(Utils.mkvc(Bzra))
plot(Utils.mkvc(Bzr), 'k:')Out [22]:
[<matplotlib.lines.Line2D at 0xa11f550>]
In [24]:
fig, ax = subplots(3,2, figsize = (10,15))
dat1 = ax[0,0].imshow(Bxr); fig.colorbar(dat1, ax=ax[0,0])
dat2 = ax[0,1].imshow(Bxra); fig.colorbar(dat2, ax=ax[0,1])
dat3 = ax[1,0].imshow(Byr); fig.colorbar(dat3, ax=ax[1,0])
dat4 = ax[1,1].imshow(Byra); fig.colorbar(dat4, ax=ax[1,1])
dat5 = ax[2,0].imshow(Bzr); fig.colorbar(dat5, ax=ax[2,0])
dat6 = ax[2,1].imshow(Bzra); fig.colorbar(dat6, ax=ax[2,1])Out [24]:
<matplotlib.colorbar.Colorbar instance at 0x000000001244C608>
In [25]:
id = 21
fig, axes = subplots(1,3, figsize=(14,5))
epsx = np.linalg.norm(Utils.mkvc(Bxr))*1e-6
epsy = np.linalg.norm(Utils.mkvc(Byr))*1e-6
epsz = np.linalg.norm(Utils.mkvc(Bzr))*1e-6
axes[0].plot(Y[:,id], Bxra[:,id], 'b', Y[:,id], Bxr[:,id], 'r.')
axes[1].plot(Y[:,id], Byra[:,id], 'b', Y[:,id], Byr[:,id], 'r.')
axes[2].plot(Y[:,id], Bzra[:,id], 'b', Y[:,id], Bzr[:,id], 'r.')
print X[:,1][-285. -285. -285. -285. -285. -285. -285. -285. -285. -285. -285. -285. -285. -285. -285. -285. -285. -285. -285. -285. -285. -285. -285. -285. -285. -285. -285. -285. -285. -285. -285. -285. -285. -285. -285. -285. -285. -285. -285. -285. -285.]
In [26]:
fig, axes = subplots(1,3, figsize=(14,5))
epsx = np.linalg.norm(Utils.mkvc(Bxr))*1e-6
epsy = np.linalg.norm(Utils.mkvc(Byr))*1e-6
epsz = np.linalg.norm(Utils.mkvc(Bzr))*1e-6
axes[0].plot(Y[:,1], abs((Bxr[:,1]-Bxra[:,1])/(Bxra[:,1]+epsx)), 'r.')
axes[1].plot(Y[:,1], abs((Byr[:,1]-Byra[:,1])/(Byra[:,1]+epsy)), 'r.')
axes[2].plot(Y[:,1], abs((Bzr[:,1]-Bzra[:,1])/(Bzra[:,1]+epsz)), 'r.')Out [26]:
[<matplotlib.lines.Line2D at 0x139014e0>]