Skip to content

Commit

Permalink
more refactoring + fix cb14 mgmpe
Browse files Browse the repository at this point in the history
  • Loading branch information
CB-quakemodel committed Nov 16, 2024
1 parent 6bbc853 commit aaa26f9
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 10 deletions.
13 changes: 12 additions & 1 deletion openquake/hazardlib/gsim/atkinson_macias_2009.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from openquake.hazardlib.gsim.base import GMPE, CoeffsTable
from openquake.hazardlib import const
from openquake.hazardlib.imt import PGA, SA
from openquake.hazardlib.gsim.mgmpe.cb14_basin_term import _get_cb14_basin_term


def _get_distance_term(C, rrup, mag):
Expand Down Expand Up @@ -77,6 +78,12 @@ class AtkinsonMacias2009(GMPE):
#: Required distance measure is rupture distance
REQUIRES_DISTANCES = {'rrup'}

def __init__(self, cb14_basin_term=False):
if cb14_basin_term:
self.REQUIRES_SITES_PARAMETERS = frozenset(
self.REQUIRES_SITES_PARAMETERS | {'z2pt5'})
self.cb14_basin_term = cb14_basin_term

def compute(self, ctx: np.recarray, imts, mean, sig, tau, phi):
"""
See :meth:`superclass method
Expand All @@ -89,7 +96,11 @@ def compute(self, ctx: np.recarray, imts, mean, sig, tau, phi):
_get_distance_term(C, ctx.rrup, ctx.mag))
# Convert mean from cm/s and cm/s/s and from common logarithm to
# natural logarithm
mean[m] = np.log((10.0 ** (imean - 2.0)) / g)
ln_mean = np.log((10.0 ** (imean - 2.0)) / g)
# Apply CB14 basin term if specified
if self.cb14_basin_term:
ln_mean += _get_cb14_basin_term(imt, ctx)
mean[m] = ln_mean
sig[m] = np.log(10.0 ** C["sigma"])

COEFFS = CoeffsTable(sa_damping=5, table="""
Expand Down
3 changes: 1 addition & 2 deletions openquake/hazardlib/gsim/kuehn_2020.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,8 +647,7 @@ class KuehnEtAl2020SInter(GMPE):
m_b: The magnitude scaling breakpoint. This term is defined for each region
and tectonic region type, but this can also be over-ridden by the user
:param bool m9_basin_term: Apply the M9 basin term instead of the GMM's
native basin term
:param bool m9_basin_term: Apply the M9 basin adjustment
:param bool usgs_basin_scaling: Scaling factor to be applied to basin term
based on USGS basin model
Expand Down
6 changes: 3 additions & 3 deletions openquake/hazardlib/gsim/mgmpe/cb14_basin_term.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@
from openquake.hazardlib.gsim.campbell_bozorgnia_2014 import CampbellBozorgnia2014


def _get_cb14_basin_term(ctx, C, jpn_flag=False):
def _get_cb14_basin_term(imt, ctx, jpn_flag=False):
"""
Get the basin response term defined in equation 20 of the Campbell and
Bozorgnia (2014) GMM paper.
Currently the global basin term is provided (i.e. the Japan-regionalised
basin term is for now turned off).
"""
C = CampbellBozorgnia2014.COEFFS[imt]
z2pt5 = ctx.z2pt5
fb = np.zeros(len(z2pt5))
idx = z2pt5 < 1.0
Expand Down Expand Up @@ -81,5 +82,4 @@ def compute(self, ctx: np.recarray, imts, mean, sig, tau, phi):
"""
self.gmpe.compute(ctx, imts, mean, sig, tau, phi)
for m, imt in enumerate(imts):
C = CampbellBozorgnia2014.COEFFS[imt]
mean[m] += _get_cb14_basin_term(ctx, C)
mean[m] += _get_cb14_basin_term(ctx)
15 changes: 11 additions & 4 deletions openquake/hazardlib/gsim/parker_2020.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,7 @@ class ParkerEtAl2020SInter(GMPE):
"AK", "Cascadia", "CAM_S", "CAM_N", "JP_Pac",
"JP_Phi", "SA_N", "SA_S", "TW_W", "TW_E")
:param str basin: Choice of basin region ("Out" or "Seattle")
:param bool m9_basin_term: Apply the M9 basin term instead of the GMM's
native basin term
:param bool m9_basin_term: Apply the M9 basin term adjustment
:param bool usgs_basin_scaling: Scaling factor to be applied to basin term
based on USGS basin model
:param float sigma_mu_epsilon: Number of standard deviations to multiply
Expand Down Expand Up @@ -406,6 +405,8 @@ class ParkerEtAl2020SInter(GMPE):
#: Required distance measure is closest distance to rupture, for
#: interface events
REQUIRES_DISTANCES = {'rrup'}

# Other required attributes
REQUIRES_ATTRIBUTES = {'region', 'saturation_region', 'basin',
'm9_basin_term' 'usgs_basin_scaling',
'sigma_mu_epsilon'}
Expand Down Expand Up @@ -477,8 +478,14 @@ def compute(self, ctx: np.recarray, imts, mean, sig, tau, phi):
if self.m9_basin_term and imt != PGV:
if imt.period >= 1.9:
m9_adj = _get_adjusted_m9_basin_term(C, ctx.z2pt5)
fb[ctx.z2pt5 >= 6.0] += m9_adj[ctx.z2pt5 >= 6.0]

if fb != 0.0:
fb[ctx.z2pt5 >= 6.0] += m9_adj[ctx.z2pt5 >= 6.0]
else:
fb = m9_adj # fb is zero if no region (no basin) thus
# just take the adjusted m9 term instead
# for the basin amplification given has
# been specified by user

# Now get the mean with basin term added
mean[m] = pre_baf_mean + (fb * usgs_baf)

Expand Down

0 comments on commit aaa26f9

Please sign in to comment.