Exemplo n.º 1
0
        if i_best != indices_better[-1]:
            print(i_best, imod)
            indices_better.append(imod)
    print(indices_better)
    print(len(result.models))
    models = [result.models[i] for i in indices_better]
else:
    models = None
outputs = result.compute_models(models)

# plot results
if rank == 0:
    out_dir = result.meta['out_dir']
    points = NeighbouhoodAlgorithm._get_points_for_voronoi(
                result.perturbations, range_dict, model_params._types)
    points = points[:, model_params.get_free_indices()]
    # points = np.array(result.perturbations)[
    # :, model_params.get_free_indices()]
    misfits = result.misfit_dict['variance'].mean(axis=1)
    n_r = result.meta['n_r']
    n_s = result.meta['n_s']
    n_mod = points.shape[0]
    i_out = 0
    for imod in range(n_mod):
        figpath = os.path.join(
            out_dir, 'voronoi_{:05d}.png'.format(imod))
        fig = plt.figure(figsize=(17,5))
        gs = gridspec.GridSpec(1, 4, width_ratios=[2, 1, 1, 1])
        # plot voronoi cells
        ax0 = fig.add_subplot(gs[0])
        _, _, colormap = plot_voronoi_2d(
Exemplo n.º 2
0
                                              dtype='bool')
    mask_dict[ParameterType.RADIUS][[0, 1]] = False

    equal_dict = dict()
    equal_dict[ParameterType.VSH] = np.arange(model_params._n_grd_params,
                                              dtype='int')
    equal_dict[ParameterType.VSH][2] = 0
    equal_dict[ParameterType.VSH][3] = 1

    discon_arr = np.zeros(model_params._n_nodes, dtype='bool')
    discon_arr[1] = True

    model_params.set_constraints(mask_dict=mask_dict,
                                 equal_dict=equal_dict,
                                 discon_arr=discon_arr)

    print('Free indices:', model_params.get_free_indices())

    rng = np.random.default_rng(seed=0)
    fig, ax = plt.subplots(1)
    for i in range(5):
        values = np.zeros((model_params._n_grd_params, len(types)))
        values[:, 0] = rng.uniform(-0.5, 0.5, size=(values.shape[0]))
        values[:, 1] = rng.uniform(-100, 100, size=(values.shape[0]))
        values_dict = {
            param_type: values[:, i]
            for i, param_type in enumerate(types)
        }
        model_gen = model.build_model(model, model_params, values_dict)
        model_gen.plot(types=[ParameterType.VSH], ax=ax)
    plt.show()