forked from GeophyAI/seistorch
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_model_geometry.py
More file actions
executable file
·82 lines (66 loc) · 2.64 KB
/
generate_model_geometry.py
File metadata and controls
executable file
·82 lines (66 loc) · 2.64 KB
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
import os, pickle
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
import sys
sys.path.append("../../../..")
from seistorch.show import SeisShow
from seistorch.utils import ricker_wave
show = SeisShow()
def write_pkl(path: str, data: list):
# Open the file in binary mode and write the list using pickle
with open(path, 'wb') as f:
pickle.dump(data, f)
# Generate the source and receiver list
# Please note that in Seistorch,
# the coordinates of source points and receiver points are
# specified in a grid coordinate system, not in real-world distance coordinates.
# This distinction is essential for accurate simulation and interpretation of results.
vel = np.load("../../../models/marmousi_model/true_vp.npy")
# The depth of the sea is 24*20=480m
nz, nx = vel.shape
expand = 50
# The model is expanded by 50 grid points
# in left and right direction for better illuminating.
num_receivers = 128 # the number of receivers
rec_depth = 1 # the depth of receivers
sources, receivers = [], []
srcx_recx_offset = 5 # the offset between the source and the first receiver
current_srcx = 0
src_x_inverval = 5 # the grid interval of source
srcz = 1 # the grid depth of source
idx = 0 # the index of source
while current_srcx<nx:
idx+=1
srcx = idx*src_x_inverval
if srcx < num_receivers+srcx_recx_offset:
continue
else:
loc_of_first_recx = srcx - srcx_recx_offset
recx = np.arange(loc_of_first_recx, loc_of_first_recx-num_receivers, -1)
recz = np.ones_like(recx)*rec_depth
sources.append([srcx, srcz])
receivers.append([recx.tolist(), recz.tolist()])
current_srcx = srcx
print(f"the number of sources: {len(sources)}")
dh=20
show.geometry(vel, sources, receivers, savepath="geometry.gif", dh=dh, interval=1)
# # Save the source and receiver list
save_path = r"./geometry"
os.makedirs(save_path, exist_ok=True)
write_pkl(os.path.join(save_path, "sources.pkl"), sources)
write_pkl(os.path.join(save_path, "receivers.pkl"), receivers)
wavelet_forward = ricker_wave(fm=10, dt=0.001, T=4000, delay=256, dtype="numpy")*5
wavelet_inversion = ricker_wave(fm=10, dt=0.001, T=4000, delay=256, dtype="numpy")
fig,ax = plt.subplots(figsize=(6,3))
ax.plot(wavelet_forward, label="wavelet for forward")
ax.plot(wavelet_inversion, label="wavelet for inversion")
ax.legend()
plt.tight_layout()
plt.show()
fig.savefig("wavelet.png",dpi=300)
# Save the wavelet
save_path = r"./wavelet"
os.makedirs(save_path, exist_ok=True)
np.save(os.path.join(save_path, "wavelet_forward.npy"), wavelet_forward)
np.save(os.path.join(save_path, "wavelet_inversion.npy"), wavelet_inversion)