本文整理汇总了Python中openquake.hazardlib.gsim.base.RuptureContext.mag方法的典型用法代码示例。如果您正苦于以下问题:Python RuptureContext.mag方法的具体用法?Python RuptureContext.mag怎么用?Python RuptureContext.mag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openquake.hazardlib.gsim.base.RuptureContext
的用法示例。
在下文中一共展示了RuptureContext.mag方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_mag_greater_8pt5
# 需要导入模块: from openquake.hazardlib.gsim.base import RuptureContext [as 别名]
# 或者: from openquake.hazardlib.gsim.base.RuptureContext import mag [as 别名]
def test_mag_greater_8pt5(self):
gmpe = SadighEtAl1997()
sctx = SitesContext()
rctx = RuptureContext()
dctx = DistancesContext()
rctx.rake = 0.0
dctx.rrup = numpy.array([0., 1.])
sctx.vs30 = numpy.array([800., 800.])
rctx.mag = 9.0
mean_rock_9, _ = gmpe.get_mean_and_stddevs(
sctx, rctx, dctx, PGA(), [StdDev.TOTAL]
)
rctx.mag = 8.5
mean_rock_8pt5, _ = gmpe.get_mean_and_stddevs(
sctx, rctx, dctx, PGA(), [StdDev.TOTAL]
)
numpy.testing.assert_allclose(mean_rock_9, mean_rock_8pt5)
sctx.vs30 = numpy.array([300., 300.])
rctx.mag = 9.0
mean_soil_9, _ = gmpe.get_mean_and_stddevs(
sctx, rctx, dctx, PGA(), [StdDev.TOTAL]
)
rctx.mag = 8.5
mean_soil_8pt5, _ = gmpe.get_mean_and_stddevs(
sctx, rctx, dctx, PGA(), [StdDev.TOTAL]
)
numpy.testing.assert_allclose(mean_soil_9, mean_soil_8pt5)
示例2: test_get_mean_and_stddevs
# 需要导入模块: from openquake.hazardlib.gsim.base import RuptureContext [as 别名]
# 或者: from openquake.hazardlib.gsim.base.RuptureContext import mag [as 别名]
def test_get_mean_and_stddevs(self):
"""
Tests mean and standard deviations without amplification
"""
gsim = GMPETable(gmpe_table=self.TABLE_FILE)
rctx = RuptureContext()
rctx.mag = 6.0
dctx = DistancesContext()
# Test values at the given distances and those outside range
dctx.rjb = np.array([0.5, 1.0, 10.0, 100.0, 500.0])
sctx = SitesContext()
stddevs = [const.StdDev.TOTAL]
expected_mean = np.array([2.0, 2.0, 1.0, 0.5, 1.0E-20])
# PGA
mean, sigma = gsim.get_mean_and_stddevs(sctx, rctx, dctx,
imt_module.PGA(),
stddevs)
np.testing.assert_array_almost_equal(np.exp(mean), expected_mean, 5)
np.testing.assert_array_almost_equal(sigma[0], 0.5 * np.ones(5), 5)
# SA
mean, sigma = gsim.get_mean_and_stddevs(sctx, rctx, dctx,
imt_module.SA(1.0),
stddevs)
np.testing.assert_array_almost_equal(np.exp(mean), expected_mean, 5)
np.testing.assert_array_almost_equal(sigma[0], 0.8 * np.ones(5), 5)
# PGV
mean, sigma = gsim.get_mean_and_stddevs(sctx, rctx, dctx,
imt_module.PGV(),
stddevs)
np.testing.assert_array_almost_equal(np.exp(mean),
10. * expected_mean,
5)
np.testing.assert_array_almost_equal(sigma[0], 0.5 * np.ones(5), 5)
示例3: test_get_mean_table
# 需要导入模块: from openquake.hazardlib.gsim.base import RuptureContext [as 别名]
# 或者: from openquake.hazardlib.gsim.base.RuptureContext import mag [as 别名]
def test_get_mean_table(self, idx=0):
"""
Test the retrieval of the mean amplification tables for a given
magnitude and IMT
"""
rctx = RuptureContext()
rctx.mag = 6.0
# PGA
expected_table = np.ones([10, 2])
expected_table[:, self.IDX] *= 1.5
np.testing.assert_array_almost_equal(
self.amp_table.get_mean_table(imt_module.PGA(), rctx),
expected_table)
# SA
expected_table[:, self.IDX] = 2.0 * np.ones(10)
np.testing.assert_array_almost_equal(
self.amp_table.get_mean_table(imt_module.SA(0.5), rctx),
expected_table)
# SA (period interpolation)
interpolator = interp1d(np.log10(self.amp_table.periods),
np.log10(np.array([1.5, 2.0, 0.5])))
period = 0.3
expected_table[:, self.IDX] = (
10.0 ** interpolator(np.log10(period))) * np.ones(10.)
np.testing.assert_array_almost_equal(
self.amp_table.get_mean_table(imt_module.SA(period), rctx),
expected_table)
示例4: test_get_mean_and_stddevs_good
# 需要导入模块: from openquake.hazardlib.gsim.base import RuptureContext [as 别名]
# 或者: from openquake.hazardlib.gsim.base.RuptureContext import mag [as 别名]
def test_get_mean_and_stddevs_good(self):
"""
Tests the full execution of the GMPE tables for valid data
"""
gsim = GMPETable(gmpe_table=self.TABLE_FILE)
rctx = RuptureContext()
rctx.mag = 6.0
rctx.rake = 90.0
dctx = DistancesContext()
# Test values at the given distances and those outside range
dctx.rjb = np.array([0.5, 1.0, 10.0, 100.0, 500.0])
sctx = SitesContext()
stddevs = [const.StdDev.TOTAL]
expected_mean = np.array([20.0, 20.0, 10.0, 5.0, 1.0E-19])
# PGA
mean, sigma = gsim.get_mean_and_stddevs(sctx, rctx, dctx,
imt_module.PGA(),
stddevs)
np.testing.assert_array_almost_equal(np.exp(mean), expected_mean, 5)
np.testing.assert_array_almost_equal(sigma[0], 0.25 * np.ones(5), 5)
# SA
mean, sigma = gsim.get_mean_and_stddevs(sctx, rctx, dctx,
imt_module.SA(1.0),
stddevs)
np.testing.assert_array_almost_equal(np.exp(mean), expected_mean, 5)
np.testing.assert_array_almost_equal(sigma[0], 0.4 * np.ones(5), 5)
示例5: test_mag_dist_outside_range
# 需要导入模块: from openquake.hazardlib.gsim.base import RuptureContext [as 别名]
# 或者: from openquake.hazardlib.gsim.base.RuptureContext import mag [as 别名]
def test_mag_dist_outside_range(self):
sctx = SitesContext()
rctx = RuptureContext()
dctx = DistancesContext()
# rupture with Mw = 3 (Mblg=2.9434938048208452) at rhypo = 1 must give
# same mean as rupture with Mw = 4.4 (Mblg=4.8927897867183798) at
# rhypo = 10
rctx.mag = 2.9434938048208452
dctx.rhypo = numpy.array([1])
mean_mw3_d1, _ = self.GSIM_CLASS().get_mean_and_stddevs(
sctx, rctx, dctx, SA(0.1, 5), [StdDev.TOTAL]
)
rctx.mag = 4.8927897867183798
dctx.rhypo = numpy.array([10])
mean_mw4pt4_d10, _ = self.GSIM_CLASS().get_mean_and_stddevs(
sctx, rctx, dctx, SA(0.1, 5), [StdDev.TOTAL]
)
self.assertAlmostEqual(float(mean_mw3_d1), float(mean_mw4pt4_d10))
# rupture with Mw = 9 (Mblg = 8.2093636421088814) at rhypo = 1500 km
# must give same mean as rupture with Mw = 8.2
# (Mblg = 7.752253535347597) at rhypo = 1000
rctx.mag = 8.2093636421088814
dctx.rhypo = numpy.array([1500.])
mean_mw9_d1500, _ = self.GSIM_CLASS().get_mean_and_stddevs(
sctx, rctx, dctx, SA(0.1, 5), [StdDev.TOTAL]
)
rctx.mag = 7.752253535347597
dctx.rhypo = numpy.array([1000.])
mean_mw8pt2_d1000, _ = self.GSIM_CLASS().get_mean_and_stddevs(
sctx, rctx, dctx, SA(0.1, 5), [StdDev.TOTAL]
)
self.assertAlmostEqual(mean_mw9_d1500, mean_mw8pt2_d1000)
示例6: test_dist_not_in_increasing_order
# 需要导入模块: from openquake.hazardlib.gsim.base import RuptureContext [as 别名]
# 或者: from openquake.hazardlib.gsim.base.RuptureContext import mag [as 别名]
def test_dist_not_in_increasing_order(self):
sctx = SitesContext()
rctx = RuptureContext()
dctx = DistancesContext()
rctx.mag = 5.
dctx.rhypo = numpy.array([150, 100])
mean_150_100, _ = self.GSIM_CLASS().get_mean_and_stddevs(
sctx, rctx, dctx, SA(0.1, 5), [StdDev.TOTAL]
)
dctx.rhypo = numpy.array([100, 150])
mean_100_150, _ = self.GSIM_CLASS().get_mean_and_stddevs(
sctx, rctx, dctx, SA(0.1, 5), [StdDev.TOTAL]
)
self.assertAlmostEqual(mean_150_100[1], mean_100_150[0])
self.assertAlmostEqual(mean_150_100[0], mean_100_150[1])
示例7: test_get_mean_stddevs_unsupported_stddev
# 需要导入模块: from openquake.hazardlib.gsim.base import RuptureContext [as 别名]
# 或者: from openquake.hazardlib.gsim.base.RuptureContext import mag [as 别名]
def test_get_mean_stddevs_unsupported_stddev(self):
"""
Tests the execution of the GMPE with an unsupported standard deviation
type
"""
gsim = GMPETable(gmpe_table=self.TABLE_FILE)
rctx = RuptureContext()
rctx.mag = 6.0
dctx = DistancesContext()
# Test values at the given distances and those outside range
dctx.rjb = np.array([0.5, 1.0, 10.0, 100.0, 500.0])
sctx = SitesContext()
sctx.vs30 = 1000. * np.ones(5)
stddevs = [const.StdDev.TOTAL, const.StdDev.INTER_EVENT]
with self.assertRaises(ValueError) as ve:
gsim.get_mean_and_stddevs(sctx, rctx, dctx, imt_module.PGA(),
stddevs)
self.assertEqual(str(ve.exception),
"Standard Deviation type Inter event not supported")
示例8: test_get_amplification_factors
# 需要导入模块: from openquake.hazardlib.gsim.base import RuptureContext [as 别名]
# 或者: from openquake.hazardlib.gsim.base.RuptureContext import mag [as 别名]
def test_get_amplification_factors(self):
"""
Tests the amplification tables
"""
rctx = RuptureContext()
rctx.mag = 6.0
dctx = DistancesContext()
# Takes distances at the values found in the table (not checking
# distance interpolation)
dctx.rjb = np.copy(self.amp_table.distances[:, 0, 0])
# Test Vs30 is 700.0 m/s midpoint between the 400 m/s and 1000 m/s
# specified in the table
sctx = SitesContext()
sctx.vs30 = 700.0 * np.ones_like(dctx.rjb)
stddevs = [const.StdDev.TOTAL]
expected_mean = np.ones_like(dctx.rjb)
expected_sigma = np.ones_like(dctx.rjb)
# Check PGA and PGV
mean_amp, sigma_amp = self.amp_table.get_amplification_factors(
imt_module.PGA(), sctx, rctx, dctx.rjb, stddevs)
np.testing.assert_array_almost_equal(
mean_amp,
midpoint(1.0, 1.5) * expected_mean)
np.testing.assert_array_almost_equal(
sigma_amp[0],
0.9 * expected_mean)
mean_amp, sigma_amp = self.amp_table.get_amplification_factors(
imt_module.PGV(), sctx, rctx, dctx.rjb, stddevs)
np.testing.assert_array_almost_equal(
mean_amp,
midpoint(1.0, 0.5) * expected_mean)
np.testing.assert_array_almost_equal(
sigma_amp[0],
0.9 * expected_mean)
# Sa (0.5)
mean_amp, sigma_amp = self.amp_table.get_amplification_factors(
imt_module.SA(0.5), sctx, rctx, dctx.rjb, stddevs)
np.testing.assert_array_almost_equal(
mean_amp,
midpoint(1.0, 2.0) * expected_mean)
np.testing.assert_array_almost_equal(
sigma_amp[0],
0.9 * expected_mean)
示例9: check_gmpe_adjustments
# 需要导入模块: from openquake.hazardlib.gsim.base import RuptureContext [as 别名]
# 或者: from openquake.hazardlib.gsim.base.RuptureContext import mag [as 别名]
def check_gmpe_adjustments(self, adj_gmpe_set, original_gmpe):
"""
Takes a set of three adjusted GMPEs representing the "low", "middle"
and "high" stress drop adjustments for Germany and compares them
against the original "target" GMPE for a variety of magnitudes
and styles of fauling.
"""
low_gsim, mid_gsim, high_gsim = adj_gmpe_set
tot_std = [const.StdDev.TOTAL]
for imt in self.imts:
for mag in self.mags:
for rake in self.rakes:
rctx = RuptureContext()
rctx.mag = mag
rctx.rake = rake
rctx.hypo_depth = 10.
# Get "original" values
mean = original_gmpe.get_mean_and_stddevs(self.sctx, rctx,
self.dctx, imt,
tot_std)[0]
mean = np.exp(mean)
# Get "low" adjustments (0.75 times the original)
low_mean = low_gsim.get_mean_and_stddevs(self.sctx, rctx,
self.dctx, imt,
tot_std)[0]
np.testing.assert_array_almost_equal(
np.exp(low_mean) / mean, 0.75 * np.ones_like(low_mean))
# Get "middle" adjustments (1.25 times the original)
mid_mean = mid_gsim.get_mean_and_stddevs(self.sctx, rctx,
self.dctx, imt,
tot_std)[0]
np.testing.assert_array_almost_equal(
np.exp(mid_mean) / mean, 1.25 * np.ones_like(mid_mean))
# Get "high" adjustments (1.5 times the original)
high_mean = high_gsim.get_mean_and_stddevs(self.sctx, rctx,
self.dctx, imt,
tot_std)[0]
np.testing.assert_array_almost_equal(
np.exp(high_mean) / mean,
1.5 * np.ones_like(high_mean))
示例10: test_get_sigma_table
# 需要导入模块: from openquake.hazardlib.gsim.base import RuptureContext [as 别名]
# 或者: from openquake.hazardlib.gsim.base.RuptureContext import mag [as 别名]
def test_get_sigma_table(self):
"""
Test the retrieval of the standard deviation modification tables
for a given magnitude and IMT
"""
rctx = RuptureContext()
rctx.mag = 6.0
# PGA
expected_table = np.ones([10, 2])
expected_table[:, self.IDX] *= 0.8
stddevs = ["Total"]
pga_table = self.amp_table.get_sigma_tables(imt_module.PGA(),
rctx,
stddevs)[0]
np.testing.assert_array_almost_equal(pga_table, expected_table)
# SA (for coverage)
sa_table = self.amp_table.get_sigma_tables(imt_module.SA(0.3),
rctx,
stddevs)[0]
np.testing.assert_array_almost_equal(sa_table, expected_table)
示例11: test_rhypo_smaller_than_15
# 需要导入模块: from openquake.hazardlib.gsim.base import RuptureContext [as 别名]
# 或者: from openquake.hazardlib.gsim.base.RuptureContext import mag [as 别名]
def test_rhypo_smaller_than_15(self):
# test the calculation in case of rhypo distances less than 15 km
# (for rhypo=0 the distance term has a singularity). In this case the
# method should return values equal to the ones obtained by clipping
# distances at 15 km.
sctx = SitesContext()
sctx.vs30 = numpy.array([800.0, 800.0, 800.0])
rctx = RuptureContext()
rctx.mag = 5.0
rctx.rake = 0
dctx = DistancesContext()
dctx.rhypo = numpy.array([0.0, 10.0, 16.0])
dctx.rhypo.flags.writeable = False
mean_0, stds_0 = self.GSIM_CLASS().get_mean_and_stddevs(
sctx, rctx, dctx, PGA(), [StdDev.TOTAL])
setattr(dctx, 'rhypo', numpy.array([15.0, 15.0, 16.0]))
mean_15, stds_15 = self.GSIM_CLASS().get_mean_and_stddevs(
sctx, rctx, dctx, PGA(), [StdDev.TOTAL])
numpy.testing.assert_array_equal(mean_0, mean_15)
numpy.testing.assert_array_equal(stds_0, stds_15)
示例12: get_response_spectrum
# 需要导入模块: from openquake.hazardlib.gsim.base import RuptureContext [as 别名]
# 或者: from openquake.hazardlib.gsim.base.RuptureContext import mag [as 别名]
def get_response_spectrum(self, magnitude, distance, periods, rake=90, vs30=800, damping=0.05):
"""
"""
responses = np.zeros((len(periods),))
p_damping = damping * 100
rup = RuptureContext()
rup.mag = magnitude
rup.rake = rake
dists = DistancesContext()
dists.rjb = np.array([distance])
sites = SitesContext()
sites.vs30 = np.array([vs30])
stddev_types = [StdDev.TOTAL]
for i, period in enumerate(periods):
if period == 0:
imt = _PGA()
else:
imt = _SA(period, p_damping)
responses[i] = np.exp(self._gmpe.get_mean_and_stddevs(sites, rup, dists, imt, stddev_types)[0][0])
return ResponseSpectrum(periods, responses, unit='g', damping=damping)
示例13: test_equality
# 需要导入模块: from openquake.hazardlib.gsim.base import RuptureContext [as 别名]
# 或者: from openquake.hazardlib.gsim.base.RuptureContext import mag [as 别名]
def test_equality(self):
sctx1 = SitesContext()
sctx1.vs30 = numpy.array([500., 600., 700.])
sctx1.vs30measured = True
sctx1.z1pt0 = numpy.array([40., 50., 60.])
sctx1.z2pt5 = numpy.array([1, 2, 3])
sctx2 = SitesContext()
sctx2.vs30 = numpy.array([500., 600., 700.])
sctx2.vs30measured = True
sctx2.z1pt0 = numpy.array([40., 50., 60.])
sctx2.z2pt5 = numpy.array([1, 2, 3])
self.assertTrue(sctx1 == sctx2)
sctx2 = SitesContext()
sctx2.vs30 = numpy.array([500., 600.])
sctx2.vs30measured = True
sctx2.z1pt0 = numpy.array([40., 50., 60.])
sctx2.z2pt5 = numpy.array([1, 2, 3])
self.assertTrue(sctx1 != sctx2)
sctx2 = SitesContext()
sctx2.vs30 = numpy.array([500., 600., 700.])
sctx2.vs30measured = False
sctx2.z1pt0 = numpy.array([40., 50., 60.])
sctx2.z2pt5 = numpy.array([1, 2, 3])
self.assertTrue(sctx1 != sctx2)
sctx2 = SitesContext()
sctx2.vs30 = numpy.array([500., 600., 700.])
sctx2.vs30measured = True
sctx2.z1pt0 = numpy.array([40., 50., 60.])
self.assertTrue(sctx1 != sctx2)
rctx = RuptureContext()
rctx.mag = 5.
self.assertTrue(sctx1 != rctx)
示例14: AbrahamsonEtAl2014
# 需要导入模块: from openquake.hazardlib.gsim.base import RuptureContext [as 别名]
# 或者: from openquake.hazardlib.gsim.base.RuptureContext import mag [as 别名]
## This all works..... ##
ASK14 = AbrahamsonEtAl2014()
IMT = imt.PGA()
rctx = RuptureContext()
dctx = DistancesContext()
sctx = SitesContext()
sctx_rock = SitesContext()
rctx.rake = 0.0
rctx.dip = 90.0
rctx.ztor = 7.13
rctx.mag = 3.0
#rctx.mag = np.linspace(0.1,5.)
rctx.width = 10.0
rctx.hypo_depth = 8.0
#dctx.rrup = np.logspace(1,np.log10(200),100)
dctx.rrup = np.logspace(np.log10(10),np.log10(10.0),1)
# Assuming average ztor, get rjb:
dctx.rjb = np.sqrt(dctx.rrup**2 - rctx.ztor**2)
dctx.rhypo = dctx.rrup
dctx.rx = dctx.rjb
dctx.ry0 = dctx.rx
sctx.vs30 = np.ones_like(dctx.rrup) * 760.0
示例15: signal_end
# 需要导入模块: from openquake.hazardlib.gsim.base import RuptureContext [as 别名]
# 或者: from openquake.hazardlib.gsim.base.RuptureContext import mag [as 别名]
def signal_end(st, event_time, event_lon, event_lat, event_mag,
method=None, vmin=None, floor=None,
model=None, epsilon=2.0):
"""
Estimate end of signal by using a model of the 5-95% significant
duration, and adding this value to the "signal_split" time. This probably
only works well when the split is estimated with a p-wave picker since
the velocity method often ends up with split times that are well before
signal actually starts.
Args:
st (StationStream):
Stream of data.
event_time (UTCDateTime):
Event origin time.
event_mag (float):
Event magnitude.
event_lon (float):
Event longitude.
event_lat (float):
Event latitude.
method (str):
Method for estimating signal end time. Either 'velocity'
or 'model'.
vmin (float):
Velocity (km/s) for estimating end of signal. Only used if
method="velocity".
floor (float):
Minimum duration (sec) applied along with vmin.
model (str):
Short name of duration model to use. Must be defined in the
gmprocess/data/modules.yml file.
epsilon (float):
Number of standard deviations; if epsilon is 1.0, then the signal
window duration is the mean Ds + 1 standard deviation. Only used
for method="model".
Returns:
trace with stats dict updated to include a
stats['processing_parameters']['signal_end'] dictionary.
"""
# Load openquake stuff if method="model"
if method == "model":
mod_file = pkg_resources.resource_filename(
'gmprocess', os.path.join('data', 'modules.yml'))
with open(mod_file, 'r') as f:
mods = yaml.load(f)
# Import module
cname, mpath = mods['modules'][model]
dmodel = getattr(import_module(mpath), cname)()
# Set some "conservative" inputs (in that they will tend to give
# larger durations).
sctx = SitesContext()
sctx.vs30 = np.array([180.0])
sctx.z1pt0 = np.array([0.51])
rctx = RuptureContext()
rctx.mag = event_mag
rctx.rake = -90.0
dur_imt = imt.from_string('RSD595')
stddev_types = [const.StdDev.INTRA_EVENT]
for tr in st:
if not tr.hasParameter('signal_split'):
continue
if method == "velocity":
if vmin is None:
raise ValueError('Must specify vmin if method is "velocity".')
if floor is None:
raise ValueError('Must specify floor if method is "velocity".')
epi_dist = gps2dist_azimuth(
lat1=event_lat,
lon1=event_lon,
lat2=tr.stats['coordinates']['latitude'],
lon2=tr.stats['coordinates']['longitude'])[0] / 1000.0
end_time = event_time + max(floor, epi_dist / vmin)
elif method == "model":
if model is None:
raise ValueError('Must specify model if method is "model".')
epi_dist = gps2dist_azimuth(
lat1=event_lat,
lon1=event_lon,
lat2=tr.stats['coordinates']['latitude'],
lon2=tr.stats['coordinates']['longitude'])[0] / 1000.0
dctx = DistancesContext()
# Repi >= Rrup, so substitution here should be conservative
# (leading to larger durations).
dctx.rrup = np.array([epi_dist])
lnmu, lnstd = dmodel.get_mean_and_stddevs(
sctx, rctx, dctx, dur_imt, stddev_types)
duration = np.exp(lnmu + epsilon * lnstd[0])
# Get split time
split_time = tr.getParameter('signal_split')['split_time']
end_time = split_time + float(duration)
else:
raise ValueError('method must be either "velocity" or "model".')
# Update trace params
end_params = {
#.........这里部分代码省略.........