def get_model_syntest_cmb_topo(): model_ref = SeismicModel.ak135() types = [ParameterType.VSV, ParameterType.RADIUS] radii = np.array([3479.5, 3679.5], dtype='float') model_params = ModelParameters( types, radii, mesh_type='lininterp') model = model_ref.lininterp_mesh( model_params, discontinuous=True) # set D'' layer to constant velocity and density depth_dpp = 2691.5 idpp = model.get_zone(3479.5) for p_type in [ ParameterType.VSH, ParameterType.VSV, ParameterType.VPH, ParameterType.VPV, ParameterType.RHO]: v_dpp = model.get_value_at(6371.-depth_dpp, p_type) model.set_value( idpp, p_type, np.array([v_dpp, 0., 0., 0.])) values = np.array([0.2, 0.2]) values_dict = { ParameterType.VSV: values, ParameterType.RADIUS: np.array([-8., 0.])} model_mul = model.build_model(model, model_params, values_dict) return model_mul
def ak135_lin_dpp(): model = SeismicModel.ak135() r0 = 4000. model = model._add_boundary(r0) izone = model.get_zone(r0 - 1e-5) vp_cmb = model.get_value_at(3479.5, ParameterType.VPH) vp_r0 = model.get_value_at(r0, ParameterType.VPH) vp_cmb_p = vp_cmb + 0.09 vs_cmb = model.get_value_at(3479.5, ParameterType.VSH) vs_r0 = model.get_value_at(r0, ParameterType.VSH) x_cmb = 3479.5 / 6371 x0 = r0 / 6371 poly_vp = model._lin_element(x_cmb, x0, vp_cmb_p, vp_r0) poly_vs = model._lin_element(x_cmb, x0, vs_cmb, vs_r0) for p_type in [ParameterType.VPH, ParameterType.VPV]: model.set_value(izone, p_type, poly_vp) model.set_value(izone - 1, p_type, poly_vp) for p_type in [ParameterType.VSH, ParameterType.VSV]: model.set_value(izone, p_type, poly_vs) model.set_value(izone - 1, p_type, poly_vs) return model
def get_model(n_upper_mantle=20, n_mtz=10, n_lower_mantle=12, types=[ParameterType.VSH], verbose=0): '''Boxcar mesh using ak135 as reference model for the structure of the upper mantle and transition zone down to 1000 km depth. ''' ak135 = SeismicModel.ak135() # model parameters depth_moho = 6371. - 6336.6 depth_410 = 410. depth_660 = 660. depth_max = 1000. rs_upper_mantle = np.linspace(depth_410, depth_moho, n_upper_mantle + 1) rs_mtz = np.linspace(depth_660, depth_410, n_mtz, endpoint=False) rs_lower_mantle = np.linspace(depth_max, depth_660, n_lower_mantle, endpoint=False) radii = 6371. - np.round( np.hstack((rs_lower_mantle, rs_mtz, rs_upper_mantle)), 4) if verbose > 1: print('dr_um={}, dr_mtz={}, dr_lm={}'.format( rs_upper_mantle[1] - rs_upper_mantle[0], rs_mtz[1] - rs_mtz[0], rs_lower_mantle[1] - rs_lower_mantle[0])) model_params = ModelParameters(types, radii, mesh_type='boxcar') # mesh # model, mesh = ak135.boxcar_mesh(model_params) return ak135, model_params
def get_model_syntest1(): model_ref = SeismicModel.ak135() types = [ParameterType.VSH] radii = np.array([3479.5, 3680., 3880.], dtype='float') model_params = ModelParameters(types, radii, mesh_type='boxcar') model, mesh = model_ref.boxcar_mesh(model_params) values = np.array( [.2 * (-1)**i for i in range(model_params.get_n_grd_params())]) values_dict = {param_type: values for param_type in types} values_mat = model_params.get_values_matrix(values_dict) model_updated = mesh.multiply(values_mat) return model_updated
def get_model_syntest1(): model_ref = SeismicModel.ak135() types = [ParameterType.VSH] radii = 6371. - np.array([493.33, 410.]) model_params = ModelParameters(types, radii, mesh_type='boxcar') model, mesh = model_ref.boxcar_mesh(model_params) values = np.array( [.2 * (-1)**i for i in range(model_params._n_grd_params)]) values_dict = {param_type: values for param_type in types} values_mat = model_params.get_values_matrix(values_dict) mesh_mul = mesh.multiply(model_params.get_nodes(), values_mat) model_mul = model + mesh_mul return model_mul
def get_output(tlen=1638.4, nspc=64, sampling_hz=20, mode=0): catalog = read_catalog() event = Event.event_from_catalog(catalog, '200707211534A') stations = [ Station('{:03d}'.format(i), 'DSM', event.latitude, event.longitude + i) for i in range(12, 36) ] model = SeismicModel.ak135() pydsm_input = PyDSMInput.input_from_arrays(event, stations, model, tlen, nspc, sampling_hz) pydsm_output = compute(pydsm_input, mode=mode) pydsm_output.to_time_domain() return pydsm_output
def get_model_lininterp(n_mtz=10, n_lower_mantle=12, types=[ParameterType.VSH], discontinuous=True, verbose=0): """Boxcar mesh using ak135 as reference model for the structure of the upper mantle and transition zone down to 1000 km depth. """ ak135 = SeismicModel.ak135() radii = np.array([5371, 5611, 5711, 5836, 5961, 6161, 6251, 6336.6]) model_params = ModelParameters(types, radii, mesh_type='lininterp') # mesh model = ak135.lininterp_mesh(model_params, discontinuous=discontinuous) return model, model_params
def get_model_lininterp( n_upper_mantle=20, n_mtz=10, n_lower_mantle=12, n_dpp=8, types=[ParameterType.VSH], discontinuous=False, verbose=0): """Boxcar mesh using ak135 as reference model for the structure of the upper mantle and transition zone down to 1000 km depth. """ ak135 = SeismicModel.ak135() # model parameters depth_moho = 6371. - 6336.6 depth_410 = 410. depth_660 = 660. depth_dpp = 2691.5 depth_cmb = 2891.5 rs_upper_mantle = np.linspace(depth_410, depth_moho, n_upper_mantle) rs_mtz = np.linspace(depth_660, depth_410, n_mtz, endpoint=(n_upper_mantle==0)) rs_lower_mantle = np.linspace( depth_dpp, depth_660, n_lower_mantle, endpoint=(n_mtz==0)) rs_dpp = np.linspace( depth_cmb, depth_dpp, n_dpp, endpoint=(n_lower_mantle==0)) radii = 6371. - np.round( np.hstack((rs_dpp, rs_lower_mantle, rs_mtz, rs_upper_mantle)), 4) if verbose > 1: print('dr_um={}, dr_mtz={}, dr_lm={}, dr_dpp={}'.format( rs_upper_mantle[1] - rs_upper_mantle[0], rs_mtz[1] - rs_mtz[0], rs_lower_mantle[1] - rs_lower_mantle[0], rs_dpp[1] - rs_dpp[0])) model_params = ModelParameters(types, radii, mesh_type='lininterp') # mesh model = ak135.lininterp_mesh(model_params, discontinuous=discontinuous) # set D'' layer to constant velocity and density idpp = model.get_zone(3479.5) for p_type in [ ParameterType.VSH, ParameterType.VSV, ParameterType.VPH, ParameterType.VPV, ParameterType.RHO]: v_dpp = model.get_value_at(6371.-depth_dpp, p_type) model.set_value( idpp, p_type, np.array([v_dpp, 0., 0., 0.])) return model, model_params
def get_model_syntest4(): model_ref = SeismicModel.ak135() types = [ParameterType.VSH] radii = np.array([3479.5, 3489.5], dtype='float') model_params = ModelParameters( types, radii, mesh_type='lininterp') model = model_ref.lininterp_mesh( model_params, discontinuous=True) izone = model.get_zone(3479.5) vsh_dpp = model.get_value_at(radii[-1], ParameterType.VSH) model._vsh[:, izone] = np.array([vsh_dpp, 0., 0., 0.]) # model._vsh[:, izone+1] = np.array([vsh_dpp, 0., 0., 0.]) values_p = np.array([0.2, 0.2]) values_dict_p = {param_type: values_p for param_type in types} values_m = np.array([0., 0.]) values_dict_m = {param_type: values_m for param_type in types} model_mul = model.build_model( model, model_params, values_dict_p) return model_mul
from dsmpy.seismicmodel import SeismicModel import matplotlib.pyplot as plt import matplotlib.gridspec as gridspec import numpy as np from mpi4py import MPI import os import sys comm = MPI.COMM_WORLD n_core = comm.Get_size() rank = comm.Get_rank() result = InversionResult.load(sys.argv[1]) loaded = True model_ref = SeismicModel.ak135() types = [ParameterType.VSH, ParameterType.RADIUS] figscale = 1. # compute best models if rank == 0: indices_better = [0] for imod in range(1, result.meta['n_mod']): i_best = result.get_indices_best_models(n_best=1, n_mod=imod+1) if i_best != indices_better[-1]: indices_better.append(imod) models = [result.models[i] for i in indices_better] else: models = None outputs = result.compute_models(models)
print('Results saved to \'{}\''.format(result_path)) fig, ax = dataset.plot_event(0, windows, component=Component.T, align_zero=True, color='black') cycler = plt.rcParams['axes.prop_cycle'] for imod, sty in enumerate(cycler[:n_block]): _, ax = outputs[imod][0].plot_component(Component.T, windows, ax=ax, align_zero=True, **sty) plt.savefig('profiles_syntest2.pdf') plt.close(fig) # plt.show() fig, ax = result.plot_models(types=[ParameterType.VSH], n_best=3) # fig, ax = work_parameters.get_model_syntest1().plot( # types=[ParameterType.VSH], ax=ax, color='red') fig, ax = work_parameters.get_model_syntest2().plot( types=[ParameterType.VSH], ax=ax, color='red') fig, ax = SeismicModel.ak135().plot(types=[ParameterType.VSH], ax=ax, color='blue') ax.set(ylim=[model_params._radii[0] - 100, 6371]) ax.get_legend().remove() plt.savefig('recovered_models_syntest2.pdf') # plt.show() plt.close(fig)
def get_dataset_syntest3(tlen=1638.4, nspc=256, sampling_hz=20, mode=0, add_noise=False, noise_normalized_std=1.): return get_dataset(get_model_syntest3(), tlen, nspc, sampling_hz, mode, add_noise, noise_normalized_std) if __name__ == '__main__': model, model_params = get_model_lininterp( types=[ParameterType.VSH, ParameterType.RADIUS]) fig, ax = get_model_syntest3().plot() SeismicModel.ak135().plot(ax=ax) plt.show() dataset, _ = get_dataset_syntest3(nspc=64, mode=2) dataset.plot_event(0) plt.show() fig, ax = SeismicModel.ak135().plot(types=[ParameterType.VSH], dr=.5, label='') mask_dict = dict() mask_dict[ParameterType.VSH] = np.ones(model_params._n_grd_params // 2, dtype='bool') mask_dict[ParameterType.RADIUS] = np.zeros(model_params._n_grd_params // 2, dtype='bool')
def get_dataset_ref(tlen=1638.4, nspc=256, sampling_hz=20, mode=0): return get_dataset( SeismicModel.ak135(), tlen, nspc, sampling_hz, mode)[0]
model.set_value( idpp, p_type, np.array([v_dpp, 0., 0., 0.])) values = np.array([0.2, 0.2]) values_dict = { ParameterType.VSV: values, ParameterType.RADIUS: np.array([-8., 0.])} model_mul = model.build_model(model, model_params, values_dict) return model_mul if __name__ == '__main__': model_syntest2 = get_model_syntest2() fig, ax = model_syntest2.plot() SeismicModel.ak135().plot(ax=ax, label='ak135') plt.show() # plt.savefig('model_syntest2.pdf') # plt.show() # plt.close(fig) # fig, ax = get_model_syntest4().plot(types=[ParameterType.VSH]) # SeismicModel.ak135().plot(types=[ParameterType.VSH], ax=ax, label='ak135') # plt.show() model_, model_params = get_model_lininterp(0, 0, 0, 2, discontinuous=True) value_dict = { ParameterType.VSH: np.array([0.2, 0.2]), ParameterType.RADIUS: np.array([0., -8.])} value_dict_m = {