def test_gm_calculation_soil_SA(self): """ Test mean and std calculation - CY14 on soil - SA""" # Modified gmpe gmpe = ChiouYoungs2014() mgmpe = CY14SiteTerm(gmpe_name='ChiouYoungs2014') imt = SA(1.0) # Compute results mean, stds = mgmpe.get_mean_and_stddevs(self.sites, self.rup, self.dists, imt, self.stdt) # Compute the expected results mean_expected, stds_expected = gmpe.get_mean_and_stddevs( self.sites, self.rup, self.dists, imt, self.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) # Here we use a quite large tolerance since in the site term we take # the std from the calculation of motion on reference rock. This # does not match the std that the same GMM computes for soft soils # with the same remaining conditions np.testing.assert_almost_equal(stds, stds_expected, decimal=1)
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 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 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. """ # Prepare sites sites_rock = copy.copy(sites) sites_rock.vs30 = np.ones_like(sites_rock.vs30) * 1130. # Compute mean and standard deviation using the original GMM. These # values are used as ground-motion values on reference rock conditions. # CHECKED [MP]: The computed reference motion is equal to the one in the # CY14 model mean, stddvs = self.gmpe.get_mean_and_stddevs(sites_rock, rup, dists, imt, stds_types) # Compute the site term correction factor cy14 = ChiouYoungs2014() vs30 = sites.vs30 fa = cy14._get_site_term(cy14.COEFFS[imt], vs30, mean) mean += fa return mean, stddvs
def ground_motion_from_rupture(rupture, sites=None, imts=[PGA()], gsim=ChiouYoungs2014(), truncation_level=4, realizations=1, **kwargs): gm = ground_motion_fields(rupture=rupture, sites=sites, imts=imts, gsim=gsim, truncation_level=truncation_level, realizations=realizations) return gm
import sys import os import os.path import datetime try: import configparser except ImportError: import ConfigParser as configparser import time as time import numpy as np from scipy.stats import norm from openquake.hazardlib.gsim.chiou_youngs_2014 import ChiouYoungs2014 from openquake.hazardlib.imt import PGA, PGV, SA cy14 = ChiouYoungs2014() coef = cy14.COEFFS.non_sa_coeffs[PGA()] ##################################################### # This function loops over M and R, calling EpsilonDipDxDyTheta # and writes out progress information. ##################################################### def MeanVar_MR(ndip=19, mindip=0.0, maxdip=np.pi / 2.0, min_seis_depth=0, max_seis_depth=20, rup_dim_model='WC94', mech="A", LW=True,
def test_virtualipe(): # # Set up the GMPE, IPE, and GMICE # gmpe_cy14 = ChiouYoungs2014() gmpe = MultiGMPE.from_list([gmpe_cy14], [1.0]) gmice = WGRW12() ipe = VirtualIPE.fromFuncs(gmpe, gmice) # # Use the Calexico event info # homedir = os.path.dirname(os.path.abspath(__file__)) datadir = os.path.abspath( os.path.join(homedir, 'virtualipe_data', 'Calexico', 'input')) # # Read the event, origin, and rupture files and produce Rupture and Origin # objects # # inputfile = os.path.join(datadir, 'stationlist_dat.xml') # dyfifile = os.path.join(datadir, 'ciim3_dat.xml') eventfile = os.path.join(datadir, 'event.xml') rupturefile = os.path.join(datadir, 'wei_fault.txt') origin_obj = Origin.fromFile(eventfile) rupture_obj = get_rupture(origin_obj, rupturefile) rx = rupture_obj.getRuptureContext([gmpe]) rx.rake = 45. smdx = 0.0083333333 smdy = 0.0083333333 lonspan = 6.0 latspan = 4.0 vs30filename = os.path.join(datadir, '..', 'vs30', 'vs30.grd') sites_obj_grid = Sites.fromCenter(rx.hypo_lon, rx.hypo_lat, lonspan, latspan, smdx, smdy, defaultVs30=760.0, vs30File=vs30filename, vs30measured_grid=None, padding=False, resample=False) npts = 200 lats = np.empty(npts) lons = np.empty(npts) depths = np.zeros(npts) for i in range(npts): lats[i] = rx.hypo_lat lons[i] = rx.hypo_lon + i * 0.01 lldict = {'lats': lats, 'lons': lons} sx = sites_obj_grid.getSitesContext(lldict=lldict, rock_vs30=760.0) dobj = Distance(gmpe, lons, lats, depths, rupture_obj) dx = dobj.getDistanceContext() sd_types = [oqconst.StdDev.TOTAL] mmi_const_vs30, mmi_sd_const_vs30 = \ ipe.get_mean_and_stddevs(sx, rx, dx, MMI(), sd_types) # These prints are just so a human can examine the outputs # print(mmi_const_vs30) # print(mmi_sd_const_vs30) sx = sites_obj_grid.getSitesContext(lldict=lldict) mmi_variable_vs30, mmi_sd_variable_vs30 = \ ipe.get_mean_and_stddevs(sx, rx, dx, MMI(), sd_types) # print(mmi_variable_vs30) # print(mmi_sd_variable_vs30) sd_types = [ oqconst.StdDev.TOTAL, oqconst.StdDev.INTRA_EVENT, oqconst.StdDev.INTER_EVENT ] mmi_variable_vs30_intra, mmi_sd_variable_vs30_intra = \ ipe.get_mean_and_stddevs(sx, rx, dx, MMI(), sd_types) # print(mmi_variable_vs30_intra) # print(mmi_sd_variable_vs30_intra) # assert(0) # Assert causes test to fail and prints to be displayed # # Try with PGA # gmpe.DEFINED_FOR_INTENSITY_MEASURE_TYPES.remove(PGV) gmpe.ALL_GMPES_HAVE_PGV = False ipe = VirtualIPE.fromFuncs(gmpe, gmice) mmi_pga, mmi_sd_pga = \ ipe.get_mean_and_stddevs(sx, rx, dx, MMI(), sd_types) # # Try with SA(1.0) # gmpe.DEFINED_FOR_INTENSITY_MEASURE_TYPES.remove(PGA) ipe = VirtualIPE.fromFuncs(gmpe, gmice) mmi_psa, mmi_sd_psa = \ ipe.get_mean_and_stddevs(sx, rx, dx, MMI(), sd_types) # # This should raise an exception because the IMT isn't MMI # with pytest.raises(ValueError) as e: mmi_psa, mmi_sd_psa = \ ipe.get_mean_and_stddevs(sx, rx, dx, PGA(), sd_types) # # This should raise an exception because no valid IMTs are available # gmpe.DEFINED_FOR_INTENSITY_MEASURE_TYPES.remove(SA) with pytest.raises(ShakeLibException) as e: # noqa ipe = VirtualIPE.fromFuncs(gmpe, gmice) # # Now do a GMPE that uses Rjb instead of Rrup # gmpe_ba14 = BooreEtAl2014() gmpe = MultiGMPE.from_list([gmpe_ba14], [1.0]) ipe = VirtualIPE.fromFuncs(gmpe, gmice) rx = rupture_obj.getRuptureContext([gmpe]) rx.rake = 45. dobj = Distance(gmpe, lons, lats, depths, rupture_obj) dx = dobj.getDistanceContext() mmi_rjb, mmi_sd_rjb = \ ipe.get_mean_and_stddevs(sx, rx, dx, MMI(), sd_types) # # Test the results against a known standard # savefile = os.path.abspath( os.path.join(homedir, 'virtualipe_data', 'Calexico', 'virtualipe_test', 'savefile.npz')) # # If things change, set remake_save to True, and it will rebuild the # saved data file against which the comparisons are done # Remember to set this back to False once you've remade the test datafile # remake_save = False if remake_save: np.savez_compressed( savefile, mmi_const_vs30=mmi_const_vs30, mmi_sd_const_vs30=mmi_sd_const_vs30[0], mmi_variable_vs30=mmi_variable_vs30, mmi_sd_variable_vs30=mmi_sd_variable_vs30[0], mmi_variable_vs30_intra=mmi_variable_vs30_intra, mmi_sd_variable_vs30_total=mmi_sd_variable_vs30_intra[0], mmi_sd_variable_vs30_intra=mmi_sd_variable_vs30_intra[1], mmi_sd_variable_vs30_inter=mmi_sd_variable_vs30_intra[2], mmi_pga=mmi_pga, mmi_sd_pga=mmi_sd_pga[0], mmi_psa=mmi_psa, mmi_sd_psa=mmi_sd_psa[0], mmi_rjb=mmi_rjb, mmi_sd_rjb=mmi_sd_rjb[0]) td = np.load(savefile) assert (np.allclose(td['mmi_const_vs30'], mmi_const_vs30)) assert (np.allclose(td['mmi_sd_const_vs30'], mmi_sd_const_vs30[0])) assert (np.allclose(td['mmi_variable_vs30'], mmi_variable_vs30)) assert (np.allclose(td['mmi_sd_variable_vs30'], mmi_sd_variable_vs30[0])) assert (np.allclose(td['mmi_variable_vs30_intra'], mmi_variable_vs30_intra)) assert (np.allclose(td['mmi_sd_variable_vs30_total'], mmi_sd_variable_vs30_intra[0])) assert (np.allclose(td['mmi_sd_variable_vs30_intra'], mmi_sd_variable_vs30_intra[1])) assert (np.allclose(td['mmi_sd_variable_vs30_inter'], mmi_sd_variable_vs30_intra[2])) assert (np.allclose(td['mmi_pga'], mmi_pga)) assert (np.allclose(td['mmi_sd_pga'], mmi_sd_pga[0])) assert (np.allclose(td['mmi_psa'], mmi_psa)) assert (np.allclose(td['mmi_sd_psa'], mmi_sd_psa[0])) assert (np.allclose(td['mmi_rjb'], mmi_rjb)) assert (np.allclose(td['mmi_sd_rjb'], mmi_sd_rjb[0])) # The total uncertainties should be greater than the intra-event assert (np.all(mmi_sd_variable_vs30[0] > mmi_sd_variable_vs30_intra[1])) # The combined intra and inter-event uncertainty should be equal # to the total tot = np.sqrt(mmi_sd_variable_vs30_intra[1]**2 + mmi_sd_variable_vs30_intra[2]**2) assert (np.allclose(tot, mmi_sd_variable_vs30_intra[0], rtol=1e-2))
limits_filename = None if event_name == '1852Banda_area': disc = 15 else: disc = 5 # Area or fault source model is used to define the parameter space to be searched if trt == 'Subduction Intraslab': gsim_list = [ ZhaoEtAl2006SSlab(), AtkinsonBoore2003SSlab(), AtkinsonBoore2003SSlabCascadia(), AbrahamsonEtAl2015SSlab() ] if trt == 'Active': # gsim_list = [ChiouYoungs2008(), ChiouYoungs2014(), BooreAtkinson2008(), BooreEtAl2014(), CampbellBozorgnia2008(), CampbellBozorgnia2014() ] gsim_list = [ChiouYoungs2014(), BooreEtAl2014(), CampbellBozorgnia2014()] if trt == 'Subduction Interface': gsim_list = [ YoungsEtAl1997SInter(), AtkinsonBoore2003SInter(), ZhaoEtAl2006SInter(), AbrahamsonEtAl2015SInter() ] def build_site_col(sites_data, site_model_file, filename=None): """Interpolate vs30 values to sites of interest """ # sites_data = np.genfromtxt(site_file) site_points = [] for i in range(len(sites_data[:, 0])):
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
def get_extent(rupture=None, config=None): """ Method to compute map extent from rupture. There are numerous methods for getting the extent: - It can be specified directly in the config file, - it can be hard coded for specific magnitude ranges in the config file, or - it can be based on the MultiGMPE for the event. All methods except for the first requires a rupture object. If no config is provided then a rupture is required and the extent is based on a generic set of active/stable. Args: rupture (Rupture): A ShakeMap Rupture instance. config (ConfigObj): ShakeMap config object. Returns: tuple: lonmin, lonmax, latmin, latmax rounded to the nearest arc-minute.. """ # ------------------------------------------------------------------------- # Check to see what parameters are specified in the extent config # ------------------------------------------------------------------------- spans = {} bounds = [] if config is not None: if 'extent' in config: if 'magnitude_spans' in config['extent']: if len(config['extent']['magnitude_spans']): if isinstance(config['extent']['magnitude_spans'], dict): spans = config['extent']['magnitude_spans'] if 'bounds' in config['extent']: if 'extent' in config['extent']['bounds']: if config['extent']['bounds']['extent'][0] != -999.0: bounds = config['extent']['bounds']['extent'] # ------------------------------------------------------------------------- # Simplest option: extent was specified in the config, use that and exit. # ------------------------------------------------------------------------- if len(bounds): xmin, ymin, xmax, ymax = bounds return (xmin, xmax, ymin, ymax) if not rupture or not isinstance(rupture, Rupture): raise TypeError('get_extent() requires a rupture object if the extent ' 'is not specified in the config object.') # Find the central point origin = rupture.getOrigin() if isinstance(rupture, (QuadRupture, EdgeRupture)): # For an extended rupture, it is the midpoint between the extent of the # verticies lats = rupture.lats lons = rupture.lons # Remove nans lons = lons[~np.isnan(lons)] lats = lats[~np.isnan(lats)] clat = 0.5 * (np.nanmax(lats) + np.nanmin(lats)) clon = 0.5 * (np.nanmax(lons) + np.nanmin(lons)) else: # For a point source, it is just the epicenter clat = origin.lat clon = origin.lon mag = origin.mag # ------------------------------------------------------------------------- # Second simplest option: spans are hardcoded based on magnitude # ------------------------------------------------------------------------- if len(spans): xmin = None xmax = None ymin = None ymax = None for spankey, span in spans.items(): if mag > span[0] and mag <= span[1]: ymin = clat - span[2] / 2 ymax = clat + span[2] / 2 xmin = clon - span[3] / 2 xmax = clon + span[3] / 2 break if xmin is not None: return (xmin, xmax, ymin, ymax) # ------------------------------------------------------------------------- # Use MultiGMPE to get spans # ------------------------------------------------------------------------- if config is not None: gmpe = MultiGMPE.from_config(config) gmice = get_object_from_config('gmice', 'modeling', config) else: # Put in some default values for conf config = { 'extent': { 'mmi': { 'threshold': 4.5, 'mindist': 100, 'maxdist': 1000 } } } # Generic GMPEs choices based only on active vs stable # as defaults... stable = is_stable(origin.lon, origin.lat) if not stable: ASK14 = AbrahamsonEtAl2014() CB14 = CampbellBozorgnia2014() CY14 = ChiouYoungs2014() gmpes = [ASK14, CB14, CY14] site_gmpes = None weights = [1 / 3.0, 1 / 3.0, 1 / 3.0] gmice = WGRW12() else: Fea96 = FrankelEtAl1996MwNSHMP2008() Tea97 = ToroEtAl1997MwNSHMP2008() Sea02 = SilvaEtAl2002MwNSHMP2008() C03 = Campbell2003MwNSHMP2008() TP05 = TavakoliPezeshk2005MwNSHMP2008() AB06p = AtkinsonBoore2006Modified2011() Pea11 = PezeshkEtAl2011() Atk08p = Atkinson2008prime() Sea01 = SomervilleEtAl2001NSHMP2008() gmpes = [ Fea96, Tea97, Sea02, C03, TP05, AB06p, Pea11, Atk08p, Sea01 ] site_gmpes = [AB06p] weights = [0.16, 0.0, 0.0, 0.17, 0.17, 0.3, 0.2, 0.0, 0.0] gmice = AK07() gmpe = MultiGMPE.from_list(gmpes, weights, default_gmpes_for_site=site_gmpes) min_mmi = config['extent']['mmi']['threshold'] default_imt = imt.SA(1.0) sd_types = [const.StdDev.TOTAL] # Distance context dx = DistancesContext() # This imposes minimum/ maximum distances of: # 80 and 800 km; could make this configurable d_min = config['extent']['mmi']['mindist'] d_max = config['extent']['mmi']['maxdist'] dx.rjb = np.logspace(np.log10(d_min), np.log10(d_max), 2000) # Details don't matter for this; assuming vertical surface rupturing fault # with epicenter at the surface. dx.rrup = dx.rjb dx.rhypo = dx.rjb dx.repi = dx.rjb dx.rx = np.zeros_like(dx.rjb) dx.ry0 = np.zeros_like(dx.rjb) dx.rvolc = np.zeros_like(dx.rjb) # Sites context sx = SitesContext() # Set to soft soil conditions sx.vs30 = np.full_like(dx.rjb, 180) sx = MultiGMPE.set_sites_depth_parameters(sx, gmpe) sx.vs30measured = np.full_like(sx.vs30, False, dtype=bool) sx = Sites._addDepthParameters(sx) sx.backarc = np.full_like(sx.vs30, False, dtype=bool) # Rupture context rx = RuptureContext() rx.mag = origin.mag rx.rake = 0.0 # From WC94... rx.width = 10**(-0.76 + 0.27 * rx.mag) rx.dip = 90.0 rx.ztor = origin.depth rx.hypo_depth = origin.depth gmpe_imt_mean, _ = gmpe.get_mean_and_stddevs(sx, rx, dx, default_imt, sd_types) # Convert to MMI gmpe_to_mmi, _ = gmice.getMIfromGM(gmpe_imt_mean, default_imt) # Minimum distance that exceeds threshold MMI? dists_exceed_mmi = dx.rjb[gmpe_to_mmi > min_mmi] if len(dists_exceed_mmi): mindist_km = np.max(dists_exceed_mmi) else: mindist_km = d_min # Get a projection proj = OrthographicProjection(clon - 4, clon + 4, clat + 4, clat - 4) if isinstance(rupture, (QuadRupture, EdgeRupture)): ruptx, rupty = proj(lons, lats) else: ruptx, rupty = proj(clon, clat) xmin = np.nanmin(ruptx) - mindist_km ymin = np.nanmin(rupty) - mindist_km xmax = np.nanmax(ruptx) + mindist_km ymax = np.nanmax(rupty) + mindist_km # Put a limit on range of aspect ratio dx = xmax - xmin dy = ymax - ymin ar = dy / dx if ar > 1.2: # Inflate x dx_target = dy / 1.2 ddx = dx_target - dx xmax = xmax + ddx / 2 xmin = xmin - ddx / 2 if ar < 0.83: # Inflate y dy_target = dx * 0.83 ddy = dy_target - dy ymax = ymax + ddy / 2 ymin = ymin - ddy / 2 lonmin, latmin = proj(np.array([xmin]), np.array([ymin]), reverse=True) lonmax, latmax = proj(np.array([xmax]), np.array([ymax]), reverse=True) # # Round coordinates to the nearest minute -- that should make the # output grid register with common grid resolutions (60c, 30c, # 15c, 7.5c) # logging.debug("Extent: %f, %f, %f, %f" % (lonmin, lonmax, latmin, latmax)) return _round_coord(lonmin[0]), _round_coord(lonmax[0]), \ _round_coord(latmin[0]), _round_coord(latmax[0])
def _get_extent_from_multigmpe(rupture, config=None): """ Use MultiGMPE to determine extent """ (clon, clat) = _rupture_center(rupture) origin = rupture.getOrigin() if config is not None: gmpe = MultiGMPE.from_config(config) gmice = get_object_from_config('gmice', 'modeling', config) if imt.SA in gmice.DEFINED_FOR_INTENSITY_MEASURE_TYPES: default_imt = imt.SA(1.0) elif imt.PGV in gmice.DEFINED_FOR_INTENSITY_MEASURE_TYPES: default_imt = imt.PGV() else: default_imt = imt.PGA() else: # Put in some default values for conf config = { 'extent': { 'mmi': { 'threshold': 4.5, 'mindist': 100, 'maxdist': 1000 } } } # Generic GMPEs choices based only on active vs stable # as defaults... stable = is_stable(origin.lon, origin.lat) if not stable: ASK14 = AbrahamsonEtAl2014() CB14 = CampbellBozorgnia2014() CY14 = ChiouYoungs2014() gmpes = [ASK14, CB14, CY14] site_gmpes = None weights = [1/3.0, 1/3.0, 1/3.0] gmice = WGRW12() else: Fea96 = FrankelEtAl1996MwNSHMP2008() Tea97 = ToroEtAl1997MwNSHMP2008() Sea02 = SilvaEtAl2002MwNSHMP2008() C03 = Campbell2003MwNSHMP2008() TP05 = TavakoliPezeshk2005MwNSHMP2008() AB06p = AtkinsonBoore2006Modified2011() Pea11 = PezeshkEtAl2011() Atk08p = Atkinson2008prime() Sea01 = SomervilleEtAl2001NSHMP2008() gmpes = [Fea96, Tea97, Sea02, C03, TP05, AB06p, Pea11, Atk08p, Sea01] site_gmpes = [AB06p] weights = [0.16, 0.0, 0.0, 0.17, 0.17, 0.3, 0.2, 0.0, 0.0] gmice = AK07() gmpe = MultiGMPE.from_list( gmpes, weights, default_gmpes_for_site=site_gmpes) default_imt = imt.SA(1.0) min_mmi = config['extent']['mmi']['threshold'] sd_types = [const.StdDev.TOTAL] # Distance context dx = DistancesContext() # This imposes minimum/ maximum distances of: # 80 and 800 km; could make this configurable d_min = config['extent']['mmi']['mindist'] d_max = config['extent']['mmi']['maxdist'] dx.rjb = np.logspace(np.log10(d_min), np.log10(d_max), 2000) # Details don't matter for this; assuming vertical surface rupturing fault # with epicenter at the surface. dx.rrup = dx.rjb dx.rhypo = dx.rjb dx.repi = dx.rjb dx.rx = np.zeros_like(dx.rjb) dx.ry0 = np.zeros_like(dx.rjb) dx.rvolc = np.zeros_like(dx.rjb) # Sites context sx = SitesContext() # Set to soft soil conditions sx.vs30 = np.full_like(dx.rjb, 180) sx = MultiGMPE.set_sites_depth_parameters(sx, gmpe) sx.vs30measured = np.full_like(sx.vs30, False, dtype=bool) sx = Sites._addDepthParameters(sx) sx.backarc = np.full_like(sx.vs30, False, dtype=bool) # Rupture context rx = RuptureContext() rx.mag = origin.mag rx.rake = 0.0 # From WC94... rx.width = 10**(-0.76 + 0.27*rx.mag) rx.dip = 90.0 rx.ztor = origin.depth rx.hypo_depth = origin.depth gmpe_imt_mean, _ = gmpe.get_mean_and_stddevs( sx, rx, dx, default_imt, sd_types) # Convert to MMI gmpe_to_mmi, _ = gmice.getMIfromGM(gmpe_imt_mean, default_imt) # Minimum distance that exceeds threshold MMI? dists_exceed_mmi = dx.rjb[gmpe_to_mmi > min_mmi] if len(dists_exceed_mmi): mindist_km = np.max(dists_exceed_mmi) else: mindist_km = d_min # Get a projection proj = OrthographicProjection(clon - 4, clon + 4, clat + 4, clat - 4) if isinstance(rupture, (QuadRupture, EdgeRupture)): ruptx, rupty = proj( rupture.lons[~np.isnan(rupture.lons)], rupture.lats[~np.isnan(rupture.lats)] ) else: ruptx, rupty = proj(clon, clat) xmin = np.nanmin(ruptx) - mindist_km ymin = np.nanmin(rupty) - mindist_km xmax = np.nanmax(ruptx) + mindist_km ymax = np.nanmax(rupty) + mindist_km # Put a limit on range of aspect ratio dx = xmax - xmin dy = ymax - ymin ar = dy / dx if ar > 1.2: # Inflate x dx_target = dy / 1.2 ddx = dx_target - dx xmax = xmax + ddx / 2 xmin = xmin - ddx / 2 if ar < 0.83: # Inflate y dy_target = dx * 0.83 ddy = dy_target - dy ymax = ymax + ddy / 2 ymin = ymin - ddy / 2 lonmin, latmin = proj(np.array([xmin]), np.array([ymin]), reverse=True) lonmax, latmax = proj(np.array([xmax]), np.array([ymax]), reverse=True) # # Round coordinates to the nearest minute -- that should make the # output grid register with common grid resolutions (60c, 30c, # 15c, 7.5c) # logging.debug("Extent: %f, %f, %f, %f" % (lonmin, lonmax, latmin, latmax)) return _round_coord(lonmin[0]), _round_coord(lonmax[0]), \ _round_coord(latmin[0]), _round_coord(latmax[0])
from openquake.hazardlib.gsim.chiou_youngs_2014 import ChiouYoungs2014 from openquake.hazardlib.imt import PGA, SA from openquake.hazardlib.gsim.base import SitesContext from openquake.hazardlib.gsim.base import DistancesContext from openquake.hazardlib.gsim.base import RuptureContext from openquake.hazardlib import const from shakelib.multigmpe import MultiGMPE from shakelib.rupture.factory import get_rupture from shakelib.rupture.origin import Origin # List of GMPEs to use. gmpe_list = [ BooreEtAl2014(), CampbellBozorgnia2014(), AbrahamsonEtAl2014(), ChiouYoungs2014() ] # GMPE weights. weight_list = [0.25] * 4 # Intensity measure component. imc = const.IMC.RotD50 # Create multigmpe instance. gmpe = MultiGMPE.from_list(gmpe_list, weight_list, imc) # Define IMTs and standard deviations. imts = [PGA(), SA(0.1), SA(0.2), SA(0.3), SA(0.5), SA(1), SA(2), SA(3), SA(5)] sd_types = [const.StdDev.INTER_EVENT, const.StdDev.INTRA_EVENT]
limits_filename = f_in.readline().rstrip().split(',')[1] except: limits_filename = None if event_name == '1852Banda_area' or event_name == '1852Banda_domain_ryan_mmi' or \ event_name == '1852Banda_domain_FH_mmi' or event_name == '1852Banda_exclude_20min_ryan_mmi' or\ event_name == '1852Banda_exclude_20min_FH_mmi' or event_name == '1852Banda_exclude_15min_FH_mmi' or \ event_name == '1852Banda_exclude_15min_ryan_mmi': disc = 10 else: disc = 5 # Area or fault source model is used to define the parameter space to be searched if trt == 'Subduction Intraslab': gsim_list = [ZhaoEtAl2006SSlab(), AtkinsonBoore2003SSlab(), AtkinsonBoore2003SSlabCascadia(), AbrahamsonEtAl2015SSlab()] if trt == 'Active': # gsim_list = [ChiouYoungs2008(), ChiouYoungs2014(), BooreAtkinson2008(), BooreEtAl2014(), CampbellBozorgnia2008(), CampbellBozorgnia2014() ] gsim_list = [ChiouYoungs2014(), BooreEtAl2014(), CampbellBozorgnia2014()] if trt == 'Subduction Interface': gsim_list = [AbrahamsonEtAl2015SInter(), ZhaoEtAl2006SInter(), YoungsEtAl1997SInter(), AtkinsonBoore2003SInter()] if trt == 'Mixed': gsim_list = [AbrahamsonEtAl2015SInter(), BooreEtAl2014(), ChiouYoungs2014(), ZhaoEtAl2006SInter()] def build_site_col(sites_data, site_model_file, filename=None): """Interpolate vs30 values to sites of interest """ # sites_data = np.genfromtxt(site_file) site_points = [] for i in range(len(sites_data[:,0])): site_pt = Point(sites_data[i,0], sites_data[i,1]) site_points.append(site_pt) sitecol = get_site_collection(site_model_file, site_points, None,filename) return sitecol
def setUp(self): """ Builds a simple dipping/bending fault source with a characteristic source model. Compares the curves for four sites, two on the hanging wall and two on the footwall. The source model is taken from the PEER Tests """ point_order_dipping_east = [ Point(-64.78365, -0.45236), Point(-64.80164, -0.45236), Point(-64.90498, -0.36564), Point(-65.0000, -0.16188), Point(-65.0000, 0.0000) ] trace_dip_east = Line(point_order_dipping_east) site_1 = Site(Point(-64.98651, -0.15738), 760.0, 48.0, 0.607, vs30measured=True) site_2 = Site(Point(-64.77466, -0.45686), 760.0, 48.0, 0.607, vs30measured=True) site_3 = Site(Point(-64.92747, -0.38363), 760.0, 48.0, 0.607, vs30measured=True) site_4 = Site(Point(-65.05396, -0.17088), 760.0, 48.0, 0.607, vs30measured=True) self.sites = SiteCollection([site_1, site_2, site_3, site_4]) self.imtls = { "PGA": [ 0.001, 0.01, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.7, 0.8, 0.9, 1.0 ] } fault_surface1 = SimpleFaultSurface.from_fault_data( trace_dip_east, 0.0, 12.0, 60., 0.5) mfd1 = EvenlyDiscretizedMFD(6.75, 0.01, [0.01]) tom = PoissonTOM(1.0) self.sources = [ CharacteristicFaultSource( "PEER_CHAR_FLT_EAST", "Peer Bending Fault Dipping East - Characteristic", "Active Shallow Crust", mfd1, tom, fault_surface1, 90.0) ] # We will check all the GMPEs self.gsim_set = { "ASK": [ NSHMP2014(gmpe_name='AbrahamsonEtAl2014', sgn=0), (0.185, NSHMP2014(gmpe_name='AbrahamsonEtAl2014', sgn=-1)), (0.63, AbrahamsonEtAl2014()), (0.185, NSHMP2014(gmpe_name='AbrahamsonEtAl2014', sgn=1)) ], "BSSA": [ NSHMP2014(gmpe_name='BooreEtAl2014', sgn=0), (0.185, NSHMP2014(gmpe_name='BooreEtAl2014', sgn=-1)), (0.63, BooreEtAl2014()), (0.185, NSHMP2014(gmpe_name='BooreEtAl2014', sgn=1)) ], "CB": [ NSHMP2014(gmpe_name='CampbellBozorgnia2014', sgn=0), (0.185, NSHMP2014(gmpe_name='CampbellBozorgnia2014', sgn=-1)), (0.63, CampbellBozorgnia2014()), (0.185, NSHMP2014(gmpe_name='CampbellBozorgnia2014', sgn=1)) ], "CY": [ NSHMP2014(gmpe_name='ChiouYoungs2014', sgn=0), (0.185, NSHMP2014(gmpe_name='ChiouYoungs2014', sgn=-1)), (0.63, ChiouYoungs2014()), (0.185, NSHMP2014(gmpe_name='ChiouYoungs2014', sgn=1)) ], "ID": [ NSHMP2014(gmpe_name='Idriss2014', sgn=0), (0.185, NSHMP2014(gmpe_name='Idriss2014', sgn=-1)), (0.63, Idriss2014()), (0.185, NSHMP2014(gmpe_name='Idriss2014', sgn=1)) ] }