def test_calculation_addition_args(self): avg_periods = [0.05, 0.15, 1.0, 2.0, 4.0] gmm = GenericGmpeAvgSA(gmpe_name="KothaEtAl2020ESHM20", avg_periods=avg_periods, corr_func="akkar", sigma_mu_epsilon=1.0) rctx = RuptureContext() rctx.mag = 6. rctx.hypo_depth = 15. dctx = DistancesContext() dctx.rjb = np.array([1., 10., 30., 70.]) sctx = SitesContext() sctx.vs30 = 500.0 * np.ones(4) sctx.vs30measured = np.ones(4, dtype="bool") sctx.region = np.zeros(4, dtype=int) stdt = [const.StdDev.TOTAL] expected_mean = np.array( [-1.72305707, -2.2178751, -3.20100306, -4.19948242]) expected_stddev = np.array( [0.5532021, 0.5532021, 0.5532021, 0.5532021]) imtype = imt.AvgSA() mean, [stddev] = gmm.get_mean_and_stddevs(sctx, rctx, dctx, imtype, stdt) np.testing.assert_almost_equal(mean, expected_mean) np.testing.assert_almost_equal(stddev, expected_stddev)
def test_calculation_addition_args(self): avg_periods = [0.05, 0.15, 1.0, 2.0, 4.0] gmm = GenericGmpeAvgSA(gmpe_name="KothaEtAl2019SERA", avg_periods=avg_periods, corr_func="akkar", sigma_mu_epsilon=1.0) rctx = RuptureContext() rctx.mag = 6. rctx.hypo_depth = 15. dctx = DistancesContext() dctx.rjb = np.array([1., 10., 30., 70.]) sctx = SitesContext() sctx.vs30 = 500.0 * np.ones(4) sctx.vs30measured = np.ones(4, dtype="bool") stdt = [const.StdDev.TOTAL] expected_mean = np.array( [-1.45586338, -1.94419233, -2.91884965, -3.91919928]) expected_stddev = np.array( [0.58317566, 0.58317566, 0.58317566, 0.58317566]) imtype = imt.AvgSA() mean, [stddev] = gmm.get_mean_and_stddevs(sctx, rctx, dctx, imtype, stdt) np.testing.assert_almost_equal(mean, expected_mean) np.testing.assert_almost_equal(stddev, expected_stddev)
def test_gm_calculation_soil_reference(self): """ Test mean and std calculation - CY14 on reference rock""" # Modified gmpe mgmpe = CY14SiteTerm(gmpe_name='ChiouYoungs2014') # Set parameters sites = Dummy.get_site_collection(4, vs30=1130., vs30measured=True, z1pt0=0.) rup = Dummy.get_rupture(mag=6.0) rup.dip = 90. rup.ztor = 0. dists = DistancesContext() dists.rrup = np.array([1., 10., 30., 70.]) dists.rx = np.array([1., 10., 30., 70.]) dists.rjb = np.array([1., 10., 30., 70.]) imt = PGA() stdt = [const.StdDev.TOTAL] # Compute results mean, stds = mgmpe.get_mean_and_stddevs(sites, rup, dists, imt, stdt) # Compute the expected results gmpe = ChiouYoungs2014() mean_expected, stds_expected = gmpe.get_mean_and_stddevs( sites, rup, dists, imt, stdt) # Test that for reference soil conditions the modified GMPE gives the # same results of the original gmpe np.testing.assert_almost_equal(mean, mean_expected) np.testing.assert_almost_equal(stds, stds_expected)
def test01(self): filename = os.path.join(DATA_PATH, 'kappa.txt') gmm = AlAtikSigmaModel(gmpe_name='BindiEtAl2014Rjb', kappa_file=filename, kappa_val='high') sites = Dummy.get_site_collection(4, vs30=760.) rup = Dummy.get_rupture(mag=6.0) dists = DistancesContext() dists.rjb = np.array([1., 10., 30., 70.]) imt = SA(0.1) stdt = [const.StdDev.TOTAL] mean_expected, stds_expected = gmm.get_mean_and_stddevs( sites, rup, dists, imt, stdt)
def test02(self): # checks if gmpe is always being evaluated at vs30=760 # see HID 2.6.2 filename = os.path.join(DATA_PATH, 'kappa.txt') gmm = AlAtikSigmaModel(gmpe_name='YenierAtkinson2015ACME2019', kappa_file=filename, kappa_val='high') sites = Dummy.get_site_collection(4, vs30=760.) rup = Dummy.get_rupture(mag=6.0) dists = DistancesContext() dists.rjb = np.array([1., 10., 30., 70.]) dists.rrup = np.array([1., 10., 30., 70.]) imt = SA(0.1) stdt = [const.StdDev.TOTAL] mean_760, _ = gmm.get_mean_and_stddevs(sites, rup, dists, imt, stdt) sites2 = Dummy.get_site_collection(4, vs30=1500.) mean_1500, _ = gmm.get_mean_and_stddevs(sites2, rup, dists, imt, stdt) self.assertAlmostEqual(mean_760[-1], mean_1500[-1], 4)
def test_gm_calculationBA08_vs30variable(self): """ Test mean and std calculation - BA08 - Vs30 variable""" # Modified gmpe mgmpe = NRCan15SiteTerm(gmpe_name='BooreAtkinson2008') # Set parameters sites = Dummy.get_site_collection(3, vs30=[400., 600, 1000]) rup = Dummy.get_rupture(mag=6.0) dists = DistancesContext() dists.rjb = np.array([10., 10., 10.]) imt = PGA() stdt = [const.StdDev.TOTAL] # Computes results mean, stds = mgmpe.get_mean_and_stddevs(sites, rup, dists, imt, stdt) # Compute the expected results gmpe = BooreAtkinson2008() mean_expected, stds_expected = gmpe.get_mean_and_stddevs( sites, rup, dists, imt, stdt) # Test that for reference soil conditions the modified GMPE gives the # same results of the original gmpe np.testing.assert_almost_equal(mean[:-1], mean_expected[:-1]) np.testing.assert_almost_equal(stds[:-1], stds_expected[:-1])
def test_gm_calculationBA08_vs30variable(self): """ Test mean and std calculation - BA08 - Vs30 variable""" # Modified gmpe mgmpe = NRCan15SiteTerm(gmpe_name='BooreAtkinson2008') # Set parameters sites = Dummy.get_site_collection(3, vs30=[400., 600, 1000]) rup = Dummy.get_rupture(mag=6.0) dists = DistancesContext() dists.rjb = np.array([10., 10., 10.]) imt = PGA() stdt = [const.StdDev.TOTAL] # Computes results mean, stds = mgmpe.get_mean_and_stddevs(sites, rup, dists, imt, stdt) # Compute the expected results gmpe = BooreAtkinson2008() mean_expected, stds_expected = gmpe.get_mean_and_stddevs(sites, rup, dists, imt, stdt) # Test that for reference soil conditions the modified GMPE gives the # same results of the original gmpe np.testing.assert_almost_equal(mean[:-1], mean_expected[:-1]) np.testing.assert_almost_equal(stds[:-1], stds_expected[:-1])
def setUp(self): # Set parameters - Setting z1pt0 does not make sense but here we # want to make sure that the modified gmm provided GM amplified # by the site term exactly as the original model. sites = Dummy.get_site_collection(4, vs30=400., vs30measured=True, z1pt0=0.) rup = Dummy.get_rupture(mag=6.0) rup.dip = 90. rup.ztor = 0. dists = DistancesContext() dists.rrup = np.array([1., 10., 30., 70.]) dists.rx = np.array([1., 10., 30., 70.]) dists.rjb = np.array([1., 10., 30., 70.]) stdt = [const.StdDev.TOTAL] self.rup = rup self.dists = dists self.stdt = stdt self.sites = sites
def extrapolate_in_PSA(self, sites, rup, dists, imt_high, set_imt, stds_types, imt): extrap_mean = [] t_log10 = np.log10([im for im in set_imt]) for d in np.arange(0, len(dists.rjb)): dist = DistancesContext() if hasattr(dists, 'rjb'): dist.rjb = np.array([dists.rjb[d]]) if hasattr(dists, 'rrup'): dist.rrup = np.array([dists.rrup[d]]) means_log10 = [] for im in set_imt: mean_ln, _ = self.gmpe.get_mean_and_stddevs( sites, rup, dist, SA(im), stds_types) mean = np.exp(mean_ln[0]) means_log10.append(np.log10(mean)) mb = np.polyfit(t_log10, means_log10, 1) mean_imt_log10 = mb[0] * np.log10(imt) + mb[1] extrap_mean.append(np.log(10**mean_imt_log10)) return extrap_mean