initial upload

This commit is contained in:
2025-12-17 10:53:43 +08:00
commit f3f1778f77
308 changed files with 129940 additions and 0 deletions

View File

@@ -0,0 +1,287 @@
# %%
from pytomoatt.model import ATTModel
from pytomoatt.checkerboard import Checker
import os
import numpy as np
import h5py
# %% [markdown]
# # read YAML parameter file to obtain the grid parameters for the model
# %%
output_path = "models"
os.makedirs(output_path, exist_ok=True)
par_file = "input_params/input_params.yaml"
att_model = ATTModel(par_file)
n_rtp = att_model.n_rtp # grid node numbers in r (depth), t (longtitude), p (latitude) directions
am_depths = att_model.depths # depths in km
am_latitudes = att_model.latitudes # latitudes in degrees
am_longitudes = att_model.longitudes # longitudes in degrees
print("grid node numbers (N_r, N_t, N_p):", n_rtp)
print("depths (km):", am_depths)
print("latitudes (degree):", am_latitudes)
print("longitudes (degree):", am_longitudes)
# %% [markdown]
# # eg1. generate model with constant velocity
# %%
# case 1. ---------- generate a constant velocity model using PyTomoATT module -------------
# set the velocity model to a constant value
constant_v = 6.0 # constant velocity (km/s)
att_model.vel[:,:,:] = constant_v
att_model.xi[:,:,:] = 0.0
att_model.eta[:,:,:] = 0.0
# write the model to a file
fname = "%s/constant_velocity_N%d_%d_%d_PyTomoATT.h5"%(output_path, n_rtp[0], n_rtp[1], n_rtp[2])
att_model.write(fname)
print("generate model using PyTomoATT:", fname)
# case 2. ---------- generate a constant velocity model using plain loop (h5py module is required) -------------
# set the velocity model to a constant value
vel = np.zeros(n_rtp)
xi = np.zeros(n_rtp)
eta = np.zeros(n_rtp)
for ir in range(n_rtp[0]):
for it in range(n_rtp[1]):
for ip in range(n_rtp[2]):
vel[ir, it, ip] = constant_v
fname = "%s/constant_velocity_N%d_%d_%d_loop.h5"%(output_path, n_rtp[0], n_rtp[1], n_rtp[2])
with h5py.File(fname, 'w') as f:
f.create_dataset('vel', data=vel)
f.create_dataset('xi', data=xi)
f.create_dataset('eta', data=eta)
print("generate model using plain loop:", fname)
# %% [markdown]
# # eg2. generate a linear velocity model:
# vel = 5.0, if depth < 0 km
#
# vel = 5.0 + 0.1 * depth, if 0 km <= depth <= 30 km
#
# vel = 8.0, if depth > 30 km
# %%
# case 1. ---------- generate a constant velocity model using PyTomoATT module -------------
# set the velocity model to a constant value
idx = np.where((am_depths >= 0.0) & (am_depths <= 30.0))
depth = am_depths[idx]
att_model.vel[idx,:,:] = 5.0 + 0.1 * depth[:, np.newaxis, np.newaxis] # velocity increases linearly from 5.0 to 8.0 km/s
att_model.vel[np.where(am_depths > 30.0),:,:] = 8.0 # velocity is constant at 8.0 km/s below 30.0 km depth
att_model.vel[np.where(am_depths < 0.0),:,:] = 5.0 # velocity is constant at 5.0 km/s above 0.0 km depth
att_model.xi[:,:,:] = 0.0
att_model.eta[:,:,:] = 0.0
# write the model to a file
fname = "%s/linear_velocity_N%d_%d_%d_PyTomoATT.h5"%(output_path, n_rtp[0], n_rtp[1], n_rtp[2])
att_model.write(fname)
print("generate model using PyTomoATT:", fname)
# case 2. ---------- generate a linear velocity model using plain loop (h5py module is required) -------------
# set the velocity model to a linear value
vel = np.zeros(n_rtp)
xi = np.zeros(n_rtp)
eta = np.zeros(n_rtp)
for ir in range(n_rtp[0]):
for it in range(n_rtp[1]):
for ip in range(n_rtp[2]):
if am_depths[ir] < 0.0:
vel[ir, it, ip] = 5.0
elif am_depths[ir] <= 30.0:
vel[ir, it, ip] = 5.0 + 0.1 * am_depths[ir]
else:
vel[ir, it, ip] = 8.0
fname = "%s/linear_velocity_N%d_%d_%d_loop.h5"%(output_path, n_rtp[0], n_rtp[1], n_rtp[2])
with h5py.File(fname, 'w') as f:
f.create_dataset('vel', data=vel)
f.create_dataset('xi', data=xi)
f.create_dataset('eta', data=eta)
print("generate model using plain loop:", fname)
# %% [markdown]
# # eg3. generate checkerboard model for velocity and anisotropy.
#
# assign perturbation
# %%
# case 1. ---------- generate a constant velocity model using PyTomoATT module -------------
# file name of the background model
bg_model_fname = "%s/linear_velocity_N%d_%d_%d_PyTomoATT.h5" % (output_path, n_rtp[0], n_rtp[1], n_rtp[2])
lim_x = [0.5, 1.5] # longitude limits of the checkerboard
lim_y = [0.25, 0.75] # latitude limits of the checkerboard
lim_z = [0, 30] # depth limits of the checkerboard
pert_vel = 0.1 # amplitude of velocity perturbation (%)
pert_ani = 0.05 # amplitude of anisotropy perturbation (fraction)
ani_dir = 60.0 # fast velocity direction (anti-clockwise from x-axis, in degrees)
n_pert_x = 4 # number of checkers in x (lon) direction
n_pert_y = 2 # number of checkers in y (lat) direction
n_pert_z = 3 # number of checkers in z (dep) direction
size_x = (lim_x[1] - lim_x[0]) / n_pert_x # size of each checker in x direction
size_y = (lim_y[1] - lim_y[0]) / n_pert_y # size of each checker in y direction
size_z = (lim_z[1] - lim_z[0]) / n_pert_z # size of each checker in z direction
ckb = Checker(bg_model_fname, para_fname=par_file)
# n_pert_x, n_pert_y, n_pert_z: number of checkers in x (lon), y (lat), z (dep) directions
# pert_vel: amplitude of velocity perturbation (km/s)
# pert_ani: amplitude of anisotropy perturbation (fraction)
# ani_dir: fast velicty direction (anti-cloclkwise from x-axis, in degrees)
# lim_x, lim_y, lim_z: limits of the checkerboard in x (lon), y (lat), z (dep) directions
ckb.checkerboard(
n_pert_x=n_pert_x, n_pert_y=n_pert_y, n_pert_z=n_pert_z,
pert_vel=pert_vel, pert_ani=pert_ani, ani_dir=ani_dir,
lim_x=lim_x, lim_y=lim_y, lim_z=lim_z
)
fname = "%s/linear_velocity_ckb_N%d_%d_%d_PyTomoATT.h5" % (output_path, n_rtp[0], n_rtp[1], n_rtp[2])
ckb.write(fname)
print("generate checkerboard model based on the linear velocity model using PyTomoATT:", fname)
# case 2. ---------- generate a checkerboard model using plain loop (h5py module is required) -------------
# read the background model
bg_model = np.zeros(n_rtp)
with h5py.File(bg_model_fname, 'r') as f:
bg_model = f['vel'][:]
# set the checkerboard model
vel = np.zeros(n_rtp)
xi = np.zeros(n_rtp)
eta = np.zeros(n_rtp)
for ir in range(n_rtp[0]):
for it in range(n_rtp[1]):
for ip in range(n_rtp[2]):
depth = am_depths[ir]
lat = am_latitudes[it]
lon = am_longitudes[ip]
# check if the current grid node is within the checkerboard limits
if (lim_x[0] <= lon <= lim_x[1]) and (lim_y[0] <= lat <= lim_y[1]) and (lim_z[0] <= depth <= lim_z[1]):
sigma_vel = np.sin(np.pi * (lon - lim_x[0])/size_x) * np.sin(np.pi * (lat - lim_y[0])/size_y) * np.sin(np.pi * (depth - lim_z[0])/size_z)
sigma_ani = np.sin(np.pi * (lon - lim_x[0])/size_x) * np.sin(np.pi * (lat - lim_y[0])/size_y) * np.sin(np.pi * (depth - lim_z[0])/size_z)
if (sigma_ani > 0):
psi = ani_dir / 180.0 * np.pi # convert degrees to radians
elif (sigma_ani < 0):
psi = (ani_dir + 90.0) / 180.0 * np.pi
else:
psi = 0.0
else:
sigma_vel = 0.0
sigma_ani = 0.0
psi = 0.0
# set the velocity and anisotropy
vel[ir, it, ip] = bg_model[ir, it, ip] * (1.0 + pert_vel * sigma_vel)
xi[ir, it, ip] = pert_ani * abs(sigma_ani) * np.cos(2*psi)
eta[ir, it, ip] = pert_ani * abs(sigma_ani) * np.sin(2*psi)
# write the model to a file
fname = "%s/linear_velocity_ckb_N%d_%d_%d_loop.h5" % (output_path, n_rtp[0], n_rtp[1], n_rtp[2])
with h5py.File(fname, 'w') as f:
f.create_dataset('vel', data=vel)
f.create_dataset('xi', data=xi)
f.create_dataset('eta', data=eta)
print("generate checkerboard model based on the linear velocity model using plain loop:", fname)
# %% [markdown]
# # eg4. generate flexible checkerboard model
#
# the checker size increases with depth;
#
# the checker size is large for anisotropy;
# %%
# only
# file name of the background model
bg_model_fname = "%s/linear_velocity_N%d_%d_%d_PyTomoATT.h5" % (output_path, n_rtp[0], n_rtp[1], n_rtp[2])
# read the background model
bg_model = np.zeros(n_rtp)
with h5py.File(bg_model_fname, 'r') as f:
bg_model = f['vel'][:]
# set the checkerboard model
vel = np.zeros(n_rtp)
xi = np.zeros(n_rtp)
eta = np.zeros(n_rtp)
for ir in range(n_rtp[0]):
for it in range(n_rtp[1]):
for ip in range(n_rtp[2]):
depth = am_depths[ir]
lat = am_latitudes[it]
lon = am_longitudes[ip]
if ((depth >= 0.0) and (depth <= 8.0)):
size_vel = 0.2
size_ani = 0.3
sigma_vel = np.sin(np.pi * lon/size_vel) * np.sin(np.pi * lat/size_vel) * np.sin(np.pi * depth/8.0)
sigma_ani = np.sin(np.pi * lon/size_ani) * np.sin(np.pi * lat/size_ani) * np.sin(np.pi * depth/8.0)
elif ((depth > 8.0) and (depth <= 20.0)):
size_vel = 0.3
size_ani = 0.4
sigma_vel = np.sin(np.pi * lon/size_vel) * np.sin(np.pi * lat/size_vel) * np.sin(np.pi * (depth - 8.0)/12.0 + np.pi)
sigma_ani = np.sin(np.pi * lon/size_ani) * np.sin(np.pi * lat/size_ani) * np.sin(np.pi * (depth - 8.0)/12.0 + np.pi)
elif ((depth > 20.0) and (depth <= 36.0)):
size_vel = 0.4
size_ani = 0.5
sigma_vel = np.sin(np.pi * lon/size_vel) * np.sin(np.pi * lat/size_vel) * np.sin(np.pi * (depth - 20.0)/16.0 + 2*np.pi)
sigma_ani = np.sin(np.pi * lon/size_ani) * np.sin(np.pi * lat/size_ani) * np.sin(np.pi * (depth - 20.0)/16.0 + 2*np.pi)
else:
sigma_vel = 0.0
sigma_ani = 0.0
if (sigma_ani > 0):
psi = ani_dir / 180.0 * np.pi # convert degrees to radians
elif (sigma_ani < 0):
psi = (ani_dir + 90.0) / 180.0 * np.pi
else:
psi = 0.0
# set the velocity and anisotropy
vel[ir, it, ip] = bg_model[ir, it, ip] * (1.0 + pert_vel * sigma_vel)
xi[ir, it, ip] = pert_ani * abs(sigma_ani) * np.cos(2*psi)
eta[ir, it, ip] = pert_ani * abs(sigma_ani) * np.sin(2*psi)
# write the model to a file
fname = "%s/linear_velocity_ckb_flex_N%d_%d_%d.h5" % (output_path, n_rtp[0], n_rtp[1], n_rtp[2])
with h5py.File(fname, 'w') as f:
f.create_dataset('vel', data=vel)
f.create_dataset('xi', data=xi)
f.create_dataset('eta', data=eta)
print("generate flexible checkerboard model based on the linear velocity model using plain loop:", fname)

View File

@@ -0,0 +1,338 @@
# %%
import pygmt
pygmt.config(FONT="16p", IO_SEGMENT_MARKER="<<<")
from pytomoatt.model import ATTModel
from pytomoatt.data import ATTData
import numpy as np
# %%
import os
output_path = "figs"
os.makedirs(output_path, exist_ok=True)
# %% [markdown]
# # eg1. plot constant velocity model
# %%
# ---------------- read model files ----------------
# file names
# init_model_file = 'models/constant_velocity_N61_51_101_PyTomoATT.h5' # initial model file
init_model_file = 'models/constant_velocity_N61_51_101_loop.h5' # initial model file
par_file = 'input_params/input_params.yaml' # parameter file
# read initial and final model file
att_model = ATTModel.read(init_model_file, par_file)
init_model = att_model.to_xarray()
# interp vel at depth = 20 km
depth = 20.0
vel_init = init_model.interp_dep(depth, field='vel') # vel_init[i,:] are (lon, lat, vel)
# ----------------- pygmt plot ------------------
fig = pygmt.Figure()
pygmt.makecpt(cmap="seis", series=[5, 7], background=True, reverse=False) # colorbar
# ------------ plot horizontal profile of velocity ------------
region = [0, 2, 0, 1] # region of interest
fig.basemap(region=region, frame=["xa1","ya1","+tVelocity (km/s)"], projection="M10c") # base map
depth = 20.0
prof_init = init_model.interp_dep(depth, field='vel') # prof_init[i,:] are (lon, lat, vel)
lon = prof_init[:,0] # longitude
lat = prof_init[:,1] # latitude
vel = prof_init[:,2] # velocity
grid = pygmt.surface(x=lon, y=lat, z=vel, spacing=0.04,region=region)
fig.grdimage(grid = grid) # plot figure
fig.text(text="%d km"%(depth), x = 0.2 , y = 0.1, font = "14p,Helvetica-Bold,black", fill = "white")
# colorbar
fig.shift_origin(xshift=0, yshift=-1.5)
fig.colorbar(frame = ["a1","y+lVp (km/s)"], position="+e+w4c/0.3c+h")
fig.shift_origin(xshift=0, yshift= 1.5)
# ------------ plot horivertical profile of velocity ------------
fig.shift_origin(xshift=11, yshift= 0)
region = [0, 40, 0, 1] # region of interest
fig.basemap(region=region, frame=["xa20+lDepth (km)","ya1+lLatitude","nSwE"], projection="X3c/5c") # base map
start = [1,0]; end = [1,1]; gap = 1
prof_init = init_model.interp_sec(start, end, field='vel', val = gap) # prof_init[i,:] are (lon, lat, dis, dep, vel)
lat = prof_init[:,1] # lat
dep = prof_init[:,3] # depth
vel = prof_init[:,4] # velocity
grid = pygmt.surface(x=dep, y=lat, z=vel, spacing="1/0.04",region=region)
fig.grdimage(grid = grid) # plot figure
fig.savefig("figs/constant_velocity.png") # save figure
fig.show()
# %% [markdown]
# # eg2. plot linear velocity model
# %%
# ---------------- read model files ----------------
# file names
# init_model_file = 'models/linear_velocity_N61_51_101_PyTomoATT.h5' # initial model file
init_model_file = 'models/linear_velocity_N61_51_101_loop.h5' # initial model file
par_file = 'input_params/input_params.yaml' # parameter file
# read initial and final model file
att_model = ATTModel.read(init_model_file, par_file)
init_model = att_model.to_xarray()
# # interp vel at depth = 20 km
# depth = 20.0
# vel_init = init_model.interp_dep(depth, field='vel') # vel_init[i,:] are (lon, lat, vel)
# ----------------- pygmt plot ------------------
fig = pygmt.Figure()
pygmt.makecpt(cmap="seis", series=[5, 8], background=True, reverse=False) # colorbar
# ------------ plot horizontal profile of velocity ------------
region = [0, 2, 0, 1] # region of interest
fig.basemap(region=region, frame=["xa1","ya1","+tVelocity (km/s)"], projection="M10c") # base map
depth = 20.0
prof_init = init_model.interp_dep(depth, field='vel') # prof_init[i,:] are (lon, lat, vel)
lon = prof_init[:,0] # longitude
lat = prof_init[:,1] # latitude
vel = prof_init[:,2] # velocity
grid = pygmt.surface(x=lon, y=lat, z=vel, spacing=0.04,region=region)
fig.grdimage(grid = grid) # plot figure
fig.text(text="%d km"%(depth), x = 0.2 , y = 0.1, font = "14p,Helvetica-Bold,black", fill = "white")
# colorbar
fig.shift_origin(xshift=0, yshift=-1.5)
fig.colorbar(frame = ["a1","y+lVp (km/s)"], position="+e+w4c/0.3c+h")
fig.shift_origin(xshift=0, yshift= 1.5)
# ------------ plot horivertical profile of velocity ------------
fig.shift_origin(xshift=11, yshift= 0)
region = [0, 40, 0, 1] # region of interest
fig.basemap(region=region, frame=["xa20+lDepth (km)","ya1+lLatitude","nSwE"], projection="X3c/5c") # base map
start = [1,0]; end = [1,1]; gap = 1
prof_init = init_model.interp_sec(start, end, field='vel', val = gap) # prof_init[i,:] are (lon, lat, dis, dep, vel)
lat = prof_init[:,1] # lat
dep = prof_init[:,3] # depth
vel = prof_init[:,4] # velocity
grid = pygmt.surface(x=dep, y=lat, z=vel, spacing="1/0.04",region=region)
fig.grdimage(grid = grid) # plot figure
fig.savefig("figs/linear_velocity.png") # save figure
fig.show()
# %% [markdown]
# # eg3. plot checkerboard model
# %%
# ---------------- read model files ----------------
# file names
init_model_file = 'models/linear_velocity_N61_51_101_PyTomoATT.h5' # initial model file
ckb_model_file = 'models/linear_velocity_ckb_N61_51_101_PyTomoATT.h5' # checkerboard model file
# ckb_model_file = 'models/linear_velocity_ckb_N61_51_101_loop.h5' # checkerboard model file
par_file = 'input_params/input_params.yaml' # parameter file
# read initial and final model file
att_model = ATTModel.read(init_model_file, par_file)
init_model = att_model.to_xarray()
att_model = ATTModel.read(ckb_model_file, par_file)
ckb_model = att_model.to_xarray()
# # interp vel at depth = 20 km
# depth = 20.0
# vel_init = init_model.interp_dep(depth, field='vel') # vel_init[i,:] are (lon, lat, vel)
# vel_ckb = ckb_model.interp_dep(depth, field='vel') # vel_ckb[i,:] are (lon, lat, vel)
# ----------------- pygmt plot ------------------
fig = pygmt.Figure()
pygmt.makecpt(cmap="../utils/svel13_chen.cpt", series=[-10,10], background=True, reverse=False) # colorbar
# ------------ plot horizontal profile of velocity ------------
region = [0, 2, 0, 1] # region of interest
fig.basemap(region=region, frame=["xa1","ya1","+tVelocity perturbation (%)"], projection="M10c") # base map
# velocity perturbation at depth = 15 km
depth = 15.0
prof_init = init_model.interp_dep(depth, field='vel') # prof_init[i,:] are (lon, lat, vel)
prof_ckb = ckb_model.interp_dep(depth, field='vel') # prof_ckb[i,:] are (lon, lat, vel)
lon = prof_init[:,0] # longitude
lat = prof_init[:,1] # latitude
vel_pert = (prof_ckb[:,2] - prof_init[:,2])/prof_init[:,2] * 100 # velocity perturbation related to initial model
grid = pygmt.surface(x=lon, y=lat, z=vel_pert, spacing=0.01,region=region)
fig.grdimage(grid = grid) # plot figure
fig.text(text="%d km"%(depth), x = 0.2 , y = 0.1, font = "14p,Helvetica-Bold,black", fill = "white")
# fast velocity directions (FVDs)
samp_interval = 3 # control the density of anisotropic arrows
width = 0.06 # width of the anisotropic arrow
ani_per_1 = 0.01; ani_per_2 = 0.05; scale = 0.5; basic = 0.1 # control the length of anisotropic arrows related to the amplitude of anisotropy. length = 0.1 + (amplitude - ani_per_1) / (ani_per_2 - ani_per_1) * scale
ani_thd = ani_per_1 # if the amplitude of anisotropy is smaller than ani_thd, no anisotropic arrow will be plotted
phi = ckb_model.interp_dep(depth, field='phi', samp_interval=samp_interval) # phi_inv[i,:] are (lon, lat, phi)
epsilon = ckb_model.interp_dep(depth, field='epsilon', samp_interval=samp_interval) # epsilon_inv[i,:] are (lon, lat, epsilon)
ani_lon = phi[:,0].reshape(-1,1)
ani_lat = phi[:,1].reshape(-1,1)
ani_phi = phi[:,2].reshape(-1,1)
length = ((epsilon[:,2] - ani_per_1) / (ani_per_2 - ani_per_1) * scale + basic).reshape(-1,1)
ani_arrow = np.hstack([ani_lon, ani_lat, ani_phi, length, np.ones((ani_lon.size,1))*width]) # lon, lat, color, angle[-90,90], length, width
# remove arrows with small amplitude of anisotropy
idx = np.where(epsilon[:,2] > ani_thd)[0] # indices of arrows with large enough amplitude of anisotropy
ani_arrow = ani_arrow[idx,:] # remove arrows with small amplitude of anisotropy
# plot anisotropic arrows
fig.plot(ani_arrow, style='j', fill='yellow1', pen='0.5p,black') # plot fast velocity direction
# colorbar
fig.shift_origin(xshift=0, yshift=-1.5)
fig.colorbar(frame = ["a10","y+ldlnVp (%)"], position="+e+w4c/0.3c+h")
fig.shift_origin(xshift=0, yshift= 1.5)
# ------------ plot horivertical profile of velocity ------------
fig.shift_origin(xshift=11, yshift= 0)
region = [0, 40, 0, 1] # region of interest
fig.basemap(region=region, frame=["xa20+lDepth (km)","ya1+lLatitude","nSwE"], projection="X3c/5c") # base map
start = [0.875,0]; end = [0.875,1]; gap = 1
prof_init = init_model.interp_sec(start, end, field='vel', val = gap) # prof_init[i,:] are (lon, lat, dis, dep, vel)
prof_ckb = ckb_model.interp_sec(start, end, field='vel', val = gap) # prof_ckb[i,:] are (lon, lat, dis, dep, vel)
lat = prof_init[:,1] # lat
dep = prof_init[:,3] # depth
vel = (prof_ckb[:,4] - prof_init[:,4])/prof_init[:,4] * 100 # velocity perturbation related to initial model
grid = pygmt.surface(x=dep, y=lat, z=vel, spacing="1/0.01",region=region)
fig.grdimage(grid = grid) # plot figure
fig.savefig("figs/checkerboard_velocity.png") # save figure
fig.show()
# %% [markdown]
# # eg4. plot flexible checkerboard model
# %%
# ---------------- read model files ----------------
# file names
init_model_file = 'models/linear_velocity_N61_51_101_PyTomoATT.h5' # initial model file
ckb_model_file = 'models/linear_velocity_ckb_flex_N61_51_101.h5' # checkerboard model file
par_file = 'input_params/input_params.yaml' # parameter file
# read initial and final model file
att_model = ATTModel.read(init_model_file, par_file)
init_model = att_model.to_xarray()
att_model = ATTModel.read(ckb_model_file, par_file)
ckb_model = att_model.to_xarray()
# # interp vel at depth = 20 km
# depth = 20.0
# vel_init = init_model.interp_dep(depth, field='vel') # vel_init[i,:] are (lon, lat, vel)
# vel_ckb = ckb_model.interp_dep(depth, field='vel') # vel_ckb[i,:] are (lon, lat, vel)
# ----------------- pygmt plot ------------------
fig = pygmt.Figure()
pygmt.makecpt(cmap="../utils/svel13_chen.cpt", series=[-10,10], background=True, reverse=False) # colorbar
for depth in [4,14,28]:
# ------------ plot horizontal profile of velocity ------------
region = [0, 2, 0, 1] # region of interest
fig.basemap(region=region, frame=["xa1","ya1","NsEw"], projection="M10c") # base map
# velocity perturbation at depth = 15 km
prof_init = init_model.interp_dep(depth, field='vel') # prof_init[i,:] are (lon, lat, vel)
prof_ckb = ckb_model.interp_dep(depth, field='vel') # prof_ckb[i,:] are (lon, lat, vel)
lon = prof_init[:,0] # longitude
lat = prof_init[:,1] # latitude
vel_pert = (prof_ckb[:,2] - prof_init[:,2])/prof_init[:,2] * 100 # velocity perturbation related to initial model
grid = pygmt.surface(x=lon, y=lat, z=vel_pert, spacing=0.01,region=region)
fig.grdimage(grid = grid) # plot figure
# fast velocity directions (FVDs)
samp_interval = 3 # control the density of anisotropic arrows
width = 0.06 # width of the anisotropic arrow
ani_per_1 = 0.01; ani_per_2 = 0.05; scale = 0.5; basic = 0.1 # control the length of anisotropic arrows related to the amplitude of anisotropy. length = 0.1 + (amplitude - ani_per_1) / (ani_per_2 - ani_per_1) * scale
ani_thd = ani_per_1 # if the amplitude of anisotropy is smaller than ani_thd, no anisotropic arrow will be plotted
phi = ckb_model.interp_dep(depth, field='phi', samp_interval=samp_interval) # phi_inv[i,:] are (lon, lat, phi)
epsilon = ckb_model.interp_dep(depth, field='epsilon', samp_interval=samp_interval) # epsilon_inv[i,:] are (lon, lat, epsilon)
ani_lon = phi[:,0].reshape(-1,1)
ani_lat = phi[:,1].reshape(-1,1)
ani_phi = phi[:,2].reshape(-1,1)
length = ((epsilon[:,2] - ani_per_1) / (ani_per_2 - ani_per_1) * scale + basic).reshape(-1,1)
ani_arrow = np.hstack([ani_lon, ani_lat, ani_phi, length, np.ones((ani_lon.size,1))*width]) # lon, lat, color, angle[-90,90], length, width
# remove arrows with small amplitude of anisotropy
idx = np.where(epsilon[:,2] > ani_thd)[0] # indices of arrows with large enough amplitude of anisotropy
ani_arrow = ani_arrow[idx,:] # remove arrows with small amplitude of anisotropy
# plot anisotropic arrows
fig.plot(ani_arrow, style='j', fill='yellow1', pen='0.5p,black') # plot fast velocity direction
fig.text(text="%d km"%(depth), x = 0.2 , y = 0.1, font = "14p,Helvetica-Bold,black", fill = "white")
# plot vertical profile
fig.plot(x=[0.9, 0.9], y=[0, 1], pen="2p,black,-") # vertical line
fig.shift_origin(xshift=0, yshift=-6)
# colorbar
fig.shift_origin(xshift=0, yshift= 4.5)
fig.colorbar(frame = ["a10","y+ldlnVp (%)"], position="+e+w4c/0.3c+h")
fig.shift_origin(xshift=0, yshift= 1.5)
# ------------ plot horivertical profile of velocity ------------
fig.shift_origin(xshift=11, yshift= 0)
region = [0, 40, 0, 1] # region of interest
fig.basemap(region=region, frame=["xa20+lDepth (km)","ya1+lLatitude","nSwE"], projection="X3c/5c") # base map
start = [0.9,0]; end = [0.9,1]; gap = 1
prof_init = init_model.interp_sec(start, end, field='vel', val = gap) # prof_init[i,:] are (lon, lat, dis, dep, vel)
prof_ckb = ckb_model.interp_sec(start, end, field='vel', val = gap) # prof_ckb[i,:] are (lon, lat, dis, dep, vel)
lat = prof_init[:,1] # lat
dep = prof_init[:,3] # depth
vel = (prof_ckb[:,4] - prof_init[:,4])/prof_init[:,4] * 100 # velocity perturbation related to initial model
grid = pygmt.surface(x=dep, y=lat, z=vel, spacing="1/0.01",region=region)
fig.grdimage(grid = grid) # plot figure
fig.savefig("figs/flexible_checkerboard_velocity.png") # save figure
fig.show()

View File

@@ -0,0 +1,50 @@
version: 3
#################################################
# computational domian #
#################################################
domain:
min_max_dep: [-10, 50] # depth in km
min_max_lat: [0, 1] # latitude in degree
min_max_lon: [0, 2] # longitude in degree
n_rtp: [61, 51, 101] # number of nodes in depth,latitude,longitude direction
#################################################
# traveltime data file path #
#################################################
source:
src_rec_file: 1_src_rec_files/src_rec_config.dat # source receiver file path
swap_src_rec: true # swap source and receiver
#################################################
# initial model file path #
#################################################
model:
init_model_path: 2_models/model_ckb_N61_51_101.h5 # path to initial model file
#################################################
# parallel computation settings #
#################################################
parallel: # parameters for parallel computation
n_sims: 8 # number of simultanoues runs (parallel the sources)
ndiv_rtp: [1, 1, 1] # number of subdivision on each direction (parallel the computional domain)
############################################
# output file setting #
############################################
output_setting:
output_dir: OUTPUT_FILES/OUTPUT_FILES_signal # path to output director (default is ./OUTPUT_FILES/)
output_final_model: true # output merged final model (final_model.h5) or not.
output_in_process: false # output model at each inv iteration or not.
output_in_process_data: false # output src_rec_file at each inv iteration or not.
output_file_format: 0
#################################################
# inversion or forward modeling #
#################################################
# run mode
# 0 for forward simulation only,
# 1 for inversion
# 2 for earthquake relocation
# 3 for inversion + earthquake relocation
run_mode: 0

View File

@@ -0,0 +1,13 @@
#!/bin/bash
# run the script to generate HDF5 model files for TomoATT. Four models will be generated for TomoATT
# 1. constant velocity model
# 2. linear velocity model
# 3. regular checkerboard model based on the linear velocity model
# 4. flexible checkerboard model based on the linear velocity model
python 1_generate_models.py
# run the script to plot the generated models (optional)
python 2_plot_models.py