Skip to content

Commit 42aade8

Browse files
authored
FEAT: remove -P<prefix>, and simplify the input argument of strain, stress and rotation (#103)
1 parent 3ee8941 commit 42aade8

File tree

14 files changed

+109
-169
lines changed

14 files changed

+109
-169
lines changed

docs/locales/en/LC_MESSAGES/Tutorial/dynamic/strain_stress.po

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgid ""
88
msgstr ""
99
"Project-Id-Version: PyGRT 0.6.1.dev1+g4641a40.d20250422\n"
1010
"Report-Msgid-Bugs-To: \n"
11-
"POT-Creation-Date: 2025-08-05 13:28+0800\n"
11+
"POT-Creation-Date: 2025-09-21 23:21+0800\n"
1212
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
1313
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
1414
"Language: en\n"
@@ -48,10 +48,11 @@ msgstr ""
4848
"To compute these tensors, the spatial derivatives of displacement "
4949
":math:`\\partial z,\\partial r,\\partial \\theta` [#partial]_ need to be "
5050
"calculated. Starting from the calculation of Green's functions "
51-
"(:doc:`/Tutorial/dynamic/gfunc`) and the formula for displacement synthesis "
52-
"(:doc:`/Tutorial/dynamic/syn`), the spatial derivatives of displacement are computed in"
53-
" two steps, and then strain, rotation, and stress tensors are synthesized"
54-
" based on the geometric and constitutive equations."
51+
"(:doc:`/Tutorial/dynamic/gfunc`) and the formula for displacement "
52+
"synthesis (:doc:`/Tutorial/dynamic/syn`), the spatial derivatives of "
53+
"displacement are computed in two steps, and then strain, rotation, and "
54+
"stress tensors are synthesized based on the geometric and constitutive "
55+
"equations."
5556

5657
#: ../../source/Tutorial/dynamic/strain_stress.rst:12
5758
msgid ""
@@ -261,12 +262,10 @@ msgid ""
261262
msgstr ""
262263

263264
#: ../../source/Tutorial/dynamic/strain_stress.rst:141
264-
msgid ""
265-
"在 :rst:dir:`syn_dc_zne/` 原路径下,生成 "
266-
":file:`*.strain.??.sac`,文件名中包括分量名,如ZZ、ZN等。"
265+
msgid "在 :rst:dir:`syn_dc_zne/` 原路径下,生成 :file:`strain_??.sac`,文件名中包括分量名,如ZZ、ZN等。"
267266
msgstr ""
268267
"In the original path :rst:dir:`syn_dc_zne/`, files named "
269-
":file:`*.strain.??.sac` are generated, with component names such as ZZ, "
268+
":file:`strain_??.sac` are generated, with component names such as ZZ, "
270269
"ZN included in the file names."
271270

272271
#: ../../source/Tutorial/dynamic/strain_stress.rst:150
@@ -294,10 +293,10 @@ msgstr ""
294293
#: ../../source/Tutorial/dynamic/strain_stress.rst:173
295294
msgid ""
296295
"在 :rst:dir:`syn_dc_zne/` 原路径下,生成 "
297-
":file:`*.rotation.??.sac`,文件名中包括分量名,如ZN,ZE,NE。"
296+
":file:`rotation_??.sac`,文件名中包括分量名,如ZN,ZE,NE。"
298297
msgstr ""
299298
"In the original path :rst:dir:`syn_dc_zne/`, files named "
300-
":file:`*.rotation.??.sac` are generated, with component names such as ZN,"
299+
":file:`rotation_??.sac` are generated, with component names such as ZN,"
301300
" ZE, NE included in the file names."
302301

303302
#: ../../source/Tutorial/dynamic/strain_stress.rst:182
@@ -321,12 +320,10 @@ msgid ""
321320
msgstr ""
322321

323322
#: ../../source/Tutorial/dynamic/strain_stress.rst:207
324-
msgid ""
325-
"在 :rst:dir:`syn_dc_zne/` 原路径下,生成 "
326-
":file:`*.stress.??.sac`,文件名中包括分量名,如ZZ、ZN等。"
323+
msgid "在 :rst:dir:`syn_dc_zne/` 原路径下,生成 :file:`stress_??.sac`,文件名中包括分量名,如ZZ、ZN等。"
327324
msgstr ""
328325
"In the original path :rst:dir:`syn_dc_zne/`, files named "
329-
":file:`*.stress.??.sac` are generated, with component names such as ZZ, "
326+
":file:`stress_??.sac` are generated, with component names such as ZZ, "
330327
"ZN included in the file names."
331328

332329
#: ../../source/Tutorial/dynamic/strain_stress.rst:224

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,22 @@ grt syn -GGRN/milrow_2_0_10 -S1e24 -A30 -M33/50/120 -Osyn_dc_zne -e -N
2727

2828
# --------------------------------------------------------------------------------------
2929
# BEGIN STRAIN
30-
# 指定文件夹以及中间名,会在原文件夹内输出SAC格式的应变张量
31-
grt strain syn_dc_zne/out
30+
# 指定文件夹,会在原文件夹内输出SAC格式的应变张量
31+
grt strain syn_dc_zne
3232
# END STRAIN
3333
# --------------------------------------------------------------------------------------
3434

3535
# --------------------------------------------------------------------------------------
3636
# BEGIN ROTATION
37-
# 指定文件夹以及中间名,会在原文件夹内输出SAC格式的旋转张量
38-
grt rotation syn_dc_zne/out
37+
# 指定文件夹,会在原文件夹内输出SAC格式的旋转张量
38+
grt rotation syn_dc_zne
3939
# END ROTATION
4040
# --------------------------------------------------------------------------------------
4141

4242

4343
# --------------------------------------------------------------------------------------
4444
# BEGIN STRESS
45-
# 指定文件夹以及中间名,会在原文件夹内输出SAC格式的应力张量
46-
grt stress syn_dc_zne/out
45+
# 指定文件夹,会在原文件夹内输出SAC格式的应力张量
46+
grt stress syn_dc_zne
4747
# END STRESS
4848
# --------------------------------------------------------------------------------------

docs/source/Tutorial/dynamic/strain_stress.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@
138138
:start-after: BEGIN STRAIN
139139
:end-before: END STRAIN
140140

141-
:rst:dir:`syn_dc_zne/` 原路径下,生成 :file:`*.strain.??.sac`,文件名中包括分量名,如ZZ、ZN等。
141+
:rst:dir:`syn_dc_zne/` 原路径下,生成 :file:`strain_??.sac`,文件名中包括分量名,如ZZ、ZN等。
142142

143143
.. group-tab:: Python
144144

@@ -170,7 +170,7 @@
170170
:start-after: BEGIN ROTATION
171171
:end-before: END ROTATION
172172

173-
:rst:dir:`syn_dc_zne/` 原路径下,生成 :file:`*.rotation.??.sac`,文件名中包括分量名,如ZN,ZE,NE。
173+
:rst:dir:`syn_dc_zne/` 原路径下,生成 :file:`rotation_??.sac`,文件名中包括分量名,如ZN,ZE,NE。
174174

175175
.. group-tab:: Python
176176

@@ -204,7 +204,7 @@
204204
:start-after: BEGIN STRESS
205205
:end-before: END STRESS
206206

207-
:rst:dir:`syn_dc_zne/` 原路径下,生成 :file:`*.stress.??.sac`,文件名中包括分量名,如ZZ、ZN等。
207+
:rst:dir:`syn_dc_zne/` 原路径下,生成 :file:`stress_??.sac`,文件名中包括分量名,如ZZ、ZN等。
208208

209209
.. group-tab:: Python
210210

example/compare_c_py/run_grt.sh

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,41 +19,40 @@ grt greenfn -M${modname} -O${out} -N${nt}/${dt} -D${depsrc}/${deprcv} -R${dist}
1919

2020
# convolve different signals
2121
G=$out/${modname}_${depsrc}_${deprcv}_${dist}
22-
P=cout
2322
S=1e24
2423
az=39.2
2524
for N in "" "-N" ; do
26-
grt syn -G$G -Osyn_ex -P$P -A$az -S$S -Dt/0.2/0.2/0.4 -e $N
27-
grt strain syn_ex/$P
28-
grt rotation syn_ex/$P
29-
grt stress syn_ex/$P
25+
grt syn -G$G -Osyn_ex$N -A$az -S$S -Dt/0.2/0.2/0.4 -e $N
26+
grt strain syn_ex$N
27+
grt rotation syn_ex$N
28+
grt stress syn_ex$N
3029

3130
fn=2
3231
fe=-1
3332
fz=4
34-
grt syn -G$G -Osyn_sf -P$P -A$az -S$S -F$fn/$fe/$fz -Dt/0.1/0.3/0.6 -e $N
35-
grt strain syn_sf/$P
36-
grt rotation syn_sf/$P
37-
grt stress syn_sf/$P
33+
grt syn -G$G -Osyn_sf$N -A$az -S$S -F$fn/$fe/$fz -Dt/0.1/0.3/0.6 -e $N
34+
grt strain syn_sf$N
35+
grt rotation syn_sf$N
36+
grt stress syn_sf$N
3837

3938
stk=77
4039
dip=88
4140
rak=99
42-
grt syn -G$G -Osyn_dc -P$P -A$az -S$S -M$stk/$dip/$rak -Dp/0.6 -e $N
43-
grt strain syn_dc/$P
44-
grt rotation syn_dc/$P
45-
grt stress syn_dc/$P
41+
grt syn -G$G -Osyn_dc$N -A$az -S$S -M$stk/$dip/$rak -Dp/0.6 -e $N
42+
grt strain syn_dc$N
43+
grt rotation syn_dc$N
44+
grt stress syn_dc$N
4645

4746
M11=1
4847
M12=-2
4948
M13=-5
5049
M22=0.5
5150
M23=3
5251
M33=1.2
53-
grt syn -G$G -Osyn_mt -P$P -A$az -S$S -T$M11/$M12/$M13/$M22/$M23/$M33 -Dr/3 -e $N
54-
grt strain syn_mt/$P
55-
grt rotation syn_mt/$P
56-
grt stress syn_mt/$P
52+
grt syn -G$G -Osyn_mt$N -A$az -S$S -T$M11/$M12/$M13/$M22/$M23/$M33 -Dr/3 -e $N
53+
grt strain syn_mt$N
54+
grt rotation syn_mt$N
55+
grt stress syn_mt$N
5756
done
5857

5958

example/compare_c_py/run_pygrt.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def compare3(st_py:Stream, c_prefix:str, ZNE:bool=False, dim2:bool=False):
2222
nerr = 0
2323
for tr_c in st_c:
2424
tr_py = st_py.select(channel=tr_c.stats.channel)[0]
25+
tr_c.data[tr_c.data == 0.0] = 1.0
2526
rerr = np.mean(np.abs(tr_c.data - tr_py.data) / np.abs(tr_c.data))
2627
if np.isnan(rerr) or np.isinf(rerr):
2728
rerr = 0.0
@@ -53,7 +54,7 @@ def static_compare3(resDct:dict, c_prefix:str):
5354
continue
5455
val1 = resDct[k]
5556
val2 = f.variables[k][:]
56-
print(k, np.mean(np.abs(val1 - val2)), np.max(val2))
57+
print(k, np.mean(np.abs(val1 - val2)), np.max(np.abs(val2)))
5758

5859
val2[val2 == 0.0] = 1.0
5960

@@ -105,52 +106,52 @@ def static_compare3(resDct:dict, c_prefix:str):
105106
M33=1.2
106107

107108
for ZNE in [False, True]:
109+
suffix = "-N" if ZNE else ""
108110
# synthetic
109-
110111
st = pygrt.utils.gen_syn_from_gf_EX(st_grn, S, az, ZNE=ZNE, calc_upar=True)
111112
sigs = pygrt.sigs.gen_triangle_wave(0.4, dt)
112113
pygrt.utils.stream_convolve(st, sigs)
113-
AVGRERR.append(compare3(st, "syn_ex/cout", ZNE=ZNE))
114+
AVGRERR.append(compare3(st, f"syn_ex{suffix}/", ZNE=ZNE))
114115
ststrain = pygrt.utils.compute_strain(st)
115116
strotation = pygrt.utils.compute_rotation(st)
116117
ststress = pygrt.utils.compute_stress(st)
117-
AVGRERR.append(compare3(ststrain, "syn_ex/cout.strain.", ZNE=ZNE, dim2=True))
118-
AVGRERR.append(compare3(strotation, "syn_ex/cout.rotation.", ZNE=ZNE, dim2=True))
119-
AVGRERR.append(compare3(ststress, "syn_ex/cout.stress.", ZNE=ZNE, dim2=True))
118+
AVGRERR.append(compare3(ststrain, f"syn_ex{suffix}/strain_", ZNE=ZNE, dim2=True))
119+
AVGRERR.append(compare3(strotation, f"syn_ex{suffix}/rotation_", ZNE=ZNE, dim2=True))
120+
AVGRERR.append(compare3(ststress, f"syn_ex{suffix}/stress_", ZNE=ZNE, dim2=True))
120121

121122

122123
st = pygrt.utils.gen_syn_from_gf_SF(st_grn, S, fn, fe, fz, az, ZNE=ZNE, calc_upar=True)
123124
sigs = pygrt.sigs.gen_trap_wave(0.1, 0.3, 0.6, dt)
124125
pygrt.utils.stream_convolve(st, sigs)
125-
AVGRERR.append(compare3(st, "syn_sf/cout", ZNE=ZNE))
126+
AVGRERR.append(compare3(st, f"syn_sf{suffix}/", ZNE=ZNE))
126127
ststrain = pygrt.utils.compute_strain(st)
127128
strotation = pygrt.utils.compute_rotation(st)
128129
ststress = pygrt.utils.compute_stress(st)
129-
AVGRERR.append(compare3(ststrain, "syn_sf/cout.strain.", ZNE=ZNE, dim2=True))
130-
AVGRERR.append(compare3(strotation, "syn_sf/cout.rotation.", ZNE=ZNE, dim2=True))
131-
AVGRERR.append(compare3(ststress, "syn_sf/cout.stress.", ZNE=ZNE, dim2=True))
130+
AVGRERR.append(compare3(ststrain, f"syn_sf{suffix}/strain_", ZNE=ZNE, dim2=True))
131+
AVGRERR.append(compare3(strotation, f"syn_sf{suffix}/rotation_", ZNE=ZNE, dim2=True))
132+
AVGRERR.append(compare3(ststress, f"syn_sf{suffix}/stress_", ZNE=ZNE, dim2=True))
132133

133134
st = pygrt.utils.gen_syn_from_gf_DC(st_grn, S, stk, dip, rak, az, ZNE=ZNE, calc_upar=True)
134135
sigs = pygrt.sigs.gen_parabola_wave(0.6, dt)
135136
pygrt.utils.stream_convolve(st, sigs)
136-
AVGRERR.append(compare3(st, "syn_dc/cout", ZNE=ZNE))
137+
AVGRERR.append(compare3(st, f"syn_dc{suffix}/", ZNE=ZNE))
137138
ststrain = pygrt.utils.compute_strain(st)
138139
strotation = pygrt.utils.compute_rotation(st)
139140
ststress = pygrt.utils.compute_stress(st)
140-
AVGRERR.append(compare3(ststrain, "syn_dc/cout.strain.", ZNE=ZNE, dim2=True))
141-
AVGRERR.append(compare3(strotation, "syn_dc/cout.rotation.", ZNE=ZNE, dim2=True))
142-
AVGRERR.append(compare3(ststress, "syn_dc/cout.stress.", ZNE=ZNE, dim2=True))
141+
AVGRERR.append(compare3(ststrain, f"syn_dc{suffix}/strain_", ZNE=ZNE, dim2=True))
142+
AVGRERR.append(compare3(strotation, f"syn_dc{suffix}/rotation_", ZNE=ZNE, dim2=True))
143+
AVGRERR.append(compare3(ststress, f"syn_dc{suffix}/stress_", ZNE=ZNE, dim2=True))
143144

144145
st = pygrt.utils.gen_syn_from_gf_MT(st_grn, S, [M11,M12,M13,M22,M23,M33], az, ZNE=ZNE, calc_upar=True)
145146
sigs = pygrt.sigs.gen_ricker_wave(3, dt)
146147
pygrt.utils.stream_convolve(st, sigs)
147-
AVGRERR.append(compare3(st, "syn_mt/cout", ZNE=ZNE))
148+
AVGRERR.append(compare3(st, f"syn_mt{suffix}/", ZNE=ZNE))
148149
ststrain = pygrt.utils.compute_strain(st)
149150
strotation = pygrt.utils.compute_rotation(st)
150151
ststress = pygrt.utils.compute_stress(st)
151-
AVGRERR.append(compare3(ststrain, "syn_mt/cout.strain.", ZNE=ZNE, dim2=True))
152-
AVGRERR.append(compare3(strotation, "syn_mt/cout.rotation.", ZNE=ZNE, dim2=True))
153-
AVGRERR.append(compare3(ststress, "syn_mt/cout.stress.", ZNE=ZNE, dim2=True))
152+
AVGRERR.append(compare3(ststrain, f"syn_mt{suffix}/strain_", ZNE=ZNE, dim2=True))
153+
AVGRERR.append(compare3(strotation, f"syn_mt{suffix}/rotation_", ZNE=ZNE, dim2=True))
154+
AVGRERR.append(compare3(ststress, f"syn_mt{suffix}/stress_", ZNE=ZNE, dim2=True))
154155

155156

156157
#-------------------------- Static -----------------------------------------

example/compute_strain_stress/dynamic/run_grt.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ az=30
2222
grt syn -G${out}/${modname}_${depsrc}_${deprcv}_${dist} -A$az -S$S -M$stk/$dip/$rak -Dp/0.6 -Osyn_dc -e
2323

2424

25-
grt strain syn_dc/out
26-
grt stress syn_dc/out
25+
grt strain syn_dc
26+
grt stress syn_dc

example/convolve_signals/plot.sh

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@ rm -rf $out
77
mkdir -p $out
88

99

10-
for synpath in syn*; do
11-
for cout in $synpath/cout*; do
12-
fname=$(basename $cout)
13-
echo $cout $(dirname $cout)/p${fname:1:}
10+
for synpath in syn_ex syn_sf syn_dc syn_mt; do
11+
for ch in Z R T; do
12+
cname=c_$synpath/$ch.sac
13+
pname=p_$synpath/$ch.sac
14+
echo $cname $pname
1415
sac << EOF
15-
r $cout $(dirname $cout)/p${fname:1}
16+
r $cname $pname
1617
qdp off
1718
color red inc list blue red
1819
p1
19-
saveimg $out/compare_${synpath}_${fname}.pdf
20+
saveimg $out/compare_${synpath}_${ch}.pdf
2021
q
2122
EOF
2223

example/convolve_signals/run_grt.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,32 @@ dt=0.01
1111
modname="milrow"
1212
out="GRN"
1313

14+
rm -rf $out
15+
1416
grt greenfn -M${modname} -O${out} -N${nt}/${dt} -D${depsrc}/${deprcv} -R${dist}
1517

18+
rm -rf c_syn* p_syn*
1619
# convolve different signals
1720
G=$out/${modname}_${depsrc}_${deprcv}_${dist}
18-
P=cout
1921
S=1e24
2022
az=39.2
21-
grt syn -G$G -Osyn_ex -P$P -A$az -S$S -Dt/0.2/0.2/0.4
23+
grt syn -G$G -Oc_syn_ex -A$az -S$S -Dt/0.2/0.2/0.4
2224

2325
fn=2
2426
fe=-1
2527
fz=4
26-
grt syn -G$G -Osyn_sf -P$P -A$az -S$S -F$fn/$fe/$fz -Dt/0.1/0.3/0.6
28+
grt syn -G$G -Oc_syn_sf -A$az -S$S -F$fn/$fe/$fz -Dt/0.1/0.3/0.6
2729

2830
stk=77
2931
dip=88
3032
rak=99
31-
grt syn -G$G -Osyn_dc -P$P -A$az -S$S -M$stk/$dip/$rak -Dp/0.6
33+
grt syn -G$G -Oc_syn_dc -A$az -S$S -M$stk/$dip/$rak -Dp/0.6
3234

3335
M11=1
3436
M12=-2
3537
M13=-5
3638
M22=0.5
3739
M23=3
3840
M33=1.2
39-
grt syn -G$G -Osyn_mt -P$P -A$az -S$S -T$M11/$M12/$M13/$M22/$M23/$M33 -Dr/3
41+
grt syn -G$G -Oc_syn_mt -A$az -S$S -T$M11/$M12/$M13/$M22/$M23/$M33 -Dr/3
4042

example/convolve_signals/run_pygrt.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@
2323
st = pygrt.utils.gen_syn_from_gf_EX(st_grn, S, az)
2424
sigs = pygrt.sigs.gen_triangle_wave(0.4, dt)
2525
pygrt.utils.stream_convolve(st, sigs)
26-
pygrt.utils.stream_write_sac(st, "syn_ex/pout")
26+
pygrt.utils.stream_write_sac(st, "p_syn_ex/")
2727

2828
st = pygrt.utils.gen_syn_from_gf_SF(st_grn, S, 2, -1, 4, az)
2929
sigs = pygrt.sigs.gen_trap_wave(0.1, 0.3, 0.6, dt)
3030
pygrt.utils.stream_convolve(st, sigs)
31-
pygrt.utils.stream_write_sac(st, "syn_sf/pout")
31+
pygrt.utils.stream_write_sac(st, "p_syn_sf/")
3232

3333
st = pygrt.utils.gen_syn_from_gf_DC(st_grn, S, 77, 88, 99, az)
3434
sigs = pygrt.sigs.gen_parabola_wave(0.6, dt)
3535
pygrt.utils.stream_convolve(st, sigs)
36-
pygrt.utils.stream_write_sac(st, "syn_dc/pout")
36+
pygrt.utils.stream_write_sac(st, "p_syn_dc/")
3737

3838
st = pygrt.utils.gen_syn_from_gf_MT(st_grn, S, [1,-2,-5,0.5,3,1.2], az)
3939
sigs = pygrt.sigs.gen_ricker_wave(3, dt)
4040
pygrt.utils.stream_convolve(st, sigs)
41-
pygrt.utils.stream_write_sac(st, "syn_mt/pout")
41+
pygrt.utils.stream_write_sac(st, "p_syn_mt/")

example/seafloor/run_grt.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ grt greenfn -M${modname} -O${out} -N${nt}/${dt} -D${depsrc}/${deprcv} -R${dist}
1919
# just give a random focal mechanism
2020
grt syn -G${out}/${modname}_${depsrc}_${deprcv}_${dist} -A20 -S1e20 -M100/20/120 -OSYN -e
2121
# compute stress
22-
grt stress SYN/out
22+
grt stress SYN

0 commit comments

Comments
 (0)