def setUp(self): path = os.path.join(BASE_DATA_PATH, 'profiles06') self.profiles, _ = _read_profiles(path) self.h_sampl = 4 self.v_sampl = 4 idl = False alg = False self.smsh = create_from_profiles(self.profiles, self.h_sampl, self.v_sampl, idl, alg)
def setUp(self): path = os.path.join(BASE_DATA_PATH, 'south_america_segment6_slab') self.profiles, _ = _read_profiles(path)
def setUp(self): path = os.path.join(BASE_DATA_PATH, 'profiles05') self.profiles, _ = _read_profiles(path)
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)