Skip to content

Commit 9ccd89a

Browse files
committed
DOC: add integral and differential in Tutorial
1 parent 22b2f6b commit 9ccd89a

File tree

6 files changed

+87
-2
lines changed

6 files changed

+87
-2
lines changed

docs/source/Tutorial/dynamic/run/run.py

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,49 @@ def plot_syn(stsyn:Stream, out:str|None=None, sigs:np.ndarray|None=None):
165165
# 卷积,原地修改
166166
pygrt.utils.stream_convolve(stsyn, trig)
167167
# END TIME FUNC
168-
plot_syn(stsyn, "syn_sf_trig.png", trig)
168+
plot_syn(stsyn, "syn_sf_trig.png", trig)
169+
170+
171+
172+
# BEGIN INT DIF
173+
idx = 2
174+
stgrn = stgrnLst[idx] # 选择格林函数
175+
176+
stsyn = pygrt.utils.gen_syn_from_gf_MT(stgrn, M0=1e24, MT=[0.1,-0.2,1.0,0.3,-0.5,-2.0], az=30)
177+
178+
# 使用inplace=False,防止原地修改
179+
stsyn_int = pygrt.utils.stream_integral(stsyn, inplace=False)
180+
stsyn_dif = pygrt.utils.stream_diff(stsyn, inplace=False)
181+
# END INT DIF
182+
183+
def plot_int_dif(stsyn:Stream, stsyn_int:Stream, stsyn_dif:Stream, comp:str, out:str|None=None):
184+
nt = stsyn[0].stats.npts
185+
dt = stsyn[0].stats.delta
186+
t = np.arange(nt)*dt
187+
188+
travtP = stsyn[0].stats.sac['t0']
189+
travtS = stsyn[0].stats.sac['t1']
190+
191+
fig, axs = plt.subplots(3, 1, figsize=(10, 4), gridspec_kw=dict(hspace=0.0), sharex=True)
192+
for i, (st, suffix) in enumerate(zip([stsyn, stsyn_int, stsyn_dif], ["", "_int", "_dif"])):
193+
tr = st.select(component=comp)[0]
194+
195+
ax = axs[i]
196+
ax.plot(t, tr.data, c='k', lw=0.5, label=f"{tr.stats.channel}{suffix}")
197+
ax.legend(loc='upper left')
198+
199+
ylims = ax.get_ylim()
200+
# 绘制到时
201+
ax.vlines(travtP, *ylims, colors='b')
202+
ax.text(travtP, ylims[1], "P", ha='left', va='top', color='b')
203+
ax.vlines(travtS, *ylims, colors='r')
204+
ax.text(travtS, ylims[1], "S", ha='left', va='top', color='r')
205+
206+
ax.set_xlim([t[0], t[-1]])
207+
ax.set_ylim(np.array(ylims)*1.2)
208+
209+
if out is not None:
210+
fig.savefig(out, dpi=100)
211+
212+
for ch in ['Z', 'R', 'T']:
213+
plot_int_dif(stsyn, stsyn_int, stsyn_dif, ch, f"syn_mt_intdif_{ch}.png")

docs/source/Tutorial/dynamic/run/run.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,10 @@ grt.syn -GGRN/milrow_2_0_10 -S1e24 -A30 -M33/50/120 -Osyn_dc_zne -N
3939
grt.syn -GGRN/milrow_2_0_10 -S1e16 -A30 -F1/-0.5/2 -Osyn_sf_trig -Dt/0.3/0.3/0.6
4040
# END TIME FUNC
4141

42+
43+
# BEGIN INT DIF
44+
# 积分,1表示积分1次
45+
grt.syn -GGRN/milrow_2_0_10 -S1e24 -A30 -T0.1/-0.2/1.0/0.3/-0.5/-2.0 -I1 -Osyn_mt_int1
46+
# 微分,1表示微分1次
47+
grt.syn -GGRN/milrow_2_0_10 -S1e24 -A30 -T0.1/-0.2/1.0/0.3/-0.5/-2.0 -J1 -Osyn_mt_dif1
48+
# END INT DIF
46.1 KB
Loading
33.1 KB
Loading
46.9 KB
Loading

docs/source/Tutorial/dynamic/syn.rst

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@
140140

141141

142142

143-
时间函数
143+
卷积时间函数
144144
---------------------
145145
**PyGRT** 内置了一些震源时间函数,例如抛物波、梯形波、雷克子波或自定义,这里以单力源为例。
146146

@@ -165,4 +165,37 @@
165165
其它时间函数以及具体参数用法可在 :py:mod:`pygrt.signals` 模块中查看函数参数。
166166

167167
.. image:: run/syn_sf_trig.png
168+
:align: center
169+
170+
171+
172+
位移对时间积分、微分
173+
--------------------------------
174+
这里以矩张量源为例。
175+
176+
.. tabs::
177+
178+
.. tab:: C
179+
180+
.. literalinclude:: run/run.sh
181+
:language: bash
182+
:start-after: BEGIN INT DIF
183+
:end-before: END INT DIF
184+
185+
186+
.. tab:: Python
187+
188+
.. literalinclude:: run/run.py
189+
:language: python
190+
:start-after: BEGIN INT DIF
191+
:end-before: END INT DIF
192+
193+
194+
.. image:: run/syn_mt_intdif_Z.png
195+
:align: center
196+
197+
.. image:: run/syn_mt_intdif_R.png
198+
:align: center
199+
200+
.. image:: run/syn_mt_intdif_T.png
168201
:align: center

0 commit comments

Comments
 (0)