Skip to content

Commit 20cd0b3

Browse files
authored
Merge pull request #55 from SCECcode/gp-mrf
GP method updates: Jbsim-3.0.0 and user-selectable merging frequency
2 parents aab28f8 + 57e9dda commit 20cd0b3

File tree

22 files changed

+1612
-150
lines changed

22 files changed

+1612
-150
lines changed

bbp/comps/anderson_gof.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"""
33
BSD 3-Clause License
44
5-
Copyright (c) 2023, University of Southern California
5+
Copyright (c) 2024, University of Southern California
66
All rights reserved.
77
88
Redistribution and use in source and binary forms, with or without
@@ -51,6 +51,16 @@
5151
from scipy import signal, stats
5252
from scipy.signal import butter, filtfilt
5353

54+
# Compatible with SciPy 1.4
55+
try:
56+
cumulative_trapezoid = integrate.cumulative_trapezoid
57+
except AttributeError:
58+
cumulative_trapezoid = integrate.cumtrapz
59+
try:
60+
simpson = integrate.simpson
61+
except AttributeError:
62+
simpson = integrate.simps
63+
5464
# Import BBP modules
5565
import bband_utils
5666
import plot_config
@@ -135,15 +145,15 @@ def eval_func2(p1, p2):
135145

136146
@staticmethod
137147
def integral(x, idt):
138-
return integrate.simps(x, x=None, dx=idt)
148+
return simpson(x, x=None, dx=idt)
139149

140150
@staticmethod
141151
def integral2(x, idt):
142-
return integrate.simps(x * x, x=None, dx=idt)
152+
return simpson(x * x, x=None, dx=idt)
143153

144154
@staticmethod
145155
def integ(array_in, idt):
146-
return integrate.cumtrapz(array_in, dx=idt)
156+
return cumulative_trapezoid(array_in, dx=idt)
147157

148158
@staticmethod
149159
def shift_bit_length(x):

bbp/comps/arias_duration.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
#!/usr/bin/env python3
12
"""
23
BSD 3-Clause License
34
4-
Copyright (c) 2021, University of Southern California
5+
Copyright (c) 2024, University of Southern California
56
All rights reserved.
67
78
Redistribution and use in source and binary forms, with or without
@@ -40,6 +41,12 @@
4041
import math
4142
import scipy.integrate
4243

44+
# Compatible with SciPy 1.4
45+
try:
46+
cumulative_trapezoid = scipy.integrate.cumulative_trapezoid
47+
except AttributeError:
48+
cumulative_trapezoid = scipy.integrate.cumtrapz
49+
4350
# Converting to cm units. Use approximation to g
4451
G_TO_CMS = 981.0 # %(cm/s)
4552

@@ -97,9 +104,9 @@ def ad_from_acc(a_in_peer_file, a_out_ad):
97104
# Integrate and calculate vel and disp arrays
98105
#
99106
acc_cms = [value * G_TO_CMS for value in acc]
100-
velo = list(dt * scipy.integrate.cumtrapz(acc_cms))
107+
velo = list(dt * cumulative_trapezoid(acc_cms))
101108
velo.insert(0, 0)
102-
disp = list(dt * scipy.integrate.cumtrapz(velo))
109+
disp = list(dt * cumulative_trapezoid(velo))
103110
disp.insert(0, 0)
104111

105112
#
@@ -138,7 +145,7 @@ def ad_from_acc(a_in_peer_file, a_out_ad):
138145
# Arias Intensities
139146
# Using the trapezoidal integration
140147
arias_intensity = [pow((value * G_TO_CMS), 2) for value in acc]
141-
tsum = list(scipy.integrate.cumtrapz(arias_intensity) * dt)
148+
tsum = list(cumulative_trapezoid(arias_intensity) * dt)
142149
tsum.insert(0, 0)
143150

144151
arias_intensity = [num * math.pi / (2 * G_TO_CMS) for num in tsum]

bbp/comps/jbsim.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"""
33
BSD 3-Clause License
44
5-
Copyright (c) 2023, University of Southern California
5+
Copyright (c) 2024, University of Southern California
66
All rights reserved.
77
88
Redistribution and use in source and binary forms, with or without
@@ -78,9 +78,18 @@ def run(self):
7878
a_statfile = os.path.join(install.A_IN_DATA_DIR,
7979
str(sim_id),
8080
self.r_stations)
81-
a_srffile = os.path.join(install.A_IN_DATA_DIR,
82-
str(sim_id),
83-
self.r_srffile)
81+
a_rupture_file = os.path.join(install.A_IN_DATA_DIR,
82+
str(sim_id),
83+
self.r_srffile)
84+
# RWG 20241025: jbsim-v3.0.0 is backward compatible with jbsim-v2.0.0
85+
# it can use rupture files in both SRF and MRF formats
86+
if os.path.splitext(a_rupture_file)[-1].lower() == ".srf":
87+
rupmod_type = "SRF"
88+
elif os.path.splitext(a_rupture_file)[-1].lower() == ".mrf":
89+
rupmod_type = "MRF"
90+
else:
91+
print("[ERROR]: Unknown rupture format in file %s" % (a_rupture_file))
92+
sys.exit(-1)
8493

8594
# Set directories, and make sure they exist
8695
a_indir = os.path.join(install.A_IN_DATA_DIR, str(sim_id))
@@ -106,9 +115,11 @@ def run(self):
106115
#
107116
progstring = ("%s latloncoords=1 slon=%f slat=%f " %
108117
(os.path.join(install.A_GP_BIN_DIR,
109-
"jbsim-v2.0.0"), slon, slat) +
118+
"jbsim-v3.0.0"), slon, slat) +
110119
"tshift_timedomain=1 use_closest_gf=1 " +
111-
"rupmodtype=SRF rupmodfile=%s " % a_srffile +
120+
"cgf_flag=%d " % (config.GF_CGFFLAG) +
121+
"rupmodtype=%s " % (rupmod_type) +
122+
"rupmodfile=%s " % (a_rupture_file) +
112123
"moment=-1 outdir=%s stat=%s " % (a_veldir, site) +
113124
"min_taper_range=0.0 max_taper_range=0.0 " +
114125
"gftype=fk gflocs=%s gftimes=%s gf_swap_bytes=%d " %

bbp/comps/jbsim_cfg.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22
"""
33
BSD 3-Clause License
44
5-
Copyright (c) 2021, University of Southern California
5+
Copyright (c) 2024, University of Southern California
66
All rights reserved.
77
88
Redistribution and use in source and binary forms, with or without
@@ -93,6 +93,11 @@ def __init__(self, vmodel_name):
9393
self.NTOUT = int(vmodel_params['NTOUT'])
9494
else:
9595
self.NTOUT = 4096
96+
# RWG 20241025: Added parameter GF_CGFFLAG
97+
if 'GF_CGFFLAG' in vmodel_params:
98+
self.GF_CGFFLAG = int(vmodel_params['GF_CGFFLAG'])
99+
else:
100+
self.GF_CGFFLAG = 0
96101

97102
# Now, configure other paramteres
98103
self.GF_SWAP_BYTES = 0

bbp/comps/match.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"""
33
BSD 3-Clause License
44
5-
Copyright (c) 2023, University of Southern California
5+
Copyright (c) 2024, University of Southern California
66
All rights reserved.
77
88
Redistribution and use in source and binary forms, with or without
@@ -87,11 +87,25 @@ def run(self):
8787
dirs = [a_tmpdir]
8888
bband_utils.mkdirs(dirs, print_cmd=False)
8989

90+
# Get pointer to the velocity model object
91+
vel_obj = velocity_models.get_velocity_model_by_name(self.vmodel_name)
92+
if vel_obj is None:
93+
raise bband_utils.ParameterError("Cannot find velocity model: %s" %
94+
(self.vmodel_name))
95+
96+
# Check for velocity model-specific parameters
97+
vmodel_params = vel_obj.get_codebase_params('gp')
98+
9099
# Start with defaults
91100
self.phase = config.PHASE
92101
self.hf_fhi = config.HF_FHI
93102
self.lf_flo = config.LF_FLO
94103

104+
# Check if we have a different merging frequency
105+
if 'MATCH_MERGING_FREQUENCY' in vmodel_params:
106+
self.hf_fhi = float(vmodel_params['MATCH_MERGING_FREQUENCY'])
107+
self.lf_flo = float(vmodel_params['MATCH_MERGING_FREQUENCY'])
108+
95109
# Set match method
96110
if config.MATCH_METHOD == 1:
97111
self.phase = 1
@@ -109,15 +123,6 @@ def run(self):
109123
slo = StationList(a_statfile)
110124
site_list = slo.get_station_list()
111125

112-
# Get pointer to the velocity model object
113-
vel_obj = velocity_models.get_velocity_model_by_name(self.vmodel_name)
114-
if vel_obj is None:
115-
raise bband_utils.ParameterError("Cannot find velocity model: %s" %
116-
(self.vmodel_name))
117-
118-
# Check for velocity model-specific parameters
119-
vmodel_params = vel_obj.get_codebase_params('gp')
120-
121126
# Figure out what DT we should use when resampling
122127

123128
# Figure out the LF DT value

bbp/comps/match_cfg.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22
"""
33
BSD 3-Clause License
44
5-
Copyright (c) 2021, University of Southern California
5+
Copyright (c) 2024, University of Southern California
66
All rights reserved.
77
88
Redistribution and use in source and binary forms, with or without
@@ -45,13 +45,16 @@ class MatchCfg(object):
4545
Define the configuration parameters for the Match program
4646
"""
4747
def __init__(self):
48-
self.HF_FHI = 1.0
48+
# Default merging frequency set
49+
self.DEFAULT_MERGING_FREQUENCY = 1.0
50+
51+
self.HF_FHI = self.DEFAULT_MERGING_FREQUENCY
4952
self.HF_FLO = "1.0e+15"
5053
self.HF_ORD = 4
5154
self.HF_TSTART = 0.0
5255

5356
self.LF_FHI = 0.0
54-
self.LF_FLO = 1.0
57+
self.LF_FLO = self.DEFAULT_MERGING_FREQUENCY
5558
self.LF_ORD = 4
5659
self.LF_TSTART = 0.0
5760

bbp/comps/rzz2015.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"""
33
BSD 3-Clause License
44
5-
Copyright (c) 2023, University of Southern California
5+
Copyright (c) 2024, University of Southern California
66
All rights reserved.
77
88
Redistribution and use in source and binary forms, with or without
@@ -45,6 +45,12 @@
4545
mpl.use('Agg') # Disable use of Tk/X11
4646
import pylab
4747

48+
# Compatible with SciPy 1.4
49+
try:
50+
cumulative_trapezoid = integrate.cumulative_trapezoid
51+
except AttributeError:
52+
cumulative_trapezoid = integrate.cumtrapz
53+
4854
# Import BBP modules
4955
import bband_utils
5056
import plot_config
@@ -106,7 +112,7 @@ def arias(self, F, dt, percent):
106112
n = len(F)
107113

108114
a_i = [pow(value, 2) for value in F]
109-
I = integrate.cumtrapz(a_i) * dt
115+
I = cumulative_trapezoid(a_i) * dt
110116
# Arias Intensity
111117
Ia = (F[0]**2) * dt / 2.0 + I[n-2] + (F[n-1]**2) * dt / 2.0
112118
It = (percent / 100.0) * Ia

bbp/src/gp/JordanBailey/.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
jbsim
33
jbsim3d
44
ray_stimes
5-
jbsim-v2.0.0
5+
jbsim-v2.0.0
6+
jbsim-v3.0.0

bbp/src/gp/JordanBailey/defs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#define U1FLAG 1
1212
#define U2FLAG 2
1313
#define U3FLAG 3
14+
#define MOMTEN_FLAG 4
1415

1516
#define RDONLY_FLAGS O_RDONLY
1617
#define RDWR_FLAGS O_RDWR

bbp/src/gp/JordanBailey/function.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ void sum_4gf_v2(float *,int,float *,struct gfheader *,int,int,float *,float *,fl
3636
void timeshift_gf_v2(float *,int,float *,struct gfheader *,int,float *,float *,int);
3737
void mech_4gf_v2(float *,float *,struct gfheader *,struct gfparam gfp,int,struct mechparam,float *,float *);
3838

39+
void momten_4gf(struct standrupformat *,int,int,float *,float *,struct gfheader *,struct gfparam,int,float *);
40+
3941
void read_beroza(struct beroza *,char *rfile,float *);
4042
void get_brmpars(struct beroza *,int,int,float *,float *,float *,float *);
4143
void beroza_stf(struct beroza *,int,int,float *,float *,float *,int,float *,float *);
@@ -57,6 +59,9 @@ void get_srfpars(struct standrupformat *,int,int,float *,float *,float *,float *
5759
void get_srfpars_v2(struct standrupformat *,int,int,float *,float *,struct mechparam *);
5860
void get_srfparsOLD(struct standrupformat *,int,int,float *,float *,float *,int,int,struct mechparam *);
5961
void srf_stf(struct standrupformat *,int,int,float *,float *,float *,int,float *,struct mechparam,float *);
62+
void srf_stf_v2(struct standrupformat *,int,int,float *,float *,float *,int,float *,struct mechparam,float *);
63+
64+
void get_indx_pow(float *,float *,float *,struct sgtindex *,struct geoprojection *,int);
6065

6166
char *skipval(int,char *);
6267
void do_cnvlv(float *,float *,int,float *,int);

0 commit comments

Comments
 (0)