Fix examples folder

This commit is contained in:
seogi
2014-02-27 09:12:54 -08:00
parent 3cba7845ca
commit 751d7098b6
4 changed files with 486 additions and 7 deletions
+1 -1
View File
@@ -100,7 +100,7 @@ Since most materials in the earth have lower permeability than \\(\\mu_0\\), us
Since we compute secondary field based on the earth field, which can be different from different locations in the world, we can expect different anomalous responses in different locations in the earth. For instance, assume we have two susceptible spheres, which are exactly same. However, anomalous responses in Seoul and Vancouver are going to be different.
.. plot :: /home/seogi/Documents/simpegpf/docs/figures/figure1.py
.. plot :: examples/Mag_back_1.py
Since we can measure total fields ( \\(\\vec{B}\\)), and usually have reasonably accurate earth field (\\(\\vec{B}_0\\)), we can compute anmalous fields, \\(\\vec{B}_s\\) from our observed data. If you want to download earth magnetic fields at specific location see this website (`noaa <http://www.ngdc.noaa.gov/geomag-web/>`_).
+47
View File
@@ -0,0 +1,47 @@
from simpegPF.MagAnalytics import MagSphereAnalFunA, IDTtoxyz
from SimPEG import *
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable
xr = np.linspace(-300, 300, 41)
yr = np.linspace(-300, 300, 41)
X, Y = np.meshgrid(xr, yr)
Z = np.ones((np.size(xr), np.size(yr)))*150
# Bz component at Korea
inckr = -8. + 3/60
deckr = 54. + 9/60
btotkr = 50898.6
Bokr = IDTtoxyz(inckr, deckr, btotkr)
bx,by,bz = MagSphereAnalFunA(X, Y, Z,100.,0.,0.,0.,0.01,Bokr,'secondary')
Bzkr = np.reshape(bz, (np.size(xr), np.size(yr)), order='F')
# Bz component at Canada
incca = 16. + 49/60
decca = 70. + 19/60
btotca = 54692.1
Boca = IDTtoxyz(incca, decca, btotca)
bx,by,bz = MagSphereAnalFunA(X, Y, Z,100.,0.,0.,0.,0.01,Boca,'secondary')
Bzca = np.reshape(bz, (np.size(xr), np.size(yr)), order='F')
fig = plt.figure( figsize = (14,5) )
ax1 = plt.subplot(121)
dat1 = plt.imshow(Bzkr, extent=[min(xr), max(xr), min(yr), max(yr)]);
divider = make_axes_locatable(ax1)
cax1 = divider.append_axes("right", size="5%", pad=0.05)
ax1.set_xlabel('East-West (m)'); ax1.set_ylabel('South-North (m)')
plt.colorbar(dat1, cax=cax1)
ax1.set_title('$B_z$ field at Seoul, South Korea')
ax2 = plt.subplot(122)
dat2 = plt.imshow(Bzca, extent=[min(xr), max(xr), min(yr), max(yr)]);
divider = make_axes_locatable(ax2)
cax2 = divider.append_axes("right", size="5%", pad=0.05)
ax2.set_xlabel('East-West (m)'); ax2.set_ylabel('South-North (m)')
plt.colorbar(dat2, cax=cax2)
ax2.set_title('$B_z$ field at Vancouver, Canada')
plt.show()
+38 -6
View File
@@ -1,23 +1,55 @@
import unittest
from SimPEG import *
import matplotlib.pyplot as plt
import simpegPF as PF
class MagProblemTests(unittest.TestCase):
def setUp(self):
M = Mesh.TensorMesh([10,10])
mod = Model.LogModel(M)
prob = PF.Mag.MagProblem(M, mod, None)
hxind = ((5,25,1.3),(41, 12.5),(5,25,1.3))
hyind = ((5,25,1.3),(41, 12.5),(5,25,1.3))
hzind = ((5,25,1.3),(40, 12.5),(5,25,1.3))
hx, hy, hz = Utils.meshTensors(hxind, hyind, hzind)
M = Mesh.TensorMesh([hx, hy, hz], [-hx.sum()/2,-hy.sum()/2,-hz.sum()/2])
chibkg = 0.
chiblk = 0.01
chi = np.ones(M.nC)*chibkg
sph_ind = PF.MagAnalytics.spheremodel(M, 0., 0., 0., 100)
chi[sph_ind] = chiblk
model = PF.BaseMag.BaseMagModel(M)
prob = PF.Magnetics.MagneticsDiffSecondary(M, model)
self.prob = prob
self.M = M
self.chi = chi
def test_forward(self):
passed = True
self.assertTrue(passed)
def test_anal_forward(self):
data = PF.BaseMag.BaseMagData()
data.setBackgroundField(x=1., y=1., z=0.)
xr = np.linspace(-300, 300, 41)
yr = np.linspace(-300, 300, 41)
X, Y = np.meshgrid(xr, yr)
Z = np.ones((xr.size, yr.size))*150
rxLoc = np.c_[Utils.mkvc(X), Utils.mkvc(Y), Utils.mkvc(Z)]
data.rxLoc = rxLoc
self.prob.pair(data)
B = self.prob.fields(self.chi)
bxa,bya,bza = PF.MagAnalytics.MagSphereAnalFunA(rxLoc[:,0],rxLoc[:,1],rxLoc[:,2],100.,0.,0.,0.,0.01,np.array([1.,1.,0.]),'secondary')
dpred = data.projectFieldsAsVector(B)
err = np.linalg.norm(dpred-np.r_[bxa, bya, bza])/np.linalg.norm(np.r_[bxa, bya, bza])
if err > 0.05:
raise Exception('Anaytic test is failed T.T')
else:
print "Anaytic test is passed"
pass
if __name__ == '__main__':
unittest.main()
File diff suppressed because one or more lines are too long