def setUp(self): fname = gettemp(ampl_func) df = read_csv(fname, { 'ampcode': ampcode_dt, None: numpy.float64 }, index='ampcode') self.df = AmplFunction(df) # Set GMMs gmmA = BooreAtkinson2008() gmmB = BooreEtAl2014() # Set parameters dsts = [10., 15., 20., 30., 40.] dsts = [10.] imts = [PGA(), SA(1.0)] sites = Dummy.get_site_collection(len(dsts), vs30=760.0) self.mag = 5.5 rup = Dummy.get_rupture(mag=self.mag) ctx = RuptureContext.full(rup, sites) ctx.rjb = numpy.array(dsts) ctx.rrup = numpy.array(dsts) self.rrup = ctx.rrup # Compute GM on rock self.meastd = gmmA.get_mean_std([ctx], imts) # shape (2, N=1, M=2)
def test_gm_calculation_hard_rock(self): """ Test mean and std calculation - on hard rock using AB06""" # Modified gmpe mgmpe = NRCan15SiteTermLinear(gmpe_name='AtkinsonBoore2006') # Set parameters sites = Dummy.get_site_collection(2, vs30=[760, 2010]) rup = Dummy.get_rupture(mag=7.0) dists = DistancesContext() dists.rrup = np.array([15., 15.]) stdt = [const.StdDev.TOTAL] gmpe = AtkinsonBoore2006() for imt in [PGA(), SA(1.0), SA(5.0)]: # # Computes results mean, stds = mgmpe.get_mean_and_stddevs(sites, rup, dists, imt, stdt) # Compute the expected results 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_allclose(np.exp(mean), np.exp(mean_expected), rtol=1.0e-1) np.testing.assert_allclose(stds, stds_expected)
def test_gm_calculation_soil_BC(self): """ Test mean and std calculation - CY14 on BC soil""" # Modified gmpe mgmpe = CY14SiteTerm(gmpe_name='ChiouYoungs2014') # Set parameters sites = Dummy.get_site_collection(4, vs30=760., 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, decimal=7) np.testing.assert_almost_equal(stds, stds_expected, decimal=2)
def test_gm_calculation_soil_reference(self): # 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. rup.rrup = np.array([1., 10., 30., 70.]) rup.rx = np.array([1., 10., 30., 70.]) rup.rjb = np.array([1., 10., 30., 70.]) ctx = full_context(sites, rup) imt = PGA() stdt = [StdDev.TOTAL] # Compute results mean, stds = mgmpe.get_mean_and_stddevs(ctx, ctx, ctx, imt, stdt) # Compute the expected results gmpe = ChiouYoungs2014() mean_expected, stds_expected = gmpe.get_mean_and_stddevs( ctx, ctx, ctx, 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 setUp(self): fname = gettemp(ampl_func) df = read_csv(fname, { 'ampcode': ampcode_dt, None: numpy.float64 }, index='ampcode') self.df = AmplFunction(df) # Set GMMs gmmA = BooreAtkinson2008() # Set parameters dsts = [10., 15., 20., 30., 40.] dsts = [10.] imts = [PGA(), SA(1.0)] sites = Dummy.get_site_collection(len(dsts), vs30=760.0) self.mag = 5.5 rup = Dummy.get_rupture(mag=self.mag) ctx = full_context(sites, rup) ctx.rjb = numpy.array(dsts) ctx.rrup = numpy.array(dsts) self.rrup = ctx.rrup # Compute GM on rock self.cmaker = ContextMaker('TRT', [gmmA], dict(imtls={str(im): [0] for im in imts})) [self.meastd] = self.cmaker.get_mean_stds([ctx], const.StdDev.TOTAL)
def test_gm_calculation_hard_rock(self): """ Test mean and std calculation - on hard rock using AB06""" # Modified gmpe mgmpe = NRCan15SiteTermLinear(gmpe_name='AtkinsonBoore2006') # Set parameters sites = Dummy.get_site_collection(2, vs30=[760, 2010]) rup = Dummy.get_rupture(mag=7.0) dists = DistancesContext() dists.rrup = np.array([15., 15.]) stdt = [const.StdDev.TOTAL] gmpe = AtkinsonBoore2006() for imt in [PGA(), SA(1.0), SA(5.0)]: # # Computes results mean, stds = mgmpe.get_mean_and_stddevs(sites, rup, dists, imt, stdt) # Compute the expected results 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_allclose(np.exp(mean), np.exp(mean_expected), rtol=1.0e-1) np.testing.assert_allclose(stds, stds_expected)
def setUp(self): # Set parameters self.sites = Dummy.get_site_collection(4, vs30=760.) self.rup = Dummy.get_rupture(mag=6.0) self.dists = DistancesContext() self.dists.rrup = np.array([1., 10., 30., 70.]) self.dists.rjb = np.array([1., 10., 30., 70.]) self.imt = PGA()
def ctx(self, nsites, vs30): sites = Dummy.get_site_collection(nsites, vs30=vs30) rup = Dummy.get_rupture(mag=6.0) ctx = RuptureContext() vars(ctx).update(vars(rup)) for name in sites.array.dtype.names: setattr(ctx, name, sites[name]) return ctx
def setUp(self): # Set parameters self.sites = Dummy.get_site_collection( 4, amplfactor=[-1.0, 1.5, 0.00, -1.99]) self.rup = Dummy.get_rupture(mag=6.0, hypo_depth=10) self.dists = DistancesContext() self.dists.rhypo = np.array([1., 10., 30., 70.]) self.dists.repi = np.array([1., 10., 30., 70.]) self.imt = MMI()
def get_ctx(subset_df): locs = [] rjb = [] for idx, row in subset_df.iterrows(): locs.append(Point(row.lon_sites, row.lat_sites)) rjb.append(row.dist_jb) sites = Dummy.get_site_collection(len(rjb), vs30=800., location=locs) rup = Dummy.get_rupture(mag=row.rup_mag, hypo_lat=row.lat_epi, hypo_lon=row.lon_epi) rup.rjb = np.array(rjb) return contexts.full_context(sites, rup)
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): avg_periods = [0.05, 0.15, 1.0, 2.0, 4.0] gmm = gsim.mgmpe.generic_gmpe_avgsa.GenericGmpeAvgSA( gmpe_name='AkkarEtAlRepi2014', avg_periods=avg_periods, corr_func='akkar') msg = 'The class name is incorrect' self.assertTrue(gmm.__class__.__name__ == 'GenericGmpeAvgSA', msg=msg) sites = Dummy.get_site_collection(4, vs30=760.) rup = Dummy.get_rupture(mag=6.0) dists = DistancesContext() dists.repi = np.array([1., 10., 30., 70.]) imtype = PGA() stdt = [const.StdDev.TOTAL] # Computes results mean, _ = gmm.get_mean_and_stddevs(sites, rup, dists, imtype, stdt) expected = np.array([-2.0383581, -2.6548699, -3.767237, -4.7775653]) np.testing.assert_almost_equal(mean, expected)
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. rup.rrup = np.array([1., 10., 30., 70.]) rup.rx = np.array([1., 10., 30., 70.]) rup.rjb = np.array([1., 10., 30., 70.]) stdt = [StdDev.TOTAL] self.ctx = full_context(sites, rup) self.stdt = stdt self.sites = sites
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_calculationAB06_hard_bedrock(self): """ Test mean and std calculation - AB06 on vs30 hard bedrock""" # Modified gmpe mgmpe = NRCan15SiteTerm(gmpe_name='AtkinsonBoore2006') # Set parameters sites = Dummy.get_site_collection(4, vs30=1999.0) rup = Dummy.get_rupture(mag=6.0) dists = DistancesContext() dists.rrup = np.array([10., 20., 30., 40.]) 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 = AtkinsonBoore2006() 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 _get_stds(self, within_absolute=None, between_absolute=None): if within_absolute is not None: gmm = SplitSigmaGMPE(gmpe_name='Campbell2003', within_absolute=within_absolute) elif between_absolute is not None: gmm = SplitSigmaGMPE(gmpe_name='Campbell2003', between_absolute=between_absolute) else: raise ValueError('Unknown option') # Set parameters sites = Dummy.get_site_collection(4, vs30=760.) rup = Dummy.get_rupture(mag=6.0) dists = DistancesContext() dists.rrup = np.array([1., 10., 30., 70.]) imt = PGA() stds_types = [const.StdDev.TOTAL, const.StdDev.INTER_EVENT, const.StdDev.INTRA_EVENT] # Compute results mean, stds = gmm.get_mean_and_stddevs(sites, rup, dists, imt, stds_types) return stds, stds_types
def test01(self): avg_periods = [0.05, 0.15, 1.0, 2.0, 4.0] gmm = gsim.mgmpe.generic_gmpe_avgsa.GenericGmpeAvgSA( gmpe_name='ZhaoEtAl2006Asc', avg_periods=avg_periods, corr_func='akkar') msg = 'The class name is incorrect' self.assertTrue(gmm.__class__.__name__ == 'GenericGmpeAvgSA', msg=msg) sites = Dummy.get_site_collection(4, vs30=760.) rup = Dummy.get_rupture(mag=6.0) rup.hypo_depth = 10. dists = DistancesContext() dists.rrup = np.array([1., 10., 30., 70.]) imtype = PGA() stdt = [const.StdDev.TOTAL] # Computes results mean, _ = gmm.get_mean_and_stddevs(sites, rup, dists, imtype, stdt) expected = np.array( [-1.33735637, -2.62649473, -3.64500654, -4.60067093]) np.testing.assert_almost_equal(mean, expected)
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_calculationAB06_hard_bedrock(self): """ Test mean and std calculation - AB06 on vs30 hard bedrock""" # Modified gmpe mgmpe = NRCan15SiteTerm(gmpe_name='AtkinsonBoore2006') # Set parameters sites = Dummy.get_site_collection(4, vs30=1999.0) rup = Dummy.get_rupture(mag=6.0) dists = DistancesContext() dists.rrup = np.array([10., 20., 30., 40.]) 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 = AtkinsonBoore2006() 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 _get_stds(self, within_absolute=None, between_absolute=None): if within_absolute is not None: gmm = SplitSigmaGMPE(gmpe_name='Campbell2003', within_absolute=within_absolute) elif between_absolute is not None: gmm = SplitSigmaGMPE(gmpe_name='Campbell2003', between_absolute=between_absolute) else: raise ValueError('Unknown option') # Set parameters sites = Dummy.get_site_collection(4, vs30=760.) rup = Dummy.get_rupture(mag=6.0) dists = DistancesContext() dists.rrup = np.array([1., 10., 30., 70.]) imt = PGA() stds_types = [ const.StdDev.TOTAL, const.StdDev.INTER_EVENT, const.StdDev.INTRA_EVENT ] # Compute results mean, stds = gmm.get_mean_and_stddevs(sites, rup, dists, imt, stds_types) return stds, stds_types