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_table_string_instantiation(self): # Check that the table instantiates in the conventional way table1 = CoeffsTable(sa_damping=5, table=self.coefficient_string) self.assertDictEqual(table1.non_sa_coeffs, { PGV(): { "a": 0.1, "b": 0.2 }, PGA(): { "a": 0.05, "b": 0.1 } }) self.assertDictEqual( table1.sa_coeffs, { SA(period=0.1, damping=5): { "a": 1.0, "b": 2.0 }, SA(period=1.0, damping=5): { "a": 5.0, "b": 10.0 }, SA(period=10.0, damping=5): { "a": 10.0, "b": 20.0 } })
def __init__(self): self._pga = PGA() self._pgv = PGV() self._sa03 = SA(0.3) self._sa10 = SA(1.0) self._sa30 = SA(3.0) self.DEFINED_FOR_INTENSITY_MEASURE_TYPES = set()
def test_vskappa_scaling(self): vskappa_dict = {"PGA": 1.2, "SA(0.2)": 1.3, "SA(1.0)": 1.4} gsim_1 = self.gsim("BindiEtAl2014Rjb", branch="central", vskappa=vskappa_dict) gsim_2 = self.gsim("BindiEtAl2014Rjb", branch="central") # PGA self._compare_arrays( gsim_1.get_mean_and_stddevs(self.sctx, self.rctx, self.dctx, PGA(), [const.StdDev.TOTAL])[0], gsim_2.get_mean_and_stddevs(self.sctx, self.rctx, self.dctx, PGA(), [const.StdDev.TOTAL])[0], 1.2) # SA(0.2) self._compare_arrays( gsim_1.get_mean_and_stddevs(self.sctx, self.rctx, self.dctx, SA(0.2), [const.StdDev.TOTAL])[0], gsim_2.get_mean_and_stddevs(self.sctx, self.rctx, self.dctx, SA(0.2), [const.StdDev.TOTAL])[0], 1.3) # SA(1.0) self._compare_arrays( gsim_1.get_mean_and_stddevs(self.sctx, self.rctx, self.dctx, SA(1.0), [const.StdDev.TOTAL])[0], gsim_2.get_mean_and_stddevs(self.sctx, self.rctx, self.dctx, SA(1.0), [const.StdDev.TOTAL])[0], 1.4)
def get_mean_and_stddevs(self, sites, rup, dists, imt, stds_types): nsites = len(sites) stddevs = self.get_stddevs(rup.mag, imt, stds_types, nsites) # compute corner frequency and capping period cornerp = self.get_corner_period(rup.mag) cappingp = self.get_capping_period(cornerp, self.gmpe) # apply extrapolation to periods > cappingp if imt.period > cappingp: # compute acceleration at the capping period mean, _ = self.gmpe.get_mean_and_stddevs(sites, rup, dists, SA(cappingp), stds_types) # convert to spectral displacement at the capping period disp = self.get_disp_from_acc(mean, cappingp) mean = self.get_acc_from_disp(disp, imt.period) else: mean, _ = self.gmpe.get_mean_and_stddevs(sites, rup, dists, imt, stds_types) kappa = 1 if imt.period == 0: kappa = self.KAPPATAB[SA(0.01)][self.kappa_val] elif imt.period > 2.0: kappa = self.KAPPATAB[SA(2.0)][self.kappa_val] else: kappa = self.KAPPATAB[imt][self.kappa_val] return mean + np.log(kappa), stddevs
def test_clip_mean(self): mean = numpy.array([0.1, 0.2, 0.6, 1.2]) imt = PGA() clipped_mean = clip_mean(imt, mean) numpy.testing.assert_allclose( [0.1, 0.2, 0.405, 0.405], clipped_mean ) mean = numpy.array([0.1, 0.2, 0.6, 1.2]) imt = SA(period=0.1, damping=5.) clipped_mean = clip_mean(imt, mean) numpy.testing.assert_allclose( [0.1, 0.2, 0.6, 1.099], clipped_mean ) mean = numpy.array([0.1, 0.2, 0.6, 1.2]) imt = SA(period=0.6, damping=5.) clipped_mean = clip_mean(imt, mean) numpy.testing.assert_allclose( [0.1, 0.2, 0.6, 1.2], clipped_mean ) mean = numpy.array([0.1, 0.2, 0.6, 1.2]) imt = SA(period=0.01, damping=5.) clipped_mean = clip_mean(imt, mean) numpy.testing.assert_allclose( [0.1, 0.2, 0.6, 1.2], clipped_mean )
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)
def chk(gmm, tags, ctx, subset_df, sigma): periods = [ PGA(), SA(period=0.2), SA(period=0.50251256281407), SA(period=1.0), SA(period=2.0) ] stdt = [ const.StdDev.TOTAL, const.StdDev.INTER_EVENT, const.StdDev.INTRA_EVENT ] # Compute and check results for the NON ergodic model for i in range(len(periods)): imt = periods[i] tag = tags[i] mean, stddevs = gmm.get_mean_and_stddevs(ctx, ctx, ctx, imt, stdt) if sigma == "1": # checking the Total stddev expected = np.log(10.0**subset_df[tag].to_numpy()) # in VerifTable are in log10 computed = stddevs[0] # in ln elif sigma == "2": # checking tau expected = np.log(10.0**subset_df[tag].to_numpy()) # in VerifTable are in log10 computed = stddevs[1] # in ln elif sigma == "3": # checking phi expected = np.log(10.0**subset_df[tag].to_numpy()) # in VerifTable are in log10 computed = stddevs[2] # in ln else: # checking the mean expected = subset_df[tag].to_numpy() # Verif Table in g unit computed = np.exp(mean) # in OQ are computed in g Units in ln np.testing.assert_allclose(computed, expected, rtol=1e-5)
def compute(self, ctx: np.recarray, imts, mean, sig, tau, phi): """ See :meth:`superclass method <.base.GroundShakingIntensityModel.compute>` for spec of input and result values. """ # cap magnitude values at 8.5, see page 1709 mag = np.clip(ctx.mag, 0, 8.5) if self.kind == 'SInter2008': ctx = copy.copy(ctx) ctx.hypo_depth = 20. # compute PGA on rock (needed for site amplification calculation) G = 10**(1.2 - 0.18 * mag) pga_rock = _compute_mean( self.kind, self.COEFFS_SINTER[PGA()], G, mag, ctx.hypo_depth, ctx.rrup, ctx.vs30, # by passing pga_rock > 500 the soil # amplification is 0 np.zeros_like(ctx.vs30) + 600, PGA()) pga_rock = 10**pga_rock for m, imt in enumerate(imts): C = self.COEFFS_SINTER[imt] # periods 0.4 s (2.5 Hz) and 0.2 s (5 Hz) need a special case # because of the erratum. SA for 0.4s and 0.2s is computed and a # weighted sum is returned if imt.period in (0.2, 0.4): C04 = self.COEFFS_SINTER[SA(period=0.4, damping=5.0)] C02 = self.COEFFS_SINTER[SA(period=0.2, damping=5.0)] mean04 = _compute_mean(self.kind, C04, G, mag, ctx.hypo_depth, ctx.rrup, ctx.vs30, pga_rock, imt) mean02 = _compute_mean(self.kind, C02, G, mag, ctx.hypo_depth, ctx.rrup, ctx.vs30, pga_rock, imt) if imt.period == 0.2: mean[m] = 0.333 * mean02 + 0.667 * mean04 else: mean[m] = 0.333 * mean04 + 0.667 * mean02 else: mean[m] = _compute_mean(self.kind, C, G, mag, ctx.hypo_depth, ctx.rrup, ctx.vs30, pga_rock, imt) # convert from log10 to ln and units from cm/s**2 to g mean[m] = np.log((10**mean[m]) * 1e-2 / g) if imt.period == 4.0: mean[m] /= 0.550 sig[m] = np.log(10**C['sigma']) if 's2' in C.dtype.names: # in the Gupta subclass tau[m] = np.log(10**C['s2']) phi[m] = np.log(10**C['s1'])
def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types): """ See :meth:`superclass method <.base.GroundShakingIntensityModel.get_mean_and_stddevs>` for spec of input and result values. """ # extracting dictionary of coefficients specific to required # intensity measure type. C = self.COEFFS_SINTER[imt] # cap magnitude values at 8.5, see page 1709 mag = rup.mag if mag > 8.5: mag = 8.5 # compute PGA on rock (needed for site amplification calculation) G = 10**(1.2 - 0.18 * mag) pga_rock = self._compute_mean( self.COEFFS_SINTER[PGA()], G, mag, rup.hypo_depth, dists.rrup, sites.vs30, # by passing pga_rock > 500 the soil # amplification is 0 np.zeros_like(sites.vs30) + 600, PGA()) pga_rock = 10**(pga_rock) # periods 0.4 s (2.5 Hz) and 0.2 s (5 Hz) need a special case because # of the erratum. SA for 0.4s and 0.2s is computed and a weighted sum # is returned if imt.period in (0.2, 0.4): C04 = self.COEFFS_SINTER[SA(period=0.4, damping=5.0)] C02 = self.COEFFS_SINTER[SA(period=0.2, damping=5.0)] mean04 = self._compute_mean(C04, G, mag, rup.hypo_depth, dists.rrup, sites.vs30, pga_rock, imt) mean02 = self._compute_mean(C02, G, mag, rup.hypo_depth, dists.rrup, sites.vs30, pga_rock, imt) if imt.period == 0.2: mean = 0.333 * mean02 + 0.667 * mean04 else: mean = 0.333 * mean04 + 0.667 * mean02 else: mean = self._compute_mean(C, G, mag, rup.hypo_depth, dists.rrup, sites.vs30, pga_rock, imt) # convert from log10 to ln and units from cm/s**2 to g mean = np.log((10**mean) * 1e-2 / g) if imt.period == 4.0: mean /= 0.550 stddevs = self._get_stddevs(C, stddev_types, sites.vs30.shape[0]) return mean, stddevs
def __init__(self): self._pga = PGA() self._pgv = PGV() self._pgd = PGD() self._ia = IA() self._ih = IH() self._sa03 = SA(0.3) self._sa10 = SA(1.0) self._sa30 = SA(3.0)
def test(self): cm = NoCrossCorrelation(truncation_level=3.) imts = [PGA(), SA(0.3), SA(0.6), SA(1.0)] numpy.random.seed(42) eps = cm.get_inter_eps(imts, 2) # a 4x2 matrix aac(eps, numpy.array([[-0.318959, 1.640001], [0.616954, 0.249188], [-1.007084, -1.007184], [-1.560874, 1.103927]]), rtol=1e-5)
def test(self): cm = FullCrossCorrelation(truncation_level=3.) imts = [PGA(), SA(0.3), SA(0.6), SA(1.0)] numpy.random.seed(42) eps = cm.get_inter_eps(imts, 2) # a 4x2 matrix with same eps per IMT aac(eps, numpy.array([[-0.318959, 1.640001], [-0.318959, 1.640001], [-0.318959, 1.640001], [-0.318959, 1.640001]]), rtol=1e-5)
def test_coefficients_as_dictionary(self): """Check the parsing of the coefficients to a dictionary""" input_coeffs = {"PGA": 1.0, "SA(0.2)": 2.0, "SA(3.0)": 3.0} output_coeffs = _dict_to_coeffs_table(input_coeffs, "XYZ") self.assertListEqual(list(output_coeffs), ["XYZ"]) self.assertIsInstance(output_coeffs["XYZ"], CoeffsTable) self.assertAlmostEqual(output_coeffs["XYZ"][PGA()]["XYZ"], 1.0) self.assertAlmostEqual(output_coeffs["XYZ"][SA(0.2)]["XYZ"], 2.0) self.assertAlmostEqual(output_coeffs["XYZ"][SA(3.0)]["XYZ"], 3.0)
def get_mean_and_stddevs(self, sites, rup, dists, imt, stds_types, extr=True): nsites = len(sites) stddevs = self.get_stddevs(rup.mag, imt, stds_types, nsites) cornerp = self.get_corner_period(rup.mag) # capping period only compares # - highest period with a coefficient # - corner period # - 2.0 if it's bindi sp = self.get_capping_period(cornerp, self.gmpe, imt) hp = sp[-1] # 1 - if imt.period < cornerp, no changes needed if extr and imt.period <= cornerp and imt.period <= hp: mean, _ = self.gmpe.get_mean_and_stddevs(sites, rup, dists, imt, stds_types) # if the period is larger than the corner period but the corner period # is less than the highest period elif extr and imt.period >= cornerp and cornerp <= hp: mean, _ = self.gmpe.get_mean_and_stddevs(sites, rup, dists, SA(cornerp), stds_types) disp = self.get_disp_from_acc(mean, cornerp) mean = self.get_acc_from_disp(disp, imt.period) # if the corner period is longer than highest and imt is above # highets but below corner elif extr and cornerp > hp and imt.period >= hp and imt.period < cornerp: mean = self.extrapolate_in_PSA(sites, rup, dists, hp, sp, stds_types, imt.period) elif extr and cornerp > hp and imt.period > cornerp: mean = self.extrapolate_in_PSA(sites, rup, dists, hp, sp, stds_types, cornerp) disp = self.get_disp_from_acc(mean, cornerp) mean = self.get_acc_from_disp(disp, imt.period) else: mean, _ = self.gmpe.get_mean_and_stddevs(sites, rup, dists, imt, stds_types) kappa = 1 if self.kappa_file: if imt.period == 0: kappa = self.KAPPATAB[SA(0.01)][self.kappa_val] elif imt.period > 2.0: kappa = self.KAPPATAB[SA(2.0)][self.kappa_val] else: kappa = self.KAPPATAB[imt][self.kappa_val] return mean + np.log(kappa), stddevs
def setUp(self): """ Setup with a set of distances and site paramwters """ self.imts = [PGA(), SA(0.1), SA(0.2), SA(0.5), SA(1.0), SA(2.0)] self.mags = [4.5, 5.5, 6.5, 7.5] self.rakes = [-90., 0., 90.] self.dctx = DistancesContext() self.dctx.rhypo = np.array([5., 10., 20., 50., 100.]) self.sctx = SitesContext() self.sctx.vs30 = 800.0 * np.ones(5)
def test_alatik_youngs_factors(self): self.assertAlmostEqual( self.gsim.get_alatik_youngs_sigma_mu(5.0, -90., PGA()), 0.121) self.assertAlmostEqual( self.gsim.get_alatik_youngs_sigma_mu(5.0, -90., SA(0.5)), 0.121) self.assertAlmostEqual( self.gsim.get_alatik_youngs_sigma_mu(7.5, -90., SA(0.5)), 0.149) self.assertAlmostEqual( self.gsim.get_alatik_youngs_sigma_mu(5.0, -90., SA(np.exp(1))), 0.1381) self.assertAlmostEqual( self.gsim.get_alatik_youngs_sigma_mu(5.0, 90., SA(0.2)), 0.083)
def test_dist_not_in_increasing_order(self): ctx = RuptureContext() ctx.mag = 5. ctx.sids = [0, 1] ctx.rhypo = numpy.array([150, 100]) mean_150_100, _ = self.GSIM_CLASS().get_mean_and_stddevs( ctx, ctx, ctx, SA(0.1, 5), [StdDev.TOTAL]) ctx.rhypo = numpy.array([100, 150]) mean_100_150, _ = self.GSIM_CLASS().get_mean_and_stddevs( ctx, ctx, ctx, 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])
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])
def test_clustered(self): cormo = JB2009CorrelationModel(vs30_clustering=True) imt = SA(period=0.001, damping=5) corma = cormo._get_correlation_matrix(self.SITECOL, imt) aaae(corma, [[1, 0.44046654, 1, 0.44046654], [0.44046654, 1, 0.44046654, 0.19401077], [1, 0.44046654, 1, 0.44046654], [0.44046654, 0.19401077, 0.44046654, 1]]) imt = SA(period=0.5, damping=5) corma = cormo._get_correlation_matrix(self.SITECOL, imt) aaae(corma, [[1, 0.36612758, 1, 0.36612758], [0.36612758, 1, 0.36612758, 0.1340494], [1, 0.36612758, 1, 0.36612758], [0.36612758, 0.1340494, 0.36612758, 1]])
def test_no_clustering(self): cormo = JB2009CorrelationModel(vs30_clustering=False) imt = SA(period=0.1, damping=5) corma = cormo._get_correlation_matrix(self.SITECOL, imt) aaae(corma, [[1, 0.03823366, 1, 0.03823366], [0.03823366, 1, 0.03823366, 0.00146181], [1, 0.03823366, 1, 0.03823366], [0.03823366, 0.00146181, 0.03823366, 1]]) imt = SA(period=0.95, damping=5) corma = cormo._get_correlation_matrix(self.SITECOL, imt) aaae(corma, [[1, 0.26107857, 1, 0.26107857], [0.26107857, 1, 0.26107857, 0.06816202], [1, 0.26107857, 1, 0.26107857], [0.26107857, 0.06816202, 0.26107857, 1]])
def test_get_sigma_sa0(self): """ Test the calculation of sigma for short periods""" imt = SA(0.6) computed = get_sigma(imt) expected = np.log(10**0.25) np.testing.assert_almost_equal(computed, expected) # imt = SA(0.4) computed = get_sigma(imt) expected = np.log(10**0.24) np.testing.assert_almost_equal(computed, expected) # imt = SA(1.2) computed = get_sigma(imt) expected = np.log(10**0.27) np.testing.assert_almost_equal(computed, 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_magnitude_bins(self): """ Testing build disaggregation matrix """ fname = os.path.join(DATA_PATH, 'data', 'ssm.xml') converter = sourceconverter.SourceConverter(50., 1., 10, 0.1, 10) groups = to_python(fname, converter) sources = [] for g in groups: sources += g.sources site = Site(Point(172.63, -43.53), vs30=250, vs30measured=False, z1pt0=330) imt = SA(3.0) iml = 0.25612220 gsim_by_trt = {TRT.ACTIVE_SHALLOW_CRUST: Bradley2013()} truncation_level = 3.0 n_epsilons = 1 mag_bin_width = 0.1 dist_bin_width = 100. coord_bin_width = 100. # Compute the disaggregation matrix edges, mtx = disagg.disaggregation(sources, site, imt, iml, gsim_by_trt, truncation_level, n_epsilons, mag_bin_width, dist_bin_width, coord_bin_width) tm = disagg.mag_pmf(mtx[:, :, :, :, :, 0]) numpy.testing.assert_array_less(numpy.zeros_like(tm[2:]), tm[2:])
def get_mean_and_stddevs(self, sites, rup, dists, imt, stds_types): """ See :meth:`superclass method <.base.GroundShakingIntensityModel.get_mean_and_stddevs>` for spec of input and result values. """ mean_list = [] stddvs_list = [] # Loop over averaging periods for period in self.avg_periods: imt_local = SA(float(period)) # compute mean and standard deviation mean, stddvs = self.gmpe.get_mean_and_stddevs( sites, rup, dists, imt_local, [const.StdDev.TOTAL]) mean_list.append(mean) stddvs_list.append(stddvs[0]) # Support only for total! mean_avgsa = 0. stddvs_avgsa = 0. for i1 in range(self.tnum): mean_avgsa += mean_list[i1] for i2 in range(self.tnum): rho = self.corr_func(i1, i2) stddvs_avgsa += (rho * stddvs_list[i1] * stddvs_list[i2]) mean_avgsa /= self.tnum stddvs_avgsa = np.sqrt(stddvs_avgsa) / self.tnum return mean_avgsa, [stddvs_avgsa]
def test_correlation_with_uncertainty(self): Nsim = 100000 cormo = HM2018CorrelationModel(uncertainty_multiplier=1) imt = SA(period=3, damping=5) corma_3d = numpy.zeros((len(self.SITECOL), len(self.SITECOL), Nsim)) # For each simulation, construct a new correlation matrix for isim in range(0, Nsim): corma_3d[0:, 0:, isim] = \ cormo._get_correlation_matrix(self.SITECOL, imt) # Mean and Coefficient of Variation (COV) of correlation matrix MEANcorMa = corma_3d.mean(2) COVcorma = numpy.divide(corma_3d.std(2), MEANcorMa) aaae(MEANcorMa,[[1.0000000, 0.3766436, 1.0000000, 0.3766436,], [0.3766436, 1.0000000, 0.3766436, 0.2534904,], [1.0000000, 0.3766436, 1.0000000, 0.3766436,], [0.3766436, 0.2534904, 0.3766436, 1.00000,]], 2) aaae(COVcorma,[[0.0000000, 0.4102512, 0.0000000, 0.4102512,], [0.4102512, 0.0000000, 0.4102512, 0.5636907,], [0.0000000, 0.4102512, 0.0000000, 0.4102512,], [0.4102512, 0.5636907, 0.4102512, 0.00000,]], 2)
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 get_mean_and_stddevs(self, sctx, rctx, dctx, imt, stddev_types): """ Returns the mean and standard deviations calling the input GMPE for the mean acceleration for PGA and Sa (1.0) on the reference rock, defining the amplification factors and code spectrum to return the mean ground motion at the desired period, before the calling the input GMPE once more in order to return the standard deviations for the required IMT. """ sctx_r = deepcopy(sctx) sctx_r.vs30 = self.rock_vs30 * np.ones_like(sctx_r.vs30) # Get PGA and Sa (1.0) from GMPE pga_r = self.gmpe.get_mean_and_stddevs(sctx_r, rctx, dctx, PGA(), stddev_types)[0] s_1_rp = self.gmpe.get_mean_and_stddevs(sctx_r, rctx, dctx, SA(1.0), stddev_types)[0] s_s_rp = self.CONSTANTS["F0"] * np.exp(pga_r) s_1_rp = np.exp(s_1_rp) # Get the short and long period amplification factors f_s, f_l = self.get_amplification_factor(s_s_rp, s_1_rp, sctx) s_1 = f_l * s_1_rp s_s = f_s * s_s_rp # Get the mean ground motion at the IMT using the design code spectrum mean = self.get_amplified_mean(s_s, s_1, s_1_rp, imt) # Call the original GMPE to return the standard deviation for the # IMT in question stddevs = self.gmpe.get_mean_and_stddevs(sctx, rctx, dctx, imt, stddev_types)[1] return mean, stddevs
def get_mean_and_stddevs(self, sctx, rctx, dctx, imt, stddev_types): """ As with the :class:`PitilakisEtal2018`, the mean ground motion is determined by construction of the Eurocode 8 design spectrum from the short- and long-period acceleration coefficients amplified to the desired site class, with the standard deviations taken from the original GMPE at the desired IMT """ sctx_r = deepcopy(sctx) sctx_r.vs30 = self.rock_vs30 * np.ones_like(sctx_r.vs30) # Get PGA and Sa (1.0) from GMPE pga_r = self.gmpe.get_mean_and_stddevs(sctx_r, rctx, dctx, PGA(), stddev_types)[0] s_1_rp = self.gmpe.get_mean_and_stddevs(sctx_r, rctx, dctx, SA(1.0), stddev_types)[0] s_s_rp = self.CONSTANTS["F0"] * np.exp(pga_r) s_1_rp = np.exp(s_1_rp) ec8 = self.get_ec8_class(sctx.vs30, sctx.h800) f_s, f_l = self.get_amplification_factor(s_s_rp, s_1_rp, ec8, sctx) s_1 = f_l * s_1_rp s_s = f_s * s_s_rp mean = self.get_amplified_mean(s_s, s_1, s_1_rp, imt) stddevs = self.gmpe.get_mean_and_stddevs(sctx, rctx, dctx, imt, stddev_types)[1] return mean, stddevs
def get_mean_and_stddevs(self, sctx, rctx, dctx, imt, stddev_types): """ Returns the mean and standard deviations """ # Get the PGA on the reference rock condition if PGA in self.DEFINED_FOR_INTENSITY_MEASURE_TYPES: rock_imt = PGA() else: rock_imt = SA(0.01) pga_r = self.get_hard_rock_mean(rctx, dctx, rock_imt, stddev_types) # Get the desired spectral acceleration on rock if not str(imt) == "PGA": # Calculate the ground motion at required spectral period for # the reference rock mean = self.get_hard_rock_mean(rctx, dctx, imt, stddev_types) else: # Avoid re-calculating PGA if that was already done! mean = np.copy(pga_r) mean += self.get_site_amplification(imt, np.exp(pga_r), sctx) # Get standard deviation model nsites = getattr(dctx, self.distance_type).shape stddevs = self.get_stddevs(rctx.mag, imt, stddev_types, nsites) return mean, stddevs