mirror of
https://github.com/wassname/simpeg.git
synced 2026-08-14 12:50:10 +08:00
Separate out the input files.
This commit is contained in:
@@ -1,33 +1,12 @@
|
||||
#%%
|
||||
from SimPEG import *
|
||||
import simpegPF as PF
|
||||
import pylab as plt
|
||||
|
||||
import os
|
||||
|
||||
#home_dir = 'C:\Users\dominiquef.MIRAGEOSCIENCE\Documents\GIT\SimPEG\simpegpf\simpegPF\Dev'
|
||||
#home_dir = 'C:\\Users\\dominiquef.MIRAGEOSCIENCE\\ownCloud\\Research\\Modelling\\Synthetic\\Nut_Cracker\\Induced_MAG3C'
|
||||
home_dir = '.\\'
|
||||
#home_dir = '.\\'
|
||||
|
||||
inpfile = 'PYMAG3D_inv.inp'
|
||||
|
||||
dsep = '\\'
|
||||
os.chdir(home_dir)
|
||||
## New scripts to be added to basecode
|
||||
#from fwr_MAG_data import fwr_MAG_data
|
||||
#from read_MAGfwr_inp import read_MAGfwr_inp
|
||||
plt.close('all')
|
||||
#%%
|
||||
# Read input file
|
||||
[mshfile, obsfile, topofile, mstart, mref, magfile, wgtfile, chi, alphas, bounds, lpnorms] = PF.Magnetics.read_MAGinv_inp(home_dir + dsep + inpfile)
|
||||
|
||||
# Load mesh file
|
||||
mesh = Mesh.TensorMesh.readUBC(mshfile)
|
||||
#mesh = Utils.meshutils.readUBCTensorMesh(mshfile)
|
||||
|
||||
# Load in observation file
|
||||
survey = PF.Magnetics.readUBCmagObs(obsfile)
|
||||
driver = PF.MagneticsIO.MagneticsDriver_Inv('PYMAG3D_inv.inp')
|
||||
mesh = driver.mesh
|
||||
survey = driver.survey
|
||||
|
||||
rxLoc = survey.srcField.rxList[0].locs
|
||||
d = survey.dobs
|
||||
@@ -38,48 +17,24 @@ ndata = survey.srcField.rxList[0].locs.shape[0]
|
||||
beta_in = 1e+5
|
||||
eps_p = 1e-4
|
||||
eps_q = 1e-4
|
||||
# Load in topofile or create flat surface
|
||||
if topofile == 'null':
|
||||
|
||||
# All active
|
||||
actv = np.asarray(range(mesh.nC))
|
||||
|
||||
else:
|
||||
|
||||
topo = np.genfromtxt(topofile,skip_header=1)
|
||||
# Find the active cells
|
||||
actv = PF.Magnetics.getActiveTopo(mesh,topo,'N')
|
||||
|
||||
actv = driver.activeCells
|
||||
nC = len(actv)
|
||||
|
||||
# Create active map to go from reduce set to full
|
||||
actvMap = Maps.ActiveCells(mesh, actv, -100)
|
||||
actvMap = Maps.InjectActiveCells(mesh, actv, -100)
|
||||
|
||||
# Creat reduced identity map
|
||||
idenMap = Maps.IdentityMap(nP = nC)
|
||||
|
||||
# Load starting model file
|
||||
if isinstance(mstart, float):
|
||||
|
||||
mstart = np.ones(nC) * mstart
|
||||
else:
|
||||
mstart = Utils.meshutils.readUBCTensorModel(mstart,mesh)
|
||||
mstart = mstart[actv]
|
||||
mstart = driver.m0
|
||||
|
||||
# Load reference file
|
||||
if isinstance(mref, float):
|
||||
mref = np.ones(nC) * mref
|
||||
else:
|
||||
mref = Utils.meshutils.readUBCTensorModel(mref,mesh)
|
||||
mref = mref[actv]
|
||||
|
||||
mref = driver.mref
|
||||
|
||||
# Get magnetization vector for MOF
|
||||
if magfile=='DEFAULT':
|
||||
|
||||
M_xyz = PF.Magnetics.dipazm_2_xyz(np.ones(nC) * survey.srcField.param[1], np.ones(nC) * survey.srcField.param[2])
|
||||
|
||||
else:
|
||||
M_xyz = np.genfromtxt(magfile,delimiter=' \n',dtype=np.str,comments='!')
|
||||
M_xyz = driver.magnetizationModel
|
||||
|
||||
# Get index of the center
|
||||
midx = int(mesh.nCx/2)
|
||||
@@ -95,17 +50,15 @@ midy = int(mesh.nCy/2)
|
||||
PF.Magnetics.plot_obs_2D(rxLoc,d,'Observed Data')
|
||||
|
||||
#%% Run inversion
|
||||
prob = PF.Magnetics.MagneticIntegral(mesh, mapping = idenMap, actInd = actv)
|
||||
prob = PF.Magnetics.MagneticIntegral(mesh, mapping=idenMap, actInd=actv)
|
||||
prob.solverOpts['accuracyTol'] = 1e-4
|
||||
|
||||
#survey = Survey.LinearSurvey()
|
||||
survey.pair(prob)
|
||||
#survey.makeSyntheticData(data, std=0.01)
|
||||
#survey.dobs=d
|
||||
#survey.mtrue = model
|
||||
# Write out the predicted
|
||||
pred = prob.fields(mstart)
|
||||
PF.Magnetics.writeUBCobs(home_dir + dsep + 'Pred.dat',survey,pred)
|
||||
PF.Magnetics.writeUBCobs('Pred.dat', survey, pred)
|
||||
|
||||
wr = np.sum(prob.G**2.,axis=0)**0.5 / mesh.vol[actv]
|
||||
wr = ( wr/np.max(wr) )
|
||||
@@ -113,28 +66,28 @@ wr_out = actvMap * wr
|
||||
|
||||
plt.figure()
|
||||
ax = plt.subplot()
|
||||
mesh.plotSlice(wr_out, ax = ax, normal = 'Y', ind=midx ,clim = (-1e-3, wr.max()))
|
||||
mesh.plotSlice(wr_out, ax=ax, normal='Y', ind=midx ,clim=(-1e-3, wr.max()))
|
||||
plt.title('Distance weighting')
|
||||
plt.xlabel('x');plt.ylabel('z')
|
||||
plt.gca().set_aspect('equal', adjustable='box')
|
||||
|
||||
reg = Regularization.Simple(mesh, indActive = actv, mapping = idenMap)
|
||||
reg = Regularization.Simple(mesh, indActive=actv, mapping=idenMap)
|
||||
reg.mref = mref
|
||||
reg.wght = wr
|
||||
#reg.alpha_s = 1.
|
||||
|
||||
# Create pre-conditioner
|
||||
# Create pre-conditioner
|
||||
diagA = np.sum(prob.G**2.,axis=0) + beta_in*(reg.W.T*reg.W).diagonal()
|
||||
PC = Utils.sdiag(diagA**-1.)
|
||||
|
||||
|
||||
dmis = DataMisfit.l2_DataMisfit(survey)
|
||||
dmis.Wd = 1/wd
|
||||
opt = Optimization.ProjectedGNCG(maxIter=10,lower=0.,upper=1., maxIterCG= 20, tolCG = 1e-3)
|
||||
opt = Optimization.ProjectedGNCG(maxIter=10,lower=0.,upper=1., maxIterCG= 20, tolCG=1e-3)
|
||||
opt.approxHinv = PC
|
||||
|
||||
# opt = Optimization.InexactGaussNewton(maxIter=6)
|
||||
invProb = InvProblem.BaseInvProblem(dmis, reg, opt, beta = beta_in)
|
||||
invProb = InvProblem.BaseInvProblem(dmis, reg, opt, beta=beta_in)
|
||||
beta = Directives.BetaSchedule(coolingFactor=2, coolingRate=1)
|
||||
#betaest = Directives.BetaEstimate_ByEig()
|
||||
target = Directives.TargetMisfit()
|
||||
@@ -157,7 +110,7 @@ pred = prob.fields(mrec)
|
||||
#PF.Magnetics.plot_obs_2D(rxLoc,pred,wd,'Predicted Data')
|
||||
#PF.Magnetics.plot_obs_2D(rxLoc,(d-pred),wd,'Residual Data')
|
||||
|
||||
print "Final misfit:" + str(np.sum( ((d-pred)/wd)**2. ) )
|
||||
print "Final misfit:" + str(np.sum( ((d-pred)/wd)**2. ) )
|
||||
|
||||
#%% Plot out a section of the model
|
||||
|
||||
@@ -196,7 +149,7 @@ reg.mref = mref
|
||||
reg.wght = wr
|
||||
reg.eps_p = eps_p
|
||||
reg.eps_q = eps_q
|
||||
reg.norms = lpnorms
|
||||
reg.norms = driver.lpnorms
|
||||
|
||||
|
||||
diagA = np.sum(prob.G**2.,axis=0) + beta_in*(reg.W.T*reg.W).diagonal()
|
||||
@@ -234,7 +187,7 @@ pred = prob.fields(mrec)
|
||||
#%% Plot obs data
|
||||
PF.Magnetics.plot_obs_2D(rxLoc,pred,'Predicted Data')
|
||||
PF.Magnetics.plot_obs_2D(rxLoc,d,'Observed Data')
|
||||
print "Final misfit:" + str(np.sum( ((d-pred)/wd)**2. ) )
|
||||
print "Final misfit:" + str(np.sum( ((d-pred)/wd)**2. ) )
|
||||
#%% Plot out a section of the model
|
||||
|
||||
yslice = midx
|
||||
@@ -260,4 +213,7 @@ ax = plt.subplot(212)
|
||||
mesh.plotSlice(m_out, ax = ax, normal = 'Y', ind=yslice, clim = (mrec.min(), mrec.max()))
|
||||
plt.title('Cross Section')
|
||||
plt.xlabel('x');plt.ylabel('z')
|
||||
plt.gca().set_aspect('equal', adjustable='box')
|
||||
plt.gca().set_aspect('equal', adjustable='box')
|
||||
|
||||
|
||||
plt.show()
|
||||
|
||||
Reference in New Issue
Block a user