In [1]:
import SimPEG as simpeg
from SimPEG import NSEM
from glob import glob
import numpy as np, sys, matplotlib.pyplot as plt
# sys.path.append('/home/gudni/Dropbox/Work/UBCwork/SyntheticModels/SynGeothermalStructures/ThesisModels')
# import synhelpFunc

In [2]:
def convergeCurves(resList):
    its  = np.array([res['iter'] for res in resList]).T
    ind = np.argsort(its)
    phid = np.array([res['phi_d'] for res in resList]).T
    try:
        phim = np.array([res['phi_m'] for res in resList]).T
    except:
        phim = np.array([res['phi_ms'] for res in resList]).T + np.array([res['phi_mx'] for res in resList]).T + np.array([res['phi_my'] for res in resList]).T + np.array([res['phi_mz'] for res in resList]).T     
    
    x = np.arange(len(its))
    
    fig, ax1 = plt.subplots()
    ax1.semilogy(x,phid[ind],'bx--')
    ax1.set_ylabel('phi_d', color='b')
    plt.hlines(len(resList[0]['dpred'])*.75,0,len(x),colors='g',linestyles='-.')
    for tl in ax1.get_yticklabels():
        tl.set_color('b')
    ax2 = ax1.twinx()          
    ax2.semilogy(x,phim[ind],'rx--',)
    ax2.set_ylabel('phi_m', color='r')
    for tl in ax2.get_yticklabels():
        tl.set_color('r')
    plt.show()
    
def tikanovCurve(resList):
    its  = np.array([res['iter'] for res in resList]).T
    ind = np.argsort(its)
    phid = np.array([res['phi_d'] for res in resList]).T
    phim = np.array([res['phi_m'] for res in resList]).T
    x = np.arange(len(its))
    fig, ax1 = plt.subplots()
    ax1.loglog(phim[ind],phid[ind],'bx--')
    ax1.set_ylabel('phi_d')
    ax1.set_xlabel('phi_m')
    plt.hlines(len(resList[0]['dpred'])*.75,np.min(phim),np.max(phim),colors='g',linestyles='-.')
    plt.show()
    
def allconvergeCurves(resList):
    its  = np.array([res['iter'] for res in resList]).T
    ind = np.argsort(its)
    phid = np.array([res['phi_d'] for res in resList]).T
    phim = np.array([res['phi_m'] for res in resList]).T
    phims = np.array([res['phi_ms'] for res in resList]).T
    phimx = np.array([res['phi_mx'] for res in resList]).T
    phimy = np.array([res['phi_my'] for res in resList]).T
    phimz = np.array([res['phi_mz'] for res in resList]).T
    x = np.arange(len(its))
    fig, ax1 = plt.subplots()
    ax1.semilogy(x,phid[ind],'bx--',label='phid')
    ax1.set_ylabel('phi_d', color='b')
    plt.hlines(len(resList[0]['dpred'])*.75,0,len(x),colors='g',linestyles='-.')
    for tl in ax1.get_yticklabels():
        tl.set_color('b')         
    ax1.semilogy(x,phim[ind],'gx--',label='phim')
    ax1.semilogy(x,phims[ind],'y,--',label='phims')
    ax1.semilogy(x,phimx[ind],'r.--',label='phimx')
    ax1.semilogy(x,phimy[ind],'r+--',label='phimy')
    ax1.semilogy(x,phimz[ind],'r*--',label='phimz')
    
    plt.legend()
    plt.show()

def loadInversionMakeVTRFiles(dirStr,mesh,mapping):
    temp = [np.load(f) for f in glob(dirStr+'/*Inversion*.npz')]
    iterResults = [i if len(i.keys()) > 1 else i['arr_0'].tolist() for i in temp ]
    # Make the vtk models
    for it in iterResults:
        mesh.writeVTK(dirStr+'/recoveredMod_{:s}_it{:.0f}.vtr'.format(dirStr,int(it['iter'])),{'S/m':mapping*it['m']})
    return iterResults

In [3]:
# Load the model
mesh, modDict = simpeg.Mesh.TensorMesh.readVTK('nsmesh_GKRCoarseHKPK1.vtr')
sigma = modDict['S/m']

In [4]:
# Make the mapping
active = sigma != 1e-8
actMap = simpeg.Maps.InjectActiveCells(mesh, active, np.log(1e-8), nC=mesh.nC)
mappingExpAct = simpeg.Maps.ExpMap(mesh) * actMap

In [5]:
# Load the data
drecAll = np.load('MTdataStArr_nsmesh_GKRHKPK1.npy')

run1


In [54]:
run1Files = loadInversionMakeVTRFiles('run1',mesh,mappingExpAct)

In [ ]:


In [55]:
ls run1


001-InversionModel-2016-06-21-09-50.npzB  findDiam_inversion.py
001-InversionModel-2016-06-21-14-09.npz   recoveredMod_run1_it10.vtr
002-InversionModel-2016-06-21-14-09.npz   recoveredMod_run1_it11.vtr
003-InversionModel-2016-06-21-14-09.npz   recoveredMod_run1_it12.vtr
004-InversionModel-2016-06-21-14-09.npz   recoveredMod_run1_it13.vtr
005-InversionModel-2016-06-21-14-09.npz   recoveredMod_run1_it14.vtr
006-InversionModel-2016-06-21-14-09.npz   recoveredMod_run1_it15.vtr
007-InversionModel-2016-06-21-14-09.npz   recoveredMod_run1_it16.vtr
008-InversionModel-2016-06-21-14-09.npz   recoveredMod_run1_it17.vtr
009-InversionModel-2016-06-21-14-09.npz   recoveredMod_run1_it18.vtr
010-InversionModel-2016-06-21-14-09.npz   recoveredMod_run1_it19.vtr
011-InversionModel-2016-06-21-14-09.npz   recoveredMod_run1_it1.vtr
012-InversionModel-2016-06-21-14-09.npz   recoveredMod_run1_it20.vtr
013-InversionModel-2016-06-21-14-09.npz   recoveredMod_run1_it21.vtr
014-InversionModel-2016-06-21-14-09.npz   recoveredMod_run1_it22.vtr
015-InversionModel-2016-06-21-14-09.npz   recoveredMod_run1_it23.vtr
016-InversionModel-2016-06-21-14-09.npz   recoveredMod_run1_it2.vtr
017-InversionModel-2016-06-21-14-09.npz   recoveredMod_run1_it3.vtr
018-InversionModel-2016-06-21-14-09.npz   recoveredMod_run1_it4.vtr
019-InversionModel-2016-06-21-14-09.npz   recoveredMod_run1_it5.vtr
020-InversionModel-2016-06-21-14-09.npz   recoveredMod_run1_it6.vtr
021-InversionModel-2016-06-21-14-09.npz   recoveredMod_run1_it7.vtr
022-InversionModel-2016-06-21-14-09.npz   recoveredMod_run1_it8.vtr
023-InversionModel-2016-06-21-14-09.npz   recoveredMod_run1_it9.vtr

In [56]:
%matplotlib inline
convergeCurves(run1Files)



In [47]:
[res['iter'] for res in run1Files]


Out[47]:
[10, 16, 13, 2, 1, 3, 9, 4, 14, 11, 17, 6, 12, 8, 15, 7, 5]

In [48]:
%matplotlib qt
sys.path.append('/home/gudni/Dropbox/code/python/MTview/')
import interactivePlotFunctions as iPf

In [49]:
finData = NSEM.Data(survey,run1Files[np.argmax([it['iter'] for it in run1Files])]['dpred']).toRecArray('Complex')

In [53]:
%matplotlib notebook
iPf.MTinteractiveMap([dUse.toRecArray('Complex'),finData])


Warning: Cannot change to a different GUI toolkit: notebook. Using qt instead.
Out[53]:
<interactivePlotFunctions.MTinteractiveMap at 0x7fb63ef88f10>

In [19]:



Out[19]:
array([ -1.12913682,  -1.0547609 ,  -0.91376578, ...,  20.59292622,
        21.43811444,  26.946862  ])

run2


In [13]:
run2Files = loadInversionMakeVTRFiles('run2',mesh,mappingExpAct)

In [14]:
%matplotlib inline
convergeCurves(run2Files)



In [ ]:
finData = NSEM.Data(survey,run2Files[0]['dpred']).toRecArray('Complex')