@@ -80,6 +80,73 @@ pip install -v pyfmm-kit
8080<br >
8181
8282
83+ # 使用示例 Usage Example
84+ 更多使用示例详见[ ** 在线文档** ] ( https://pyfmm.readthedocs.io/zh-cn/latest/ ) 。
85+ ``` python
86+ import pyfmm
87+ import numpy as np
88+ import matplotlib.pyplot as plt
89+ from scipy import interpolate
90+
91+ pyfmm.logger.myLogger.setLevel(' ERROR' )
92+
93+ # 定义网格
94+ nx, ny, nz = 401 , 1 , 101
95+ xarr = np.linspace(0 , 200 , nx)
96+ yarr = np.array([0.0 ])
97+ zarr = np.linspace(0 , 50 , nz)
98+
99+ # 定义1D速度
100+ vel1d = np.array([
101+ [0.0 , 3.2 ],
102+ [5.0 , 5.8 ],
103+ [15.0 , 6.5 ],
104+ [30.0 , 6.8 ],
105+ [35.0 , 8.1 ],
106+ [80.0 , 8.2 ]
107+ ])
108+
109+ # 插值1d分层速度
110+ # _idxs = np.searchsorted(vel1d[:,0], zarr)
111+ # velocity = vel1d[_idxs, 1]
112+ # OR
113+ # 插值1d梯度速度
114+ velocity = interpolate.interpn((vel1d[:,0 ],), vel1d[:,1 ], zarr)
115+
116+ # 慢度数组
117+ slowness = np.empty((nx, ny, nz))
118+ slowness[... ] = 1.0 / velocity[None ,None ,:]
119+
120+ # 定义震源位置
121+ srcloc = [0.0 , 0.0 , 0.0 ]
122+
123+ # 计算时间场
124+ TT = pyfmm.travel_time_source(
125+ srcloc,
126+ xarr, yarr, zarr, slowness)
127+
128+ # ====================================================================
129+ # 绘制走时场和射线
130+ fig, ax1 = plt.subplots(1 , 1 )
131+ cs = ax1.contour(xarr, zarr, TT [:, 0 , :].T, levels = 30 , linewidths = 0.5 )
132+ ax1.clabel(cs)
133+
134+ for x in np.arange(5 , 200 , 5 ):
135+ # 射线追踪
136+ rcvloc = [x, 0 , 0 ]
137+
138+ travt, rays = pyfmm.raytracing(
139+ TT , srcloc, rcvloc, xarr, yarr, zarr, 0.1 )
140+ ax1.plot(rays[:,0 ], rays[:,2 ], c = ' r' , lw = 0.8 , ls = ' --' )
141+
142+ ax1.set_aspect(' equal' )
143+ ax1.set_xlim(0 , 200 )
144+ ax1.set_ylim(0 , 50 )
145+ ax1.yaxis.set_inverted(True )
146+
147+ ```
148+ ![ ] ( https://github.com/Dengda98/PyFMM/blob/main/figs/example.png )
149+
83150
84151# 其它
85152代码是我在研二写的,如果遇到bug,欢迎联系我(
[email protected] ),我会完善!
0 commit comments