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_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 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 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 get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types): """ Calculate and return mean value of intensity distribution and it's standard deviation. Method must be implemented by subclasses. :param sites: Instance of :class:`openquake.hazardlib.site.SiteCollection` with parameters of sites collection assigned to respective values as numpy arrays. Only those attributes that are listed in class' :attr:`REQUIRES_SITES_PARAMETERS` set are available. :param rup: Instance of :class:`openquake.hazardlib.source.rupture.BaseRupture` with parameters of a rupture assigned to respective values. Only those attributes that are listed in class' :attr:`REQUIRES_RUPTURE_PARAMETERS` set are available. :param dists: Instance of :class:`DistancesContext` with values of distance measures between the rupture and each site of the collection assigned to respective values as numpy arrays. Only those attributes that are listed in class' :attr:`REQUIRES_DISTANCES` set are available. :param imt: An instance (not a class) of intensity measure type. See :mod:`openquake.hazardlib.imt`. :param stddev_types: List of standard deviation types, constants from :class:`openquake.hazardlib.const.StdDev`. Method result value should include standard deviation values for each of types in this list. :returns: Method should return a tuple of two items. First item should be a numpy array of floats -- mean values of respective component of a chosen intensity measure type, and the second should be a list of numpy arrays of standard deviation values for the same single component of the same single intensity measure type, one array for each type in ``stddev_types`` parameter, preserving the order. Combining interface to mean and standard deviation values in a single method allows to avoid redoing the same intermediate calculations if there are some shared between stddev and mean formulae without resorting to keeping any sort of internal state (and effectively making GSIM not reenterable). However it is advised to split calculation of mean and stddev values and make ``get_mean_and_stddevs()`` just combine both (and possibly compute interim steps). """ # mean and stddevs by calling the underlying .compute method N = len(sites) mean = numpy.zeros((1, N)) sig = numpy.zeros((1, N)) tau = numpy.zeros((1, N)) phi = numpy.zeros((1, N)) if sites is not rup or dists is not rup: # convert three old-style contexts to a single new-style context ctx = full_context(sites, rup, dists) else: ctx = rup # rup is already a good object if self.compute.__annotations__.get("ctx") is numpy.recarray: cmaker = ContextMaker('*', [self], {'imtls': {imt: [0]}}) ctx = cmaker.recarray([ctx]) self.compute(ctx, [imt], mean, sig, tau, phi) stddevs = [] for stddev_type in stddev_types: if stddev_type == const.StdDev.TOTAL: stddevs.append(sig[0]) elif stddev_type == const.StdDev.INTER_EVENT: stddevs.append(tau[0]) elif stddev_type == const.StdDev.INTRA_EVENT: stddevs.append(phi[0]) return mean[0], stddevs