-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOT_Lib_Functions.py
97 lines (67 loc) · 4.3 KB
/
OT_Lib_Functions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# We make use of the software package OTlib.py, which implements the approach of Sambridge et al. (2022).
# https://github.com/msambridge/waveform-ot/tree/main
# Reference paper: Malcolm Sambridge, Andrew Jackson, y Andrew P Valentine,
# «Geophysical Inversion and Optimal Transport»,
# Geophysical Journal International 231, n.º 1 (21 de junio de 2022): 172-98,
# https://doi.org/10.1093/gji/ggac151.
# waveform-ot libraries
from Imported_Libraries import OTlib as OT
from Imported_Libraries import ricker_util as ru
# waveform-ot functions
# https://github.com/msambridge/waveform-ot/blob/main/Point_mass_demo_Fig_5.ipynb
# https://github.com/msambridge/waveform-ot/blob/main/Ricker_Figs_1_7.ipynb
def compute_OT(simulated_data, observed_data):
# choose grid to use
nugrid,ntgrid=40,512 # This is the discretization of the waveform window used to evaluated the density surface
lambdav = 1 #0.03 # This is the distance scale factor used to calculate the density function (eqn. 17 of Sambridge et al. (2
trange = [0, nx]
grid = (trange[0], trange[1], -1.0, 1.0, nugrid,ntgrid) # specify grid for fingerprint # -0.8, 1.2
# set up initial and final PDFs simple point masses
fx = np.linspace(0, nx*nz, nx*nz)
gx = np.linspace(0, nx*nz, nx*nz)
f = np.abs(simulated_data.T.flatten())
g = np.abs(observed_data.T.flatten())
wf_f, OT_pdf_f = ru.BuildOTobjfromWaveform(fx,f,grid,lambdav=lambdav)
wf_g, OT_pdf_g = ru.BuildOTobjfromWaveform(gx,g,grid,lambdav=lambdav)
#ru.fp.plot_LS(wf_f.dfield,wf_f,None,None,'Fingerprint of observed data','grey','grey',aspect=True)
#ru.fp.plot_LS(wf_g.dfield,wf_g,None,None,'Fingerprint of simulated data','grey','grey',aspect=True)
w_1 = ru.CalcWasserWaveform(OT_pdf_f, OT_pdf_g, wf_g, distfunc='W1', deriv=False, returnmarg=False)
w_2 = ru.CalcWasserWaveform(OT_pdf_f, OT_pdf_g, wf_g, distfunc='W1', deriv=False, returnmarg=False)
return (w_2)
def compute_OT_2(simulated_data, observed_data):
# choose grid to use
nugrid,ntgrid=40,512 # This is the discretization of the waveform window used to evaluated the density surface
lambdav = 1 #0.03 # This is the distance scale factor used to calculate the density function (eqn. 17 of Sambridge et al. (2
trange = [0, nx]
grid = (trange[0], trange[1], -1.0, 1.0, nugrid,ntgrid) # specify grid for fingerprint # -0.8, 1.2
fx = np.linspace(0, nx*nz, nx*nz)
gx = np.linspace(0, nx*nz, nx*nz)
f = observed_data.T.flatten()
g = simulated_data.T.flatten()
wf_f, OT_pdf_f = ru.BuildOTobjfromWaveform(fx,f,grid,lambdav=lambdav)
wf_g, OT_pdf_g = ru.BuildOTobjfromWaveform(gx,g,grid,lambdav=lambdav)
#ru.fp.plot_LS(wf_f.dfield,wf_f,None,None,'Fingerprint of observed data','grey','grey',aspect=True)
#ru.fp.plot_LS(wf_g.dfield,wf_g,None,None,'Fingerprint of simulated data','grey','grey',aspect=True)
w_1 = ru.CalcWasserWaveform(OT_pdf_f, OT_pdf_g, wf_g, distfunc='W1', deriv=False, returnmarg=False)
w_2 = ru.CalcWasserWaveform(OT_pdf_f, OT_pdf_g, wf_g, distfunc='W1', deriv=False, returnmarg=False)
return (w_2)
def compute_OT_3(simulated_data, observed_data):
w = 0
# choose grid to use
nugrid,ntgrid=40,512 # This is the discretization of the waveform window used to evaluated the density surface
lambdav = 1 #0.03 # This is the distance scale factor used to calculate the density function (eqn. 17 of Sambridge et al. (2
trange = [0, nx]
grid = (trange[0], trange[1], -1.0, 1.0, nugrid,ntgrid) # specify grid for fingerprint # -0.8, 1.2
for i in range(nx):
fx = np.linspace(0, nx, nx)
gx = np.linspace(0, nx, nx)
f = observed_data.T[:,i]
g = simulated_data.T[:,i]
wf_f, OT_pdf_f = ru.BuildOTobjfromWaveform(fx,f,grid,lambdav=lambdav)
wf_g, OT_pdf_g = ru.BuildOTobjfromWaveform(gx,g,grid,lambdav=lambdav)
#ru.fp.plot_LS(wf_f.dfield,wf_f,None,None,'Fingerprint of observed data','grey','grey',aspect=True)
#ru.fp.plot_LS(wf_g.dfield,wf_g,None,None,'Fingerprint of simulated data','grey','grey',aspect=True)
w_1 = ru.CalcWasserWaveform(OT_pdf_f, OT_pdf_g, wf_g, distfunc='W1', deriv=False, returnmarg=False)
w_2 = ru.CalcWasserWaveform(OT_pdf_f, OT_pdf_g, wf_g, distfunc='W1', deriv=False, returnmarg=False)
w = (w_2)
return w