Hypocentre location with a probabilistic approach¶

*Material adapted from: Igel, H., Geßele K., Seismic Inverse Problems: Probabilistic estimation of earthquake hypocenters, https://krischer.github.io/seismo_live_build/html/Seismic%20Inverse%20Problems/Earthquake%20Location/el_hypocenter_solution_wrapper.html*

In the previous part we located the hypocentre with an analytical approach, linearising with a Taylor series. Here we apply the probabilistic approach introduced by Albert Tarantola. In the probabilistic approach, model and data are represented as probability density functions (PDFs). In other words, the result is a set of solutions with given probabilities, so we can also guess many values at once.

As in the analytical approach, our observed data are the P arrival times, written as $\mathbf{d_{obs}}=\{t_1,t_2,t_3,t_4\}$. In this case we work in a 2D space with a lateral axis $X$ and a vertical axis $Z$. The model we look for is the hypocentre and the origin time, written as $\mathbf{m}=\{X,Z,T\}$. In this 2D case the forward equation is:

$$t_i=f_i(X,Z,T)=T+\frac{\sqrt{(X-x_i)^2-(Z-z_i)^2}}{v}$$

The solution as a PDF is called the marginal a posteriori probability, written $\sigma_m(X,Z,T)$:

$$ \sigma_m(X,Z,T) = k \; \rho_m(X,Z,T) \; \rho_d(t_1,t_2,t_3,t_4)\rvert_{t_i = f_i(X,Z,T)} $$

where the guesses as a PDF are the a priori information $\rho_m(X,Z,T)$, and $\rho_d(t_1,t_2,t_3,t_4)$ is the information on the observations:

$$ \rho_d(\mathbf{d}) = k\exp\Big(-\frac{1}{2} \sum_{i}\big(\frac{t_i - t_i^{obs}}{\sigma_i}\big)^2\Big) $$

$\mathbf{\sigma}$ ={$\sigma_1, \sigma_2, \sigma_3,\sigma_4$} are the variances describing the Gaussian uncertainty, and $k$ is a normalisation constant.

In this example, the guesses follow a uniform distribution between given lower and upper bounds.

Creating synthetic data¶

We use our own synthetic data: four stations with their coordinates, the uncertainty of the observed arrival times, the hypocentre, the origin time and the velocity:

In [1]:
import numpy as np

# Station coordinates                      # (original values)
station_x = np.array([ 5,10,15,25])      # x(km) = [ 5,10,15,25]
station_z = np.array([ 0, 0, 0, 0])      # z(km) = [ 0, 0, 0, 0]

# Uncertainty of the picked arrival times
uncertain_t = np.array([.5, .2, .4, .2]) # uncertainty (s) = [.5,.2,.4,.2]

# Hypocentre, origin time and P-wave velocity
source_x = 16                            # hypocentre x (km) = 16
source_z = 15                            # hypocentre z (km) = 15
origin_T = 17                            # origin time (s) = 17
v_exact  =  5                            # P-wave velocity (km/s) = 5

With the forward equation we then get the synthetic arrival times:

In [2]:
# compute the synthetic arrival times
t_obs = np.zeros(np.size(station_x))
for i in range(0,np.size(station_x)):  # loop over the stations
    t_obs[i] = origin_T + 1./v_exact * np.sqrt((station_x[i]-source_x)**2 + \
                                               (station_z[i]-source_z)**2)
print(t_obs)
[20.72021505 20.23109888 20.00665928 20.49857114]

Building the model space to explore¶

As explained above, we can guess many values within a given range. The guess points in this model space are sampled one by one. Because the distribution is uniform, we can simply use numpy.arange, with every value having the same probability (represented here by 1 in np.ones for simplicity):

In [3]:
# Model space to explore: (lower bound, upper bound, step)
space_x = np.arange( 0, 35, 1 )          # x coordinate (km): ( 0, 35, 0.5 )
space_z = np.arange( 0, 25, 1 )          # z coordinate (km): ( 0, 25, 0.5 )
space_T = np.arange(10, 30, 0.5)         # origin time (km): (10, 30, 0.25)

In the example above we guess the hypocentre x coordinate from 0 to 34 in steps of 1 (0, 1, 2, 3, ..., 34), the z coordinate from 0 to 24 in steps of 1 (0, 1, 2, 3, ..., 24) and the origin time from 10 to 30 in steps of 0.5 (10, 10.5, 11.0, ..., 33.5). The total number of guess points is 35 × 25 × 40 = 35,000. The model space for the hypocentre (space_x and space_z) can be visualised with np.meshgrid:

In [4]:
import matplotlib.pyplot as plt

space_x_grd, space_z_grd = np.meshgrid(space_x, space_z)

plt.scatter(space_x_grd, space_z_grd,color="grey", label="Model points")
plt.ylim(max(space_z)+1,-2)
plt.scatter(station_x,station_z-1,marker="v",\
            color="blue",s=50, label="Station")
plt.xlabel("Coordinate x")
plt.ylabel("Coordinate z")
plt.legend(loc="lower right")
plt.show()
No description has been provided for this image

To visualise the origin time as well, we can use a 3D projection:

In [5]:
import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure()
ax = fig.add_subplot(projection='3d')

space_x_grd, space_z_grd, space_T_grd = np.meshgrid(space_x, space_z, space_T)

ax.scatter(space_x_grd, space_z_grd, space_T_grd, alpha=.7, s=1)
ax.set_xlabel('X')
ax.set_ylabel('Z')
ax.set_zlabel('T')


plt.title("Ruang model dan sampel yang dieksplorasi")
plt.show()
No description has been provided for this image

Solving the hypocentre inversion¶

We compute the arrival times for each guess point in the model space ($X,Z,T$) with a for loop. For each point we compute the information on the observations ($\rho_d$):

In [6]:
from tqdm import tqdm #only for showing a progress bar

# Probabilistic hypocentre inversion
# matrix of ones with the size of the model space
sigM = np.ones([space_x.size, space_z.size, space_T.size]) # initialise the posterior PDF
# loop over the model space
for ix,X in enumerate(tqdm(space_x)): #use tqdm to show a progress bar
    for iz,Z in enumerate(space_z):
        for it,T in enumerate(space_T):
            for istat in range(np.size(station_x)):   # loop over the stations
                    
                # forward modelling
                t_calc = T + 1/v_exact * np.sqrt((X-station_x[istat])**2 + (Z-station_z[istat])**2)
                    
                # probability of each model point
                sigM[ix,iz,it] *= np.exp( -(t_calc-t_obs[istat])**2 / (2*uncertain_t[istat]**2))
                
100%|██████████████████████████████████████████████████████████████████████████████████████████████████| 35/35 [00:01<00:00, 34.28it/s]

Computing the marginal a posteriori probability¶

We now have a probability for every point of the explored model space. Next we compute the posterior PDF by summing over each axis and normalising:

In [7]:
# marginal a posteriori probability for x and z
# and for x and z separately
sigMxz = np.zeros([space_x.size, space_z.size])
sigMz = np.zeros([space_z.size])
sigMx = np.zeros([space_x.size])
for ix in range(space_x.size):
    sigMx[ix] = np.sum(sigM[ix, :, :])
    for iz in range(space_z.size):
        sigMz[iz] = np.sum(sigM[:, iz, :])
        sigMxz[ix,iz] = np.sum(sigM[ix, iz, :])
sigMx /= np.sum(sigMx)
sigMz /= np.sum(sigMz)

# marginal a posteriori probability for T
sigMT = np.zeros(space_T.size)
for it in range(space_T.size):
    sigMT[it] = np.sum(sigM[:, :, it])
sigMT /= np.sum(sigMT)

Plotting the result¶

The probabilistic approach gives a set of solutions, the marginal a posteriori probability computed above, rather than a single point as in the analytical method. The first plot is the marginal a posteriori PDF in X-Z, shown with plt.imshow after a transpose with .transpose():

In [8]:
%matplotlib inline

plt.imshow(sigMxz.transpose(), aspect='auto',extent=[space_x[0],space_x[-1],space_z[-1],space_z[0]]
          ,cmap = 'viridis', interpolation='none')
# true hypocentre
plt.plot(source_x, source_z,'r*', markersize=15,markerfacecolor='None',\
        markeredgewidth=1,label='true hypocenter')
plt.xlabel("X [km]")
plt.ylabel("Z [km]")
plt.scatter(station_x,station_z-1,marker="v",\
            color="blue",s=50, label="Station")
plt.ylim(max(space_z)+1,-2)
plt.title("Marginal a posteriori probability X-Z")
plt.colorbar()
plt.legend()
Out[8]:
<matplotlib.legend.Legend at 0x7f677f0e2910>
No description has been provided for this image

Where are the hypocentre and origin time with the highest probability?

We can use np.argmax and np.unravel_index to get the indices:

In [9]:
max_prob_index=np.unravel_index(sigM.argmax(), sigM.shape)
print(max_prob_index)
(16, 15, 14)

With these three indices we get the model parameters with the maximum probability:

In [10]:
x_prob_max=space_x[max_prob_index[0]]
z_prob_max=space_z[max_prob_index[1]]
T_prob_max=space_T[max_prob_index[2]]
print("Model dengan probabilitas tertinggi:")
print(x_prob_max, z_prob_max,T_prob_max)
print("Model sebenarnya")
print(source_x,source_z,origin_T)
Model dengan probabilitas tertinggi:
16 15 17.0
Model sebenarnya
16 15 17

Then we plot the result:

In [11]:
%matplotlib inline

plt.imshow(sigMxz.transpose(), aspect='auto',extent=[space_x[0],space_x[-1],space_z[-1],space_z[0]]
          ,cmap = 'viridis', interpolation='none')
# true hypocentre
plt.plot(source_x, source_z,'r*', markersize=15,markerfacecolor='None',\
        markeredgewidth=1,label='true hypocenter')
# hypocentre with the maximum probability
plt.plot(x_prob_max, z_prob_max,'k*', markersize=20,markerfacecolor='None',\
        markeredgewidth=1,label='max prob hypocenter')
plt.xlabel("X [km]")
plt.ylabel("Z [km]")
plt.scatter(station_x,station_z-1,marker="v",\
            color="blue",s=50, label="Station")
plt.ylim(max(space_z)+1,-2)
plt.title("Marginal a posteriori probability X-Z")
plt.colorbar()
plt.legend()
Out[11]:
<matplotlib.legend.Legend at 0x7f6781e3cca0>
No description has been provided for this image

Plots for $X$, $Y$ and $T$:

In [12]:
plt.plot(space_x,sigMx,'b-',label='pdf')
plt.axvline(source_x, color="red", linestyle="--", linewidth=3,label="True X")
plt.axvline(x_prob_max, color="black", linestyle="--",label="Max prob X")
plt.xlabel("X [km]")
plt.ylabel("X marginal PDF")
plt.legend()
Out[12]:
<matplotlib.legend.Legend at 0x7f677ef24130>
No description has been provided for this image
In [13]:
plt.plot(sigMz,space_z,'b-',label='pdf')
plt.axhline(source_z, color="red", linestyle="--", linewidth=3,label="True Z")
plt.axhline(z_prob_max, color="black", linestyle="--",label="Max prob Z")
plt.xlabel("Z marginal PDF")
plt.ylabel("Z [km]")
plt.legend()
Out[13]:
<matplotlib.legend.Legend at 0x7f677ee9ba90>
No description has been provided for this image
In [14]:
plt.plot(space_T,sigMT,'b-',label='pdf')
plt.axvline(origin_T, color="red", linestyle="--",linewidth=3,label="True T")
plt.axvline(T_prob_max, color="black", linestyle="--",label="Max prob T")
plt.xlabel("T [s]")
plt.ylabel("T marginal PDF")
plt.legend()
Out[14]:
<matplotlib.legend.Legend at 0x7f677ee1f6a0>
No description has been provided for this image

Combining the plots above with grid:

In [17]:
fig1 = plt.figure(figsize=(6, 8), facecolor="white", constrained_layout=True)
gs = fig1.add_gridspec(8, 6)

ax1 = fig1.add_subplot(gs[1:6, :5])
ax2 = fig1.add_subplot(gs[:1, :5])
ax3 = fig1.add_subplot(gs[1:6, 5:6])

ax4 = fig1.add_subplot(gs[6:8, :5])

# X-Z
ax1.imshow(sigMxz.transpose(), aspect='auto',extent=[space_x[0],space_x[-1],space_z[-1],space_z[0]]
          ,cmap = 'viridis', interpolation='none')
# true hypocentre
ax1.plot(source_x, source_z,'r*', markersize=15,markerfacecolor='None',\
        markeredgewidth=1,label='true hypocenter')
# hypocentre with the maximum probability
ax1.plot(x_prob_max, z_prob_max,'k*', markersize=20,markerfacecolor='None',\
        markeredgewidth=1,label='max prob hypocenter')
ax1.set_label("X [km]")
ax1.set_ylabel("Z [km]")
ax1.scatter(station_x,station_z-1,marker="v",\
            color="blue",s=50, label="Station")
ax1.set_ylim(max(space_z)+1,-2)
ax1.legend()

# X
ax2.plot(space_x,sigMx,'b-',label='pdf')
ax2.axvline(source_x, color="red", linestyle="--",label="True X")
ax2.set_ylabel("X marginal PDF")
for tl in ax2.get_xticklabels():
    tl.set_visible(False)

ax2.legend()

#Z
ax3.plot(sigMz,space_z,'b-',label='pdf')
ax3.axhline(source_z, color="red", linestyle="--",label="True Z")
ax3.set_xlabel("Z marginal PDF")
ax3.set_ylim(max(space_z),min(space_z))
ax3.set_ylim(max(space_z)+1,-2)
for tl in ax3.get_yticklabels():
    tl.set_visible(False)

#T
ax4.plot(space_T,sigMT,'b-',label='pdf')
ax4.axvline(origin_T, color="red", linestyle="--",label="True T")
ax4.set_xlabel("T [s]")
ax4.set_ylabel("T marginal PDF")
ax4.legend()
#plt.tight_layout()
Out[17]:
<matplotlib.legend.Legend at 0x7f677e9fea30>
No description has been provided for this image

Exercises¶

  1. Use the same case study, but treat the velocity as unknown, so it also becomes part of the guessed model space. For example, guess velocities between 4 and 6.5 km/s in steps of 0.25 km/s.

  2. Use case study 1, but with a Gaussian a priori probability for the velocity, with a mean of 4.5 km/s and a variance of 1.

Solution 1¶

Add the velocity to the loop

In [18]:
# Model space to explore: (lower bound, upper bound, step)
space_x = np.arange( 0, 35, 1 )          # x coordinate (km): ( 0, 35, 0.5 )
space_z = np.arange( 0, 25, 1 )          # z coordinate (km): ( 0, 25, 0.5 )
space_T = np.arange(10, 30, 0.5)         # origin time (km): (10, 30, 0.25)
space_v = np.arange( 4,  6.5, 0.25 )     # NEW: velocity (km/s): (4, 6.5, 0.25)

from tqdm import tqdm #only for showing a progress bar

# Probabilistic hypocentre inversion
# matrix of ones with the size of the model space
sigM = np.ones([space_x.size, space_z.size, space_T.size, space_v.size]) # NEW: one more dimension, initialise the posterior PDF
# loop over the model space
for ix,X in enumerate(tqdm(space_x)): #use tqdm to show a progress bar
    for iz,Z in enumerate(space_z):
        for it,T in enumerate(space_T):
            for iv,v in enumerate(space_v): #NEW
                for istat in range(np.size(station_x)):   # loop over the stations

                    # forward modelling: NEW, v_exact replaced by v
                    t_calc = T + 1/v * np.sqrt((X-station_x[istat])**2 + (Z-station_z[istat])**2)

                    # probability of each model point
                    sigM[ix,iz,it,iv] *= np.exp( -(t_calc-t_obs[istat])**2 / (2*uncertain_t[istat]**2))
100%|██████████████████████████████████████████████████████████████████████████████████████████████████| 35/35 [00:09<00:00,  3.56it/s]
In [19]:
# marginal a posteriori probability for x and z
# and for x and z separately
sigMxz = np.zeros([space_x.size, space_z.size])
sigMz = np.zeros([space_z.size])
sigMx = np.zeros([space_x.size])
for ix in range(space_x.size):
    sigMx[ix] = np.sum(sigM[ix, :, :,:])
    for iz in range(space_z.size):
        sigMz[iz] = np.sum(sigM[:, iz, :,:])
        sigMxz[ix,iz] = np.sum(sigM[ix, iz, :,:])
sigMx /= np.sum(sigMx)
sigMz /= np.sum(sigMz)

# marginal a posteriori probability for T
sigMT = np.zeros(space_T.size)
for it in range(space_T.size):
    sigMT[it] = np.sum(sigM[:, :, it,:])
sigMT /= np.sum(sigMT)

# marginal a posteriori probability for v
sigMv = np.zeros(space_v.size)
for iv in range(space_v.size):
    sigMv[iv] = np.sum(sigM[:, :,:,iv])
sigMv /= np.sum(sigMv)
In [20]:
max_prob_index=np.unravel_index(sigM.argmax(), sigM.shape)
x_prob_max=space_x[max_prob_index[0]]
z_prob_max=space_z[max_prob_index[1]]
T_prob_max=space_T[max_prob_index[2]]
v_prob_max=space_v[max_prob_index[3]]

print("Model dengan probabilitas tertinggi:")
print(x_prob_max, z_prob_max,T_prob_max,v_prob_max)
print("Model sebenarnya")
print(source_x,source_z,origin_T, v_exact)
Model dengan probabilitas tertinggi:
16 15 17.0 5.0
Model sebenarnya
16 15 17 5
In [21]:
fig1 = plt.figure(figsize=(6, 8), facecolor="white", constrained_layout=True)
gs = fig1.add_gridspec(8, 6)

ax1 = fig1.add_subplot(gs[1:6, :5])
ax2 = fig1.add_subplot(gs[:1, :5])
ax3 = fig1.add_subplot(gs[1:6, 5:6])

# NEW: axes for the velocity
ax4 = fig1.add_subplot(gs[6:8, :3])
ax5 = fig1.add_subplot(gs[6:8, 3:6])

# X-Z
ax1.imshow(sigMxz.transpose(), aspect='auto',extent=[space_x[0],space_x[-1],space_z[-1],space_z[0]]
          ,cmap = 'viridis', interpolation='none')
# true hypocentre
ax1.plot(source_x, source_z,'r*', markersize=15,markerfacecolor='None',\
        markeredgewidth=1,label='true hypocenter')
# hypocentre with the maximum probability
ax1.plot(x_prob_max, z_prob_max,'k*', markersize=20,markerfacecolor='None',\
        markeredgewidth=1,label='max prob hypocenter')
ax1.set_label("X [km]")
ax1.set_ylabel("Z [km]")
ax1.scatter(station_x,station_z-1,marker="v",\
            color="blue",s=50, label="Station")
ax1.set_ylim(max(space_z)+1,-2)
ax1.legend()

# X
ax2.plot(space_x,sigMx,'b-',label='pdf')
ax2.axvline(source_x, color="red", linestyle="--",label="True X")
ax2.set_ylabel("X marginal PDF")
for tl in ax2.get_xticklabels():
    tl.set_visible(False)

ax2.legend()

#Z
ax3.plot(sigMz,space_z,'b-',label='pdf')
ax3.axhline(source_z, color="red", linestyle="--",label="True Z")
ax3.set_xlabel("Z marginal PDF")
ax3.set_ylim(max(space_z),min(space_z))
ax3.set_ylim(max(space_z)+1,-2)
for tl in ax3.get_yticklabels():
    tl.set_visible(False)

#T
ax4.plot(space_T,sigMT,'b-',label='pdf')
ax4.axvline(origin_T, color="red", linestyle="--",label="True T")
ax4.set_xlabel("T [s]")
ax4.set_ylabel("T marginal PDF")
ax4.legend()

#NEW: V
ax5.plot(space_v,sigMv,'b-',label='pdf')
ax5.axvline(v_exact, color="red", linestyle="--",label="True T")
ax5.set_xlabel("v [km/s]")
ax5.set_ylabel("v marginal PDF")
ax5.legend()
#plt.tight_layout()
Out[21]:
<matplotlib.legend.Legend at 0x7f677e4e78e0>
No description has been provided for this image

Solution 2¶

In [178]:
#NEW 2
v_variance = 1
v_mean=4.5

# Model space to explore: (lower bound, upper bound, step)
space_x = np.arange( 0, 35, 1 )          # x coordinate (km): ( 0, 35, 0.5 )
space_z = np.arange( 0, 25, 1 )          # z coordinate (km): ( 0, 25, 0.5 )
space_T = np.arange(10, 30, 0.5)         # origin time (km): (10, 30, 0.25)
space_v = np.arange( 4,  6.5, 0.25 )     # NEW: velocity (km/s): (4, 6.5, 0.25)

from tqdm import tqdm #only for showing a progress bar

# Probabilistic hypocentre inversion
# matrix of ones with the size of the model space
sigM = np.ones([space_x.size, space_z.size, space_T.size, space_v.size]) # NEW: one more dimension (v), initialise the posterior PDF
# loop over the model space
for ix,X in enumerate(tqdm(space_x)): #use tqdm to show a progress bar
    for iz,Z in enumerate(space_z):
        for it,T in enumerate(space_T):
            for iv,v in enumerate(space_v): #NEW
                for istat in range(np.size(station_x)):   # loop over the stations

                    # forward modelling: NEW, v_exact replaced by v
                    t_calc = T + 1/v * np.sqrt((X-station_x[istat])**2 + (Z-station_z[istat])**2)

                    # probability of each model point
                    sigM[ix,iz,it,iv] *= np.exp( -(t_calc-t_obs[istat])**2 / (2*uncertain_t[istat]**2))
                #NEW for exercise 2
                sigM[ix,iz,it,iv] *= np.exp(-(v-v_mean)**2 / (2*v_variance**2))
100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 35/35 [00:13<00:00,  2.61it/s]
In [179]:
# marginal a posteriori probability for x and z
# and for x and z separately
sigMxz = np.zeros([space_x.size, space_z.size])
sigMz = np.zeros([space_z.size])
sigMx = np.zeros([space_x.size])
for ix in range(space_x.size):
    sigMx[ix] = np.sum(sigM[ix, :, :,:])
    for iz in range(space_z.size):
        sigMz[iz] = np.sum(sigM[:, iz, :,:])
        sigMxz[ix,iz] = np.sum(sigM[ix, iz, :,:])
sigMx /= np.sum(sigMx)
sigMz /= np.sum(sigMz)

# marginal a posteriori probability for T
sigMT = np.zeros(space_T.size)
for it in range(space_T.size):
    sigMT[it] = np.sum(sigM[:, :, it,:])
sigMT /= np.sum(sigMT)

# marginal a posteriori probability for v
sigMv = np.zeros(space_v.size)
for iv in range(space_v.size):
    sigMv[iv] = np.sum(sigM[:, :,:,iv])
sigMv /= np.sum(sigMv)

# NEW 2
# a priori information for v
prior_v = np.zeros(space_v.size)
for iv in range(space_v.size):
    prior_v[iv] = np.exp(-1. / (2*v_variance**2) * ((space_v[0]+iv*(space_v[1]-space_v[0])) - v_mean)**2)
prior_v /= np.sum(prior_v)
In [182]:
max_prob_index=np.unravel_index(sigM.argmax(), sigM.shape)
x_prob_max=space_x[max_prob_index[0]]
z_prob_max=space_z[max_prob_index[1]]
T_prob_max=space_T[max_prob_index[2]]
v_prob_max=space_v[max_prob_index[3]]
print("Model dengan probabilitas tertinggi:")
print(x_prob_max, z_prob_max,T_prob_max,v_prob_max)
print("Model sebenarnya")
print(source_x,source_z,origin_T, v_exact)
Model dengan probabilitas tertinggi:
16 18 16.0 4.5
Model sebenarnya
16 15 17 5
In [181]:
space_v
Out[181]:
array([4.  , 4.25, 4.5 , 4.75, 5.  , 5.25, 5.5 , 5.75, 6.  , 6.25])
In [176]:
fig1 = plt.figure(figsize=(6, 8), facecolor="white")
gs = fig1.add_gridspec(8, 6)

ax1 = fig1.add_subplot(gs[1:6, :5])
ax2 = fig1.add_subplot(gs[:1, :5])
ax3 = fig1.add_subplot(gs[1:6, 5:6])

# NEW: axes for the velocity
ax4 = fig1.add_subplot(gs[6:8, :3])
ax5 = fig1.add_subplot(gs[6:8, 3:6])

# X-Z
ax1.imshow(sigMxz.transpose(), aspect='auto',extent=[space_x[0],space_x[-1],space_z[-1],space_z[0]]
          ,cmap = 'viridis', interpolation='none')
# true hypocentre
ax1.plot(source_x, source_z,'r*', markersize=15,markerfacecolor='None',\
        markeredgewidth=1,label='true hypocenter')
# hypocentre with the maximum probability
ax1.plot(x_prob_max, z_prob_max,'k*', markersize=20,markerfacecolor='None',\
        markeredgewidth=1,label='max prob hypocenter')
ax1.set_label("X [km]")
ax1.set_ylabel("Z [km]")
ax1.scatter(station_x,station_z-1,marker="v",\
            color="blue",s=50, label="Station")
ax1.set_ylim(max(space_z)+1,-2)
ax1.legend()

# X
ax2.plot(space_x,sigMx,'b-',label='pdf')
ax2.axvline(source_x, color="red", linestyle="--",label="True X")
ax2.set_ylabel("X marginal PDF")
for tl in ax2.get_xticklabels():
    tl.set_visible(False)

ax2.legend()

#Z
ax3.plot(sigMz,space_z,'b-',label='pdf')
ax3.axhline(source_z, color="red", linestyle="--",label="True Z")
ax3.set_xlabel("Z marginal PDF")
ax3.set_ylim(max(space_z),min(space_z))
ax3.set_ylim(max(space_z)+1,-2)
for tl in ax3.get_yticklabels():
    tl.set_visible(False)

#T
ax4.plot(space_T,sigMT,'b-',label='pdf')
ax4.axvline(origin_T, color="red", linestyle="--",label="True T")
ax4.set_xlabel("T [s]")
ax4.set_ylabel("T marginal PDF")
ax4.legend()

#NEW: V
ax5.plot(space_v,sigMv,'b-',label='pdf')
ax5.plot(space_v, prior_v, 'r-', label="prior") #NEW 2
ax5.axvline(v_exact, color="red", linestyle="--",label="True T")
ax5.set_xlabel("v [km/s]")
ax5.set_ylabel("v marginal PDF")
ax5.legend()
plt.tight_layout()
No description has been provided for this image

A tidier plot

In [161]:
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable
from matplotlib.ticker import NullFormatter
# Plotting the solution of the inverse problem
#----------------

#Plot 2D marginal posteriori pdf for x-z-plane
plt.rcParams['figure.figsize'] = 10,8
f1 = plt.subplot()
f1.plot(station_x, station_z, 'v', color='0.60', markersize=12, clip_on=False, zorder=10, label='station')
f1.plot(source_x, source_z,'r*', markersize=15,markerfacecolor='None',markeredgewidth=1.5,label='true hypocenter')
f1.imshow(sigMxz.transpose(), aspect='auto',extent=[space_x[0],space_x[-1],space_z[-1],space_z[0]]
          ,cmap = 'viridis', interpolation='none')
f1.set_xlabel('x[km]')
f1.set_ylabel('z[km]')
f1.legend(loc='lower right')
f1.grid()
divider = make_axes_locatable(f1)
fx = divider.append_axes("top", 1.1, pad=0.2, sharex=f1)
fz = divider.append_axes("right", 1.1, pad=0.2, sharey=f1)
fx.set_title('Marginal a posteriori probability: hypocenter',y=1.03)
fx.plot(space_x,sigMx,'b-',label='pdf')
fz.plot(sigMz,space_z,'b-')
fx.set_xlim(space_x[0],space_x[-1])
fz.set_ylim(space_z[-1],space_z[0])
fx.set_ylabel('x marginal pdf')
fz.set_xlabel('z marginal pdf')
for tl in fz.get_yticklabels():
    tl.set_visible(False)
for tl in fx.get_xticklabels():
    tl.set_visible(False)
plt.show()


#Plot marginal posteriori pdf for origin time
plt.rcParams['figure.figsize'] = 15,6
figure = plt.figure()
f2 = figure.add_subplot(121)
f2.plot(space_T, sigMT, 'b-')
f2.plot([origin_T,origin_T],[0,sigMT.max()*1.1],'r--',label='true origin time')
f2.set_xlabel('Origin time [s]')
f2.set_ylabel('Probability')
f2.set_title('Marginal a posteriori probability: origin time')
f2.set_xlim(space_T[0],space_T[-1])
f2.set_ylim(0,sigMT.max()*1.1)
f2.legend(loc='lower right')

#Plot normalized marginal posteriori pdf for velocity
f3 = figure.add_subplot(122)
f3.plot(space_v, sigMv, 'b-',label = 'marginal posteriori pdf: velocity')
f3.plot(space_v, prior_v, 'r-', label='prior velocity information')
f3.plot([v_exact,v_exact],[0,sigMv.max()*1.1],'r--',label='true velocity')
f3.set_xlabel('velocity [km/s]')
f3.set_ylabel('Probability')
f3.set_title('Marginal a posteriori probability: velocity')
f3.set_xlim(space_v[0],space_v[-1])
f3.set_ylim(0,sigMv.max()*1.1)
f3.legend(loc='lower right')

plt.show()
No description has been provided for this image
No description has been provided for this image

References¶

  • Igel, H., Geßele K., Seismic Inverse Problems: Probabilistic estimation of earthquake hypocenters, https://krischer.github.io/seismo_live_build/html/Seismic%20Inverse%20Problems/Earthquake%20Location/el_hypocenter_solution_wrapper.html

  • Mosegaard, K., & Tarantola, A. (2002). Probabilistic approach to inverse problems. International Geophysics Series, 81(A), 237-268.

  • Tarantola, A. (2005). Inverse problem theory and methods for model parameter estimation. Society for Industrial and Applied Mathematics.