コード例 #1
0
ファイル: inversion_chen_new.py プロジェクト: wyeck-usgs/WASP
def execute_plot(tensor_info,
                 data_type,
                 segments_data,
                 default_dirs,
                 velmodel=None,
                 plot_input=False):
    """We plot modelling results
    
    :param tensor_info: dictionary with moment tensor properties
    :param data_type: set with data types to be used in modelling
    :param plot_input: choose whether to plot initial kinematic model as well
    :param default_dirs: dictionary with default directories to be used
    :param velmodel: dictionary with velocity model
    :type velmodel: dict, optional
    :type default_dirs: dict
    :type tensor_info: dict
    :type data_type: set
    :type plot_input: bool, optional
    """
    print('Plot results')
    segments = segments_data['segments']
    rise_time = segments_data['rise_time']
    solution = get_outputs.read_solution_static_format(segments)
    if not velmodel:
        velmodel = mv.select_velmodel(tensor_info, default_dirs)
    point_sources = pf.point_sources_param(segments, tensor_info, rise_time)
    shear = pf.shear_modulous(point_sources, velmodel=velmodel)
    plot.plot_ffm_sol(tensor_info, segments_data, point_sources, shear,
                      solution, velmodel, default_dirs)
    plot.plot_misfit(data_type)
    # plot.plot_beachballs(tensor_info, segments, data_type)
    traces_info, stations_gps = [None, None]
    if 'strong_motion' in data_type:
        traces_info = json.load(open('strong_motion_waves.json'))
    if 'gps' in data_type:
        names, lats, lons, observed, synthetic, error = get_outputs.retrieve_gps(
        )
        stations_gps = zip(names, lats, lons, observed, synthetic, error)
    if 'strong_motion' in data_type or 'gps' in data_type:
        plot._PlotMap(tensor_info,
                      segments,
                      point_sources,
                      solution,
                      default_dirs,
                      files_str=traces_info,
                      stations_gps=stations_gps)
    if plot_input:
        input_model = load_ffm_model(segments_data, option='Fault.time')
        plot._PlotSlipDist_Compare(segments, point_sources, input_model,
                                   solution)
        plot._PlotComparisonMap(tensor_info, segments, point_sources,
                                input_model, solution)
コード例 #2
0
ファイル: inversion_chen_new.py プロジェクト: wyeck-usgs/WASP
def _automatic2(tensor_info,
                plane_data,
                data_type,
                data_prop,
                default_dirs,
                logger,
                velmodel=None):
    """Routine for automatic FFM modelling for each nodal plane
    
    :param tensor_info: dictionary with moment tensor properties
    :param plane_data: dictionary with fault plane mechanism
    :param data_type: list with data types to be used in modelling
    :param default_dirs: dictionary with default directories to be used
    :param data_prop: dictionary with properties for different waveform types
    :param velmodel: dictionary with velocity model
    :type default_dirs: dict
    :type tensor_info: dict
    :type plane_data: dict
    :type data_type: list
    :type data_prop: dict
    :type velmodel: dict, optional
    """
    #
    # Create JSON files
    #
    logger.info('Create input files for Fortran scripts')
    logger.info('Create automatic JSON')
    tensor.write_tensor(tensor_info)
    if velmodel:
        mv.velmodel2json(velmodel)
    if not velmodel:
        velmodel = mv.select_velmodel(tensor_info, default_dirs)
    np_plane_info = plane_data['plane_info']
    data_folder = os.path.join('..', 'data')
    dm.filling_data_dicts(tensor_info, data_type, data_prop, data_folder)
    segments_data = pf.create_finite_fault(tensor_info, np_plane_info,
                                           data_type)
    segments = segments_data['segments']
    rise_time = segments_data['rise_time']
    mp.modelling_prop(tensor_info, segments_data, data_type=data_type)
    #
    # write text files from JSONs
    #
    rupt_vel = segments[0]['rupture_vel']
    lambda_min = 0.4
    lambda_max = 1.25
    min_vel, max_vel = [lambda_min * rupt_vel, lambda_max * rupt_vel]
    logger.info('Write input files')
    writing_inputs(tensor_info, data_type, segments_data, min_vel, max_vel)
    #
    # Modelling and plotting results
    #
    inversion(tensor_info, data_type, default_dirs, logger)
    logger.info('Plot data in folder {}'.format(os.getcwd()))
    execute_plot(tensor_info,
                 data_type,
                 segments_data,
                 default_dirs,
                 velmodel=velmodel)
    base = os.path.basename(os.getcwd())
    dirname = os.path.abspath(os.getcwd())
    #
    # write solution in FSP format
    #
    # segments, rise_time, point_sources = pl_mng.__read_planes_info()
    solution = get_outputs.read_solution_static_format(segments)
    static_to_fsp(tensor_info, segments_data, data_type, velmodel, solution)
    for file in glob.glob('*png'):
        if os.path.isfile(os.path.join(dirname, base, file)):
            copy2(os.path.join(dirname, base, file),
                  os.path.join(dirname, 'plots'))
コード例 #3
0
                        action="store_true",
                        help="use strong motion data in modelling")
    parser.add_argument("--cgps",
                        action="store_true",
                        help="use cGPS data in modelling")
    parser.add_argument("--gps",
                        action="store_true",
                        help="use GPS data in modelling")
    args = parser.parse_args()
    os.chdir(args.folder)
    used_data = []
    used_data = used_data + ['gps'] if args.gps else used_data
    used_data = used_data + ['strong_motion'] if args.strong else used_data
    used_data = used_data + ['cgps'] if args.cgps else used_data
    used_data = used_data + ['tele_body'] if args.tele else used_data
    used_data = used_data + ['surf_tele'] if args.surface else used_data
    if args.gcmt_tensor:
        cmt_file = args.gcmt_tensor
        tensor_info = tensor.get_tensor(cmt_file=cmt_file)
    else:
        tensor_info = tensor.get_tensor()
    segments_data, rise_time, point_sources = pl_mng.__read_planes_info()
    if not os.path.isfile('static_data.json'):
        raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT),
                                'velmodel_data.json')
    vel_model = json.load(open('velmodel_data.json'))
    solution = get_outputs.read_solution_static_format(segments_data,
                                                       point_sources)
    static_to_fsp(tensor_info, segments_data, rise_time, point_sources,
                  used_data, vel_model, solution)
コード例 #4
0
ファイル: load_ffm_model.py プロジェクト: gferragu/WASP
def load_ffm_model(option='Solucion.txt', max_slip=1000, len_stk=4, len_dip=4):
    """Load FFM model from some input file.

    :param option: file from where to load the input kinematic model
    :param max_slip: largest slip of kinematic model, when creating custom
     kinematic model
    :param len_stk: length of patches when creating checkerboard model
    :param len_dip: width of patches when creating checkerboard model
    :type option: string, optional
    :type max_slip: float, optional
    :type len_stk: int, optional
    :type len_dip: int, optional
    """
    from random import randint
    segments, rise_time, point_sources = pl_mng.__read_planes_info()

    slip = []
    rake = []
    trup = []
    trise = []
    tfall = []

    if option == 'Solucion.txt':
        solution = get_outputs.read_solution_static_format(segments)
        slip = solution['slip']
        rake = solution['rake']
        trup = solution['rupture_time']
        trise = solution['trise']
        tfall = solution['tfall']

    with open('Fault.time', 'r') as input_file:
        jk = [line.split() for line in input_file]

    faults_data = [index + 4 for index, (line0, line1)\
                   in enumerate(zip(jk[3:-1], jk[4:])) if len(line0) <= 3\
                   and len(line1) >= 5]
    headers = [index + 4 for index, (line0, line1)\
               in enumerate(zip(jk[3:-1], jk[4:])) if len(line0) >= 5\
               and len(line1) <= 3]
    headers = headers[:] + [len(jk)]
    if option == 'Fault.time':
        for segment, point_source_seg, start, end\
        in zip(segments, point_sources, faults_data, headers):
#
# load FFM input model
#
            slip_fault = np.array([float(line[0]) for line in jk[start:end]])
            rake_fault = np.array([float(line[1]) for line in jk[start:end]])
            trup_fault = np.array([float(line[2]) for line in jk[start:end]])
            trise_fault = np.array([float(line[3]) for line in jk[start:end]])
            tfall_fault = np.array([float(line[4]) for line in jk[start:end]])
            n_sub_stk, n_sub_dip, delta_x, delta_y, hyp_stk, hyp_dip\
                = pl_mng.__unpack_plane_data(segment)
#
# Reshape the rupture process
#
            slip_fault.shape = n_sub_dip, n_sub_stk
            rake_fault.shape = n_sub_dip, n_sub_stk
            trup_fault.shape = n_sub_dip, n_sub_stk
            trise_fault.shape = n_sub_dip, n_sub_stk
            tfall_fault.shape = n_sub_dip, n_sub_stk
            slip = slip + [slip_fault]
            rake = rake + [rake_fault]
            trup = trup + [trup_fault]
            trise = trise + [trise_fault]
            tfall = tfall + [tfall_fault]

    if option == 'point_source':
        ta0 = rise_time['ta0']
        for i_segment, (segment, point_source_seg, start, end)\
        in enumerate(zip(segments, point_sources, faults_data, headers)):
            rake_value = segment['rake']
            a, b, c, d, e = point_sources[0].shape
            ny = int(c / 2)
            nx = int(d / 2)
#
# load FFM input model
#
            slip_fault = np.array([float(line[0]) for line in jk[start:end]])
            rake_fault = np.array([rake_value for line in jk[start:end]])
            trup_fault = point_source_seg[:, :, ny, nx, 4]
            trise_fault = np.array([ta0 for line in jk[start:end]])
            tfall_fault = np.array([ta0 for line in jk[start:end]])
            n_sub_stk, n_sub_dip, delta_x, delta_y, hyp_stk, hyp_dip\
                = pl_mng.__unpack_plane_data(segment)
#
# Reshape the rupture process
#
            slip_fault.shape = n_sub_dip, n_sub_stk
            for ny in range(n_sub_dip):
                for nx in range(n_sub_stk):
                    if nx == len_stk and ny == len_dip and i_segment == 0:
                        slip_fault[ny, nx] = max_slip
                    else:
                        slip_fault[ny, nx] = 0
            rake_fault.shape = n_sub_dip, n_sub_stk
            trup_fault.shape = n_sub_dip, n_sub_stk
            trise_fault.shape = n_sub_dip, n_sub_stk
            tfall_fault.shape = n_sub_dip, n_sub_stk
            slip = slip + [slip_fault]
            rake = rake + [rake_fault]
            trup = trup + [trup_fault]
            trise = trise + [trise_fault]
            tfall = tfall + [tfall_fault]


    if option == 'Checkerboard':
        ta0 = rise_time['ta0']
        i = 0
        for segment, point_source_seg, start, end\
        in zip(segments, point_sources, faults_data, headers):
            rake_value = segment['rake']
            a, b, c, d, e = point_sources[0].shape
            ny = int(c / 2)
            nx = int(d / 2)
#
# load FFM input model
#
            slip_fault = np.array([float(line[0]) for line in jk[start:end]])
            rake_fault = np.array([rake_value for line in jk[start:end]])
            trup_fault = point_source_seg[:, :, ny, nx, 4]
            trise_fault = np.array([ta0 for line in jk[start:end]])
            tfall_fault = np.array([ta0 for line in jk[start:end]])
            n_sub_stk, n_sub_dip, delta_x, delta_y, hyp_stk, hyp_dip\
                = pl_mng.__unpack_plane_data(segment)
#
# Reshape the rupture process
#
            slip_fault.shape = n_sub_dip, n_sub_stk
            len_stk = len_stk if len_stk < 0.5 * n_sub_stk else int(0.45 * n_sub_stk)
            len_dip = len_dip if len_dip < 0.5 * n_sub_dip else int(0.45 * n_sub_dip)
            for ny in range(n_sub_dip):
                for nx in range(n_sub_stk):
                    if (int(nx // len_stk) + int(ny // len_dip) + i) % 2 == 0:
                        slip_fault[ny, nx] = 0
                    else:
                        slip_fault[ny, nx] = max_slip
            rake_fault.shape = n_sub_dip, n_sub_stk
            trup_fault.shape = n_sub_dip, n_sub_stk
            trise_fault.shape = n_sub_dip, n_sub_stk
            tfall_fault.shape = n_sub_dip, n_sub_stk
            slip = slip + [slip_fault]
            rake = rake + [rake_fault]
            trup = trup + [trup_fault]
            trise = trise + [trise_fault]
            tfall = tfall + [tfall_fault]
            i = i + 1


    if option == 'Patches':
        ta0 = rise_time['ta0']
        for i_segment, (segment, point_source_seg, start, end)\
        in enumerate(zip(segments, point_sources, faults_data, headers)):
            rake_value = segment['rake']
            a, b, c, d, e = point_sources[0].shape
            ny = int(c / 2)
            nx = int(d / 2)
#
# load FFM input model
#
            n_sub_stk, n_sub_dip, delta_x, delta_y, hyp_stk, hyp_dip\
                = pl_mng.__unpack_plane_data(segment)
            slip_fault = np.array([0 for line in jk[start:end]])
            rake_fault = rake_value + 2 * np.random.randn(end - start)#2
            trup_fault = point_source_seg[:, :, ny, nx, 4]\
                * (np.ones((n_sub_dip, n_sub_stk))\
                + 0.2 * np.random.randn(n_sub_dip, n_sub_stk))
            trup_fault = np.maximum(trup_fault, 0)
            trise_fault = np.array([2 * ta0 for line in jk[start:end]])
            tfall_fault = np.array([2 * ta0 for line in jk[start:end]])

#
# Reshape the rupture process
#
            slip_fault.shape = n_sub_dip, n_sub_stk
            patches = 1#randint(3, 5)

            for patch in range(patches):
                n_sub_xc = randint(0, n_sub_stk - 1)
                n_sub_yc = 0#randint(0, 2)#n_sub_dip - 1)
#                if patch == 0:
#                    n_sub_xc = hyp_stk - 1#randint(0, 2)
#                    n_sub_yc = hyp_dip - 1#randint(4, 6)
#                if patch == 1:
#                    n_sub_xc = hyp_stk + 1#randint(n_sub_stk - 2, n_sub_stk)
#                    n_sub_yc = hyp_dip + 1#randint(4, 6)
                length = randint(3, 4)#length = 2
                for ny in range(n_sub_dip):
                    for nx in range(n_sub_stk):
                        dist = (n_sub_yc - ny) ** 2 + (n_sub_xc - nx) ** 2
                        if dist > length ** 2:
                            continue
                        slip_fault[ny, nx] = slip_fault[ny, nx]\
                        + max_slip * (length - np.sqrt(dist)) / length
            rake_fault.shape = n_sub_dip, n_sub_stk
            trup_fault.shape = n_sub_dip, n_sub_stk
            trise_fault.shape = n_sub_dip, n_sub_stk
            tfall_fault.shape = n_sub_dip, n_sub_stk
            slip = slip + [slip_fault]
            rake = rake + [rake_fault]
            trup = trup + [trup_fault]
            trise = trise + [trise_fault]
            tfall = tfall + [tfall_fault]

    model = {
            'slip': slip,
            'rake': rake,
            'trup': trup,
            'trise': trise,
            'tfall': tfall
    }
    return model
コード例 #5
0
ファイル: plot_graphic.py プロジェクト: wyeck-usgs/WASP
    args = parser.parse_args()
    os.chdir(args.folder)
    used_data = []
    used_data = used_data + ['strong_motion'] if args.strong else used_data
    used_data = used_data + ['cgps'] if args.cgps else used_data
    used_data = used_data + ['tele_body'] if args.tele else used_data
    used_data = used_data + ['surf_tele'] if args.surface else used_data
    default_dirs = mng.default_dirs()
    if args.gcmt_tensor:
        cmt_file = args.gcmt_tensor
        tensor_info = tensor.get_tensor(cmt_file=cmt_file)
    else:
        tensor_info = tensor.get_tensor()
    segments, rise_time, point_sources = pl_mng.__read_planes_info()
    if args.ffm_solution:
        solution = get_outputs.read_solution_static_format(segments)
        if not os.path.isfile('velmodel_data.json'):
            vel_model = mv.select_velmodel(tensor_info, default_dirs)
        else:
            vel_model = json.load(open('velmodel_data.json'))
        shear = pf.shear_modulous(point_sources, velmodel=vel_model)
        plot_ffm_sol(tensor_info, segments, point_sources, shear, solution,
                     vel_model, default_dirs)

    traces_info, stations_gps = [None, None]
    if args.gps:
        names, lats, lons, observed, synthetic, error\
                = get_outputs.retrieve_gps()
        stations_gps = zip(names, lats, lons, observed, synthetic, error)
    if args.strong:
        traces_info = json.load(open('strong_motion_waves.json'))