コード例 #1
0
ファイル: rates.py プロジェクト: ftbernales/oq-mbtk
def xml_vs_mfd(source_id, source_model_fname, model_id,
               oqmbt_project_fname):
    """
    :param str source_id:
        The ID of the source to be analysed
    :param str source_model_fname:
        The name of the xml shapefile
    :param str model_id:
        The model ID
    """
    #
    # read the source_model
    src_model, info = read(source_model_fname)
    #
    # compute total mfd sources
    tmfd = get_total_mfd(src_model)
    #
    # read project
    oqtkp = OQtProject.load_from_file(oqmbt_project_fname)
    model_id = oqtkp.active_model_id
    model = oqtkp.models[model_id]
    #
    # get source mfd
    src = model.sources[source_id]
    mfd = src.mfd
    if isinstance(src.mfd, TruncatedGRMFD):
        mfd = get_evenlyDiscretizedMFD_from_truncatedGRMFD(mfd)
    #
    # compute total mfd sources
    plt.figure(figsize=(10, 8))
    plot_mfd_cumulative(tmfd)
    plot_mfd_cumulative(mfd, title=source_model_fname)
コード例 #2
0
ファイル: mfd.py プロジェクト: ftbernales/oq-mbtk
def get_total_mfd(sources, trt=None):
    """
    :param list sources:
        A list of :class:`openquake.hazardlib.source.Source` instances
    :returns:
        A :class:`openquake.man.checks.mfd.EEvenlyDiscretizedMFD` instance
    """
    #
    #
    mfdall = mfdt.EEvenlyDiscretizedMFD(5.1, 0.1, [1e-20])
    for src in sources:
        if ((trt is not None and trt == src.tectonic_region_type)
                or (trt is None)):
            mfd = src.mfd
            if isinstance(src.mfd, TruncatedGRMFD):
                mfd = mfdt.get_evenlyDiscretizedMFD_from_truncatedGRMFD(mfd)
            mfdall.stack(mfd)
    return mfdall
コード例 #3
0
def check_mfds(fname_input_pattern: str, fname_config: str):

    for fname in sorted(glob(fname_input_pattern)):

        src_id = _get_src_id(fname)
        model = toml.load(fname_config)

        binw = 0.1
        sourceconv = SourceConverter(investigation_time=1.0,
                                     rupture_mesh_spacing=5.0,
                                     complex_fault_mesh_spacing=5.0,
                                     width_of_mfd_bin=binw)
        ssm = to_python(fname, sourceconv)

        for grp in ssm:
            
            for i, src in enumerate(grp):
                if i == 0:
                    nmfd = EEvenlyDiscretizedMFD.from_mfd(src.mfd, binw)
                else:
                    tmfd = get_evenlyDiscretizedMFD_from_truncatedGRMFD(src.mfd, nmfd.bin_width)
                    nmfd.stack(tmfd)

            occ = np.array(nmfd.get_annual_occurrence_rates())

            bgr = model["sources"][src_id]["bgr_weichert"]
            agr = model["sources"][src_id]["agr_weichert"]

            tmp = occ[:,0] - binw
            mfd = 10.0**(agr-bgr*tmp[:-1])-10.0**(agr-bgr*(tmp[:-1]+binw))
            
            fig = plt.figure(figsize=(8, 6))
            plt.plot(occ[:, 0], occ[:, 1], 'o')
            plt.plot(tmp[:-1]+binw/2, mfd, 'x')
            print(mfd)
            plt.title(fname) 
            plt.xlabel('Magnitude')
            plt.ylabel('Annual occurrence rate')
            plt.yscale('log')

            plt.show()