def main(): gmpe = ngaw2() ipe = AllenEtAl2012() event_ids = np.unique(SHAKE_DF['event_id']) i = 0 event_id = event_ids[i] idx = np.where(SHAKE_DF['event_id'] == event_id)[0] rx = base.RuptureContext() rx.mag = np.array(SHAKE_DF['magnitude'])[idx] rx.ztor = np.array(SHAKE_DF['ztor'])[idx] rx.rake = np.full_like(rx.mag) rx.width = rx.hypo_depth = np.array(SHAKE_DF['hypo_depth'])[idx] sx = base.SitesContext() sx.vs30 = np.array(SHAKE_DF['CA Vs30'])[idx] dx = base.DistancesContext() dx.rjb = np.array(SHAKE_DF['r_jb'])[idx] dx.rrup = np.array(SHAKE_DF['r_rup'])[idx] dx.rx = np.array(SHAKE_DF['r_x'])[idx] dx.ry = np.array(SHAKE_DF['r_y'])[idx] dx.ry0 = np.array(SHAKE_DF['r_y0'])[idx] lmean, lsd = gmpe.get_mean_and_stddevs( sx, rx, dx, imt=IMTS[j], stddev_types=STD)
def getRuptureContext(self, gmpelist): """ Return an Openquake `RuptureContext <http://docs.openquake.org/oq-hazardlib/master/gsim/index.html#openquake.hazardlib.gsim.base.RuptureContext>`__ suitable for any GMPE (except for those requiring hypo_loc). If Source does not contain a Fault, strike, dip, ztor, and width will be filled with default values. Rake may not be known, or may be estimated from a focal mechanism. :param gmpelist: Sequence of hazardlib GMPE objects. :raises: ShakeMapException when a GMPE requiring 'hypo_loc' is passed in. :returns: RuptureContext object with all known parameters filled in. """ # rupturecontext constructor inputs: # 'mag', 'strike', 'dip', 'rake', 'ztor', 'hypo_lon', 'hypo_lat', # 'hypo_depth', 'width', 'hypo_loc' for gmpe in gmpelist: reqset = gmpe.REQUIRES_RUPTURE_PARAMETERS if 'hypo_loc' in reqset: raise ShakeMapException( 'Rupture parameter "hypo_loc" is not supported!') rup = base.RuptureContext() rup.mag = self.getEventParam('mag') if self._fault is not None: rup.strike = self._fault.getStrike() rup.dip = self._fault.getDip() rup.ztor = self._fault.getTopOfRupture() rup.width = self._fault.getWidth() else: rup.strike = DEFAULT_STRIKE rup.dip = self.getEventParam('dip') rup.ztor = DEFAULT_ZTOR rup.width = DEFAULT_WIDTH if 'rake' in self._event_dict: rup.rake = self.getEventParam('rake') elif 'mech' in self._event_dict: mech = self._event_dict['mech'] rup.rake = RAKEDICT[mech] else: rup.rake = RAKEDICT['ALL'] rup.hypo_lat = self.getEventParam('lat') rup.hypo_lon = self.getEventParam('lon') rup.hypo_depth = self.getEventParam('depth') return rup
def getRuptureContext(self, gmpelist): """ Returns an Openquake `RuptureContext <http://docs.openquake.org/oq-hazardlib/master/gsim/index.html#openquake.hazardlib.gsim.base.RuptureContext>`__. Args: gmpelist (list): List of hazardlib GMPE objects. Returns: RuptureContext object with all known parameters filled in. """ # noqa origin = self._origin # rupturecontext constructor inputs: # 'mag', 'strike', 'dip', 'rake', 'ztor', 'hypo_lon', 'hypo_lat', # 'hypo_depth', 'width', 'hypo_loc' rx = base.RuptureContext() rx.mag = origin.mag rx.strike = self.getStrike() rx.dip = self.getDip() rx.ztor = self.getDepthToTop() rx.width = self.getWidth() if hasattr(origin, 'rake'): rx.rake = origin.rake elif hasattr(origin, 'mech'): mech = origin.mech rx.rake = constants.RAKEDICT[mech] else: rx.rake = constants.RAKEDICT['ALL'] rx.hypo_lat = origin.lat rx.hypo_lon = origin.lon rx.hypo_depth = origin.depth return rx
from openquake.hazardlib.gsim import base import openquake.hazardlib.imt as imt from openquake.hazardlib.const import StdDev from shakelib.gmpe.nga_east import NGAEast home_dir = os.path.dirname(os.path.abspath(__file__)) data_dir = os.path.join(home_dir, 'nga_east_data') stddev_types = [StdDev.TOTAL] gmpe = NGAEast() dx = base.DistancesContext() dx.rrup = np.logspace(-1, np.log10(2000), 100) rx = base.RuptureContext() sx = base.SitesContext() IMTS = [imt.PGA(), imt.PGV(), imt.SA(0.3), imt.SA(1.0), imt.SA(3.0)] MAGS = [3, 5, 6, 7] VS30 = [180, 380, 760, 2000] def update_results(): # To build the data for testing result = {} for i in IMTS: ikey = i.__str__() result[ikey] = {}
def gmpe_avg(ztest): ''' transforms cybershake dips and Rx Parameters ---------- ztest: 2d numpy array of 12 feature data Returns ------- model_avg: average of base model predictions in ln m/s2 ''' import numpy as np import openquake from openquake.hazardlib.gsim.abrahamson_2014 import AbrahamsonEtAl2014 #ASK from openquake.hazardlib.gsim.campbell_bozorgnia_2014 import CampbellBozorgnia2014 #CB from openquake.hazardlib.gsim.chiou_youngs_2014 import ChiouYoungs2014 #CY from openquake.hazardlib.gsim.boore_2014 import BooreEtAl2014 #BSSA import openquake.hazardlib.imt as imt from openquake.hazardlib.const import StdDev import openquake.hazardlib.gsim.base as base stddev_types = [StdDev.TOTAL] period = [10, 7.5, 5, 4, 3, 2, 1, 0.5, 0.2, 0.1] gmpeBSSAdata = np.zeros((ztest.shape[0], len(period))) gmpeASKdata = np.zeros((ztest.shape[0], len(period))) gmpeCBdata = np.zeros((ztest.shape[0], len(period))) gmpeCYdata = np.zeros((ztest.shape[0], len(period))) gmpeBSSAstd = np.zeros((ztest.shape[0], len(period))) gmpeASKstd = np.zeros((ztest.shape[0], len(period))) gmpeCBstd = np.zeros((ztest.shape[0], len(period))) gmpeCYstd = np.zeros((ztest.shape[0], len(period))) gmpeASK = AbrahamsonEtAl2014() gmpeCB = CampbellBozorgnia2014() gmpeCY = ChiouYoungs2014() gmpeBSSA = BooreEtAl2014() for i in range(ztest.shape[0]): dx = base.DistancesContext() dx.rjb = np.array([ztest[i, 9]]) #dx.rjb = np.logspace(-1, 2, 10) # Magnitude and rake rx = base.RuptureContext() rx.mag = np.array([ztest[i, 0]]) rx.rake = np.array([ztest[i, 5]]) rx.hypo_depth = np.array([ztest[i, 7]]) # Vs30 sx = base.SitesContext() sx.vs30 = np.array([ztest[i, 2]]) sx.vs30measured = 0 dx.rrup = np.array([ztest[i, 1]]) rx.ztor = np.array([ztest[i, 11]]) rx.dip = np.array([ztest[i, 6]]) rx.width = np.array([ztest[i, 8]]) # dx.rx=np.array([rxkeep[i]]) dx.rx = np.array([ztest[i, 10]]) dx.ry0 = np.array([0]) sx.z1pt0 = np.array([ztest[i, 3]]) sx.z2pt5 = np.array([ztest[i, 4]]) # Evaluate GMPE #Unit of measure for Z1.0 is [m] (ASK) #for period1 in period: for ii in range(len(period)): sx.vs30measured = 0 period1 = period[ii] gmpeBSSAdata[i, ii], g = gmpeBSSA.get_mean_and_stddevs( sx, rx, dx, imt.SA(period1), stddev_types) gmpeBSSAstd[i, ii] = g[0][0] gmpeCBdata[i, ii], g = gmpeCB.get_mean_and_stddevs( sx, rx, dx, imt.SA(period1), stddev_types) gmpeCBstd[i, ii] = g[0][0] gmpeCYdata[i, ii], g = gmpeCY.get_mean_and_stddevs( sx, rx, dx, imt.SA(period1), stddev_types) gmpeCYstd[i, ii] = g[0][0] sx.vs30measured = [0] gmpeASKdata[i, ii], g = gmpeASK.get_mean_and_stddevs( sx, rx, dx, imt.SA(period1), stddev_types) gmpeASKstd[i, ii] = g[0][0] model_avg = np.log(9.81 * np.exp( np.mean([gmpeBSSAdata, gmpeCBdata, gmpeCYdata, gmpeASKdata], axis=0))) #outputs ln m/s2 return model_avg