|
@@ -17,7 +17,8 @@ from matplotlib.ticker import FormatStrFormatter
|
17
|
17
|
from matplotlib.colors import Normalize
|
18
|
18
|
|
19
|
19
|
import cmocean
|
20
|
|
-from akvo.tressel.lemma_yaml import *
|
|
20
|
+from akvo.tressel.lemma_yaml import *
|
|
21
|
+from akvo.tressel import nonlinearinv as nl
|
21
|
22
|
|
22
|
23
|
import pandas as pd
|
23
|
24
|
|
|
@@ -28,7 +29,7 @@ def buildKQT(K0,tg,T2Bins):
|
28
|
29
|
nlay, nq = np.shape(K0)
|
29
|
30
|
nt2 = len(T2Bins)
|
30
|
31
|
nt = len(tg)
|
31
|
|
- KQT = np.zeros( ( nq*nt,nt2*nlay) )
|
|
32
|
+ KQT = np.zeros( ( nq*nt,nt2*nlay), dtype=np.complex128 )
|
32
|
33
|
for iq in range(nq):
|
33
|
34
|
for it in range(nt):
|
34
|
35
|
for ilay in range(nlay):
|
|
@@ -87,7 +88,8 @@ def loadK0(fname):
|
87
|
88
|
K0 = yaml.load(f, Loader=yaml.Loader)
|
88
|
89
|
K = catLayers(K0.K0)
|
89
|
90
|
ifaces = np.array(K0.Interfaces.data)
|
90
|
|
- return ifaces, np.abs(K)
|
|
91
|
+ return ifaces, K
|
|
92
|
+ #return ifaces, np.abs(K)
|
91
|
93
|
|
92
|
94
|
|
93
|
95
|
|
|
@@ -131,12 +133,15 @@ def main():
|
131
|
133
|
for ik in range(1, len(K0)):
|
132
|
134
|
K0[0] = np.concatenate( (K0[0].T, K0[ik].T) ).T
|
133
|
135
|
K0 = K0[0]
|
134
|
|
- #plt.matshow(K0)
|
|
136
|
+
|
|
137
|
+ #plt.matshow(np.real(K0))
|
|
138
|
+ #plt.show()
|
|
139
|
+ #exit()
|
135
|
140
|
|
136
|
141
|
###################
|
137
|
142
|
# VERY Simple DOI #
|
138
|
|
- maxq = np.argmax(K0, axis=1)
|
139
|
|
- maxK = .1 * K0[ np.arange(0,len(ifaces)-1), maxq ] # 10% water is arbitrary
|
|
143
|
+ maxq = np.argmax(np.abs(K0), axis=1)
|
|
144
|
+ maxK = .1 * np.abs(K0)[ np.arange(0,len(ifaces)-1), maxq ] # 10% water is arbitrary
|
140
|
145
|
SNR = maxK / (VS[0][0])
|
141
|
146
|
|
142
|
147
|
#SNR[SNR>1] = 1
|
|
@@ -163,18 +168,60 @@ def main():
|
163
|
168
|
# Build full kernel
|
164
|
169
|
###############################################
|
165
|
170
|
T2Bins = np.logspace( np.log10(cont["T2Bins"]["low"]), np.log10(cont["T2Bins"]["high"]), cont["T2Bins"]["number"], endpoint=True, base=10)
|
166
|
|
- KQT = buildKQT(K0,tg,T2Bins)
|
167
|
|
-
|
|
171
|
+ KQT = np.real(buildKQT(np.abs(K0),tg,T2Bins))
|
|
172
|
+
|
|
173
|
+ # model resolution matrix
|
|
174
|
+ np.linalg.svd(KQT)
|
|
175
|
+
|
|
176
|
+ exit()
|
|
177
|
+
|
168
|
178
|
###############################################
|
169
|
|
- # Invert
|
|
179
|
+ # Linear Inversion
|
170
|
180
|
###############################################
|
171
|
181
|
print("Calling inversion", flush=True)
|
172
|
|
- inv, ibreak, errn, phim, phid, mkappa = logBarrier(KQT, np.ravel(V), T2Bins, "lcurve", MAXITER=150, sigma=np.ravel(VS), alpha=1e6, smooth="Smallest" )
|
|
182
|
+ inv, ibreak, errn, phim, phid, mkappa, Wd, Wm, alphastar = logBarrier(KQT, np.ravel(V), T2Bins, "lcurve", MAXITER=150, sigma=np.ravel(VS), alpha=1e6, smooth="Smallest" )
|
173
|
183
|
|
|
184
|
+ ###############################################
|
|
185
|
+ # Non-linear refinement!
|
|
186
|
+ ###############################################
|
|
187
|
+
|
|
188
|
+ KQTc = buildKQT(K0, tg, T2Bins)
|
|
189
|
+ prec = np.abs(np.dot(KQTc, inv))
|
|
190
|
+ phidc = np.linalg.norm(np.dot(Wd,prec-np.ravel(V)))**2
|
|
191
|
+ #PREc = np.reshape( prec, np.shape(V) )
|
|
192
|
+ print("PHID linear=", errn, "PHID complex=", phidc/len(np.ravel(V)))
|
|
193
|
+
|
|
194
|
+ res = nl.nonlinearinversion(inv, Wd, KQTc, np.ravel(V), Wm, alphastar )
|
|
195
|
+ if res.success == True:
|
|
196
|
+ INVc = np.reshape(res.x, (len(ifaces)-1,cont["T2Bins"]["number"]) )
|
|
197
|
+ prec = np.abs(np.dot(KQTc, res.x))
|
|
198
|
+ phidc = np.linalg.norm(np.dot(Wd,prec-np.ravel(V)))**2
|
|
199
|
+ #PREc = np.reshape( prec, np.shape(V) )
|
|
200
|
+ print("PHID linear=", errn, "PHID nonlinear=", phidc/len(np.ravel(V)))
|
|
201
|
+
|
|
202
|
+ # Perform second fit around results of first
|
|
203
|
+ res = nl.nonlinearinversion(res.x, Wd, KQTc, np.ravel(V), Wm, alphastar )
|
|
204
|
+ if res.success == True:
|
|
205
|
+ INVc = np.reshape(res.x, (len(ifaces)-1,cont["T2Bins"]["number"]) )
|
|
206
|
+ prec = np.abs(np.dot(KQTc, res.x))
|
|
207
|
+ phidc = np.linalg.norm(np.dot(Wd,prec-np.ravel(V)))**2
|
|
208
|
+ #PREc = np.reshape( prec, np.shape(V) )
|
|
209
|
+ print("PHID linear=", errn, "PHID nonlinear=", phidc/len(np.ravel(V)))
|
|
210
|
+
|
|
211
|
+ #plt.matshow(INVc)
|
|
212
|
+ #KQTc = buildKQT(K0,tg,T2Bins)
|
|
213
|
+
|
|
214
|
+ #plt.matshow(PREc, cmap='Blues')
|
|
215
|
+ #plt.gca().set_title("complex predicted")
|
|
216
|
+ #plt.colorbar()
|
174
|
217
|
|
175
|
218
|
###############################################
|
176
|
219
|
# Appraise
|
177
|
220
|
###############################################
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
|
178
|
225
|
|
179
|
226
|
pre = np.dot(KQT,inv)
|
180
|
227
|
PRE = np.reshape( pre, np.shape(V) )
|
|
@@ -192,8 +239,8 @@ def main():
|
192
|
239
|
plt.gca().set_title("observed")
|
193
|
240
|
plt.colorbar()
|
194
|
241
|
|
|
242
|
+
|
195
|
243
|
T2Bins = np.append( T2Bins, T2Bins[-1] + (T2Bins[-1]-T2Bins[-2]) )
|
196
|
|
-
|
197
|
244
|
INV = np.reshape(inv, (len(ifaces)-1,cont["T2Bins"]["number"]) )
|
198
|
245
|
|
199
|
246
|
#alphas = np.tile(SNR, (len(T2Bins)-1,1))
|
|
@@ -205,6 +252,8 @@ def main():
|
205
|
252
|
|
206
|
253
|
#greys = np.full((*(INV.T).shape, 3), 70, dtype=np.uint8)
|
207
|
254
|
|
|
255
|
+ ############## LINEAR RESULT ##########################
|
|
256
|
+
|
208
|
257
|
Y,X = meshgrid( ifaces, T2Bins )
|
209
|
258
|
fig = plt.figure( figsize=(pc2in(20.0),pc2in(22.)) )
|
210
|
259
|
ax1 = fig.add_axes( [.2,.15,.6,.7] )
|
|
@@ -242,6 +291,48 @@ def main():
|
242
|
291
|
|
243
|
292
|
plt.savefig("akvoInversion.pdf")
|
244
|
293
|
|
|
294
|
+
|
|
295
|
+ ############## NONLINEAR RESULT ##########################
|
|
296
|
+
|
|
297
|
+ Y,X = meshgrid( ifaces, T2Bins )
|
|
298
|
+ fig = plt.figure( figsize=(pc2in(20.0),pc2in(22.)) )
|
|
299
|
+ ax1 = fig.add_axes( [.2,.15,.6,.7] )
|
|
300
|
+ im = ax1.pcolor(X, Y, INVc.T, cmap=cmocean.cm.tempo) #cmap='viridis')
|
|
301
|
+ #im = ax1.pcolor(X[0:SNRidx,:], Y[0:SNRidx,:], INV.T[0:SNRidx,:], cmap=cmocean.cm.tempo) #cmap='viridis')
|
|
302
|
+ #im = ax1.pcolor(X[SNRidx::,:], Y[SNRidx::,:], INV.T[SNRidx::,:], cmap=cmocean.cm.tempo, alpha=.5) #cmap='viridis')
|
|
303
|
+ #im = ax1.pcolormesh(X, Y, INV.T, alpha=alphas) #, cmap=cmocean.cm.tempo) #cmap='viridis')
|
|
304
|
+ #im = ax1.pcolormesh(X, Y, INV.T, alpha=alphas) #, cmap=cmocean.cm.tempo) #cmap='viridis')
|
|
305
|
+ #ax1.axhline( y=ifaces[SNRidx], xmin=T2Bins[0], xmax=T2Bins[-1], color='black' )
|
|
306
|
+ im.set_edgecolor('face')
|
|
307
|
+ ax1.set_xlim( T2Bins[0], T2Bins[-1] )
|
|
308
|
+ ax1.set_ylim( ifaces[-1], ifaces[0] )
|
|
309
|
+ cb = plt.colorbar(im, label = u"PWC (m$^3$/m$^3$)") #, format='%1.1f')
|
|
310
|
+ cb.locator = MaxNLocator( nbins = 4)
|
|
311
|
+ cb.ax.yaxis.set_offset_position('left')
|
|
312
|
+ cb.update_ticks()
|
|
313
|
+
|
|
314
|
+ ax1.set_xlabel(u"$T_2^*$ (ms)")
|
|
315
|
+ ax1.set_ylabel(u"depth (m)")
|
|
316
|
+
|
|
317
|
+ ax1.get_xaxis().set_major_formatter(FormatStrFormatter('%1.0f'))
|
|
318
|
+ ax1.get_yaxis().set_major_formatter(FormatStrFormatter('%1.0f'))
|
|
319
|
+ ax1.xaxis.set_major_locator( MaxNLocator(nbins = 4) )
|
|
320
|
+
|
|
321
|
+ #ax1.xaxis.set_label_position('top')
|
|
322
|
+
|
|
323
|
+ ax2 = ax1.twiny()
|
|
324
|
+ ax2.plot( np.sum(INVc, axis=1), (ifaces[1:]+ifaces[0:-1])/2 , color='red' )
|
|
325
|
+ ax2.set_xlabel(u"total water (m$^3$/m$^3$)")
|
|
326
|
+ ax2.set_ylim( ifaces[-1], ifaces[0] )
|
|
327
|
+ ax2.xaxis.set_major_locator( MaxNLocator(nbins = 3) )
|
|
328
|
+ ax2.get_xaxis().set_major_formatter(FormatStrFormatter('%0.2f'))
|
|
329
|
+ #ax2.axhline( y=ifaces[SNRidx], xmin=0, xmax=1, color='black', linestyle='dashed' )
|
|
330
|
+ #ax2.xaxis.set_label_position('bottom')
|
|
331
|
+ fig.suptitle("Non linear inversion")
|
|
332
|
+ plt.savefig("akvoInversionNL.pdf")
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
|
245
|
336
|
#############
|
246
|
337
|
# water plot#
|
247
|
338
|
|
|
@@ -265,7 +356,7 @@ def main():
|
265
|
356
|
ax.set_ylim( ifaces[-1], ifaces[0] )
|
266
|
357
|
ax.set_xlim( 0, ax.get_xlim()[1] )
|
267
|
358
|
|
268
|
|
- ax.axhline( y=ifaces[SNRidx], xmin=0, xmax=1, color='black', linestyle='dashed' )
|
|
359
|
+ #ax.axhline( y=ifaces[SNRidx], xmin=0, xmax=1, color='black', linestyle='dashed' )
|
269
|
360
|
|
270
|
361
|
plt.savefig("akvoInversionWC.pdf")
|
271
|
362
|
plt.legend()
|