def test_get_available_scalerel(self): self.assertEqual( { 'WC1994': scalerel.wc1994.WC1994, 'PeerMSR': scalerel.peer.PeerMSR, 'CEUS2011': scalerel.ceus2011.CEUS2011 }, dict(scalerel.get_available_scalerel()))
def test_get_available_scalerel(self): self.assertEqual({'WC1994': scalerel.wc1994.WC1994, 'PeerMSR': scalerel.peer.PeerMSR, 'PointMSR': scalerel.point.PointMSR, 'CEUS2011': scalerel.ceus2011.CEUS2011, 'StrasserInterface': scalerel.strasser2010.StrasserInterface, 'StrasserIntraslab': scalerel.strasser2010.StrasserIntraslab}, dict(scalerel.get_available_scalerel()))
# # The Hazard Modeller's Toolkit (openquake.hmtk) is therefore distributed WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # for more details. # # The GEM Foundation, and the authors of the software, assume no # liability for use of the software. from openquake.hazardlib.pmf import PMF from openquake.hazardlib.geo.nodalplane import NodalPlane from openquake.hazardlib.scalerel import get_available_scalerel from openquake.hazardlib.scalerel.base import BaseMSR from openquake.hazardlib.scalerel.wc1994 import WC1994 SCALE_RELS = get_available_scalerel() def render_aspect_ratio(aspect_ratio, use_default=False): ''' Returns the aspect ratio if one is defined for the source, otherwise if defaults are accepted a default value of 1.0 is returned or else a ValueError is raised :param float aspect_ratio: Ratio of along strike-length to down-dip width of the rupture :param bool use_default: If true, when aspect_ratio is undefined will return default value of 1.0, otherwise will raise an error. '''
def _test_get_available_scalerel(self): self.assertGreater(len(get_available_scalerel()), 0)
''' import numpy as np from math import fabs from openquake.hazardlib.scalerel import get_available_scalerel from openquake.hazardlib.mfd.evenly_discretized import EvenlyDiscretizedMFD from openquake.hmtk.models import IncrementalMFD from openquake.hmtk.faults.fault_geometries import (SimpleFaultGeometry, ComplexFaultGeometry) from openquake.hmtk.sources.simple_fault_source import mtkSimpleFaultSource from openquake.hmtk.sources.complex_fault_source import mtkComplexFaultSource from openquake.hmtk.faults import mfd MFD_MAP = mfd.get_available_mfds() SCALE_REL_MAP = get_available_scalerel() DEFAULT_MSR_SIGMA = [(0., 1.0)] def _update_slip_rates_with_aseismic(slip_rate, aseismic): ''' For all the slip rates in the slip rate tuple, multiply by the aseismic coefficient :param list slip_rate: List of tuples (Slip Value, Weight) defining the slip distribution :param float aseismic: Fractional proportion of slip release aseismically :returns: slip - List of tuples (Slip Value, Weight) for adjusted slip rates '''
# for more details. # # The GEM Foundation, and the authors of the software, assume no # liability for use of the software. # -*- coding: utf-8 -*- import abc from decimal import Decimal from openquake.hazardlib.pmf import PMF from openquake.hazardlib.geo.nodalplane import NodalPlane from openquake.hazardlib import mfd from openquake.hazardlib.scalerel import get_available_scalerel from openquake.hazardlib.scalerel.base import BaseMSR from openquake.hazardlib.scalerel.wc1994 import WC1994 SCALE_RELS = get_available_scalerel() def render_aspect_ratio(aspect_ratio, use_default=False): ''' Returns the aspect ratio if one is defined for the source, otherwise if defaults are accepted a default value of 1.0 is returned or else a ValueError is raised :param float aspect_ratio: Ratio of along strike-length to down-dip width of the rupture :param bool use_default: If true, when aspect_ratio is undefined will return default value of 1.0, otherwise will raise an error. '''
import yaml import numpy as np from math import fabs from openquake.hazardlib.geo.point import Point from openquake.hazardlib.geo.line import Line from openquake.hazardlib.scalerel import get_available_scalerel from hmtk.faults.fault_geometries import (SimpleFaultGeometry, ComplexFaultGeometry) from hmtk.faults.fault_models import mtkActiveFault from hmtk.faults.active_fault_model import mtkActiveFaultModel from hmtk.faults.tectonic_regionalisation import (TectonicRegionalisation, _check_list_weights) SCALE_REL_MAP = get_available_scalerel() def weight_list_to_tuple(data, attr_name): ''' Converts a list of values and corresponding weights to a tuple of values ''' if len(data['Value']) != len(data['Weight']): raise ValueError('Number of weights do not correspond to number of ' 'attributes in %s' % attr_name) weight = np.array(data['Weight']) if fabs(np.sum(weight) - 1.) > 1E-7: raise ValueError('Weights do not sum to 1.0 in %s' % attr_name) data_tuple = []
def calculate_ruptures(ini_fname, only_plt=False, ref_fdr=None): """ :param str ini_fname: The name of a .ini file :param ref_fdr: The path to the reference folder used to set the paths in the .ini file. If not provided directly, we use the one set in the .ini file. """ # # read config file config = configparser.ConfigParser() config.readfp(open(ini_fname)) # # logging settings logging.basicConfig(format='rupture:%(levelname)s:%(message)s') # # reference folder if ref_fdr is None: ref_fdr = config.get('main', 'reference_folder') # # set parameters profile_sd_topsl = config.getfloat('main', 'profile_sd_topsl') edge_sd_topsl = config.getfloat('main', 'edge_sd_topsl') # this sampling distance is used to sampling = config.getfloat('main', 'sampling') float_strike = config.getfloat('main', 'float_strike') float_dip = config.getfloat('main', 'float_dip') slab_thickness = config.getfloat('main', 'slab_thickness') label = config.get('main', 'label') hspa = config.getfloat('main', 'hspa') vspa = config.getfloat('main', 'vspa') uniform_fraction = config.getfloat('main', 'uniform_fraction') # # MFD params agr = config.getfloat('main', 'agr') bgr = config.getfloat('main', 'bgr') mmax = config.getfloat('main', 'mmax') mmin = config.getfloat('main', 'mmin') # # IDL if config.has_option('main', 'idl'): idl = config.get('main', 'idl') else: idl = False # # IDL align = False if config.has_option('main', 'profile_alignment'): tmps = config.get('main', 'profile_alignment') if re.search('true', tmps.lower()): align = True # # set profile folder path = config.get('main', 'profile_folder') path = os.path.abspath(os.path.join(ref_fdr, path)) # # catalogue cat_pickle_fname = config.get('main', 'catalogue_pickle_fname') cat_pickle_fname = os.path.abspath(os.path.join(ref_fdr, cat_pickle_fname)) # # output hdf5_filename = config.get('main', 'out_hdf5_fname') hdf5_filename = os.path.abspath(os.path.join(ref_fdr, hdf5_filename)) # # smoothing output out_hdf5_smoothing_fname = config.get('main', 'out_hdf5_smoothing_fname') tmps = os.path.join(ref_fdr, out_hdf5_smoothing_fname) out_hdf5_smoothing_fname = os.path.abspath(tmps) # # tectonic regionalisation treg_filename = config.get('main', 'treg_fname') if not re.search('[a-z]', treg_filename): treg_filename = None else: treg_filename = os.path.abspath(os.path.join(ref_fdr, treg_filename)) # # dips = list_of_floats_from_string(config.get('main', 'dips')) asprsstr = config.get('main', 'aspect_ratios') asprs = dict_of_floats_from_string(asprsstr) # # magnitude-scaling relationship msrstr = config.get('main', 'mag_scaling_relation') msrd = get_available_scalerel() if msrstr not in msrd.keys(): raise ValueError('') msr = msrd[msrstr]() # # ------------------------------------------------------------------------ logging.info('Reading profiles from: {:s}'.format(path)) profiles, pro_fnames = _read_profiles(path) assert len(profiles) > 0 # """ if logging.getLogger().isEnabledFor(logging.DEBUG): import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D fig = plt.figure(figsize=(10, 8)) ax = fig.add_subplot(111, projection='3d') for ipro, (pro, fnme) in enumerate(zip(profiles, pro_fnames)): tmp = [[p.longitude, p.latitude, p.depth] for p in pro.points] tmp = np.array(tmp) ax.plot(tmp[:, 0], tmp[:, 1], tmp[:, 2], 'x--b', markersize=2) tmps = '{:d}-{:s}'.format(ipro, os.path.basename(fnme)) ax.text(tmp[0, 0], tmp[0, 1], tmp[0, 2], tmps) ax.invert_zaxis() ax.view_init(50, 55) plt.show() """ # # create mesh from profiles msh = create_from_profiles(profiles, profile_sd_topsl, edge_sd_topsl, idl) # # Create inslab mesh. The one created here describes the top of the slab. # The output (i.e ohs) is a dictionary with the values of dip as keys. The # values in the dictionary are :class:`openquake.hazardlib.geo.line.Line` # instances ohs = create_inslab_meshes(msh, dips, slab_thickness, sampling) if only_plt: pass """ azim = 10. elev = 20. dist = 20. f = mlab.figure(bgcolor=(1, 1, 1), size=(900, 600)) vsc = -0.01 # # profiles for ipro, (pro, fnme) in enumerate(zip(profiles, pro_fnames)): tmp = [[p.longitude, p.latitude, p.depth] for p in pro.points] tmp = np.array(tmp) tmp[tmp[:, 0] < 0, 0] = tmp[tmp[:, 0] < 0, 0] + 360 mlab.plot3d(tmp[:, 0], tmp[:, 1], tmp[:, 2]*vsc, color=(1, 0, 0)) # # top of the slab mesh plot_mesh_mayavi(msh, vsc, color=(0, 1, 0)) # for key in ohs: for iii in range(len(ohs[key])): for line in ohs[key][iii]: pnt = np.array([[p.longitude, p.latitude, p.depth] for p in line.points]) pnt[pnt[:, 0] < 0, 0] = pnt[pnt[:, 0] < 0, 0] + 360 mlab.plot3d(pnt[:, 0], pnt[:, 1], pnt[:, 2]*vsc, color=(0, 0, 1)) f.scene.camera.azimuth(azim) f.scene.camera.elevation(elev) mlab.view(distance=dist) mlab.show() mlab.show() exit(0) """ if 1: vsc = 0.01 import matplotlib.pyplot as plt # MN: 'Axes3D' imported but never used from mpl_toolkits.mplot3d import Axes3D fig = plt.figure(figsize=(10, 8)) ax = fig.add_subplot(111, projection='3d') # # profiles for ipro, (pro, fnme) in enumerate(zip(profiles, pro_fnames)): tmp = [[p.longitude, p.latitude, p.depth] for p in pro.points] tmp = np.array(tmp) tmp[tmp[:, 0] < 0, 0] = tmp[tmp[:, 0] < 0, 0] + 360 ax.plot(tmp[:, 0], tmp[:, 1], tmp[:, 2] * vsc, 'x--b', markersize=2) tmps = '{:d}-{:s}'.format(ipro, os.path.basename(fnme)) ax.text(tmp[0, 0], tmp[0, 1], tmp[0, 2] * vsc, tmps) # # top of the slab mesh # plot_mesh(ax, msh, vsc) # for key in ohs: for iii in range(len(ohs[key])): for line in ohs[key][iii]: pnt = np.array([[p.longitude, p.latitude, p.depth] for p in line.points]) pnt[pnt[:, 0] < 0, 0] = pnt[pnt[:, 0] < 0, 0] + 360 ax.plot(pnt[:, 0], pnt[:, 1], pnt[:, 2] * vsc, '-r') ax.invert_zaxis() ax.view_init(50, 55) plt.show() # # The one created here describes the bottom of the slab lmsh = create_lower_surface_mesh(msh, slab_thickness) # # get min and max values milo, mila, mide, malo, mala, made = get_min_max(msh, lmsh) # # discretizing the slab # omsh = Mesh(msh[:, :, 0], msh[:, :, 1], msh[:, :, 2]) # olmsh = Mesh(lmsh[:, :, 0], lmsh[:, :, 1], lmsh[:, :, 2]) # # this `dlt` value [in degrees] is used to create a buffer around the mesh dlt = 5.0 msh3d = Grid3d(milo - dlt, mila - dlt, mide, malo + dlt, mala + dlt, made, hspa, vspa) # mlo, mla, mde = msh3d.select_nodes_within_two_meshesa(omsh, olmsh) mlo, mla, mde = msh3d.get_coordinates_vectors() # # save data on hdf5 file if os.path.exists(hdf5_filename): os.remove(hdf5_filename) logging.info('Creating {:s}'.format(hdf5_filename)) fh5 = h5py.File(hdf5_filename, 'w') grp_slab = fh5.create_group('slab') dset = grp_slab.create_dataset('top', data=msh) dset.attrs['spacing'] = sampling grp_slab.create_dataset('bot', data=lmsh) fh5.close() # # get catalogue catalogue = get_catalogue(cat_pickle_fname, treg_filename, label) # # smoothing values, smooth = smoothing(mlo, mla, mde, catalogue, hspa, vspa, out_hdf5_smoothing_fname) # # spatial index # r = spatial_index(mlo, mla, mde, catalogue, hspa, vspa) r, proj = spatial_index(smooth) # # magnitude-frequency distribution mfd = TruncatedGRMFD(min_mag=mmin, max_mag=mmax, bin_width=0.1, a_val=agr, b_val=bgr) # # create all the ruptures - the probability of occurrence is for one year # in this case # MN: 'Axes3D' assigned but never used allrup = create_ruptures(mfd, dips, sampling, msr, asprs, float_strike, float_dip, r, values, ohs, 1., hdf5_filename, uniform_fraction, proj, idl, align, True)
def test_get_available_scalerel(self): self.assertEqual({'WC1994': scalerel.wc1994.WC1994, 'PeerMSR': scalerel.peer.PeerMSR, 'PointMSR': scalerel.point.PointMSR, 'CEUS2011': scalerel.ceus2011.CEUS2011}, dict(scalerel.get_available_scalerel()))