Ejemplo n.º 1
0
def classical(sources, src_filter, gsims, monitor):
    """
    :param sources:
        a non-empty sequence of sources of homogeneous tectonic region type
    :param src_filter:
        source filter
    :param gsims:
        a list of GSIMs for the current tectonic region type
    :param monitor:
        a monitor instance
    :returns:
        an AccumDict rlz -> curves
    """
    truncation_level = monitor.truncation_level
    imtls = monitor.imtls
    src_group_id = sources[0].src_group_id
    # sanity check: the src_group must be the same for all sources
    for src in sources[1:]:
        assert src.src_group_id == src_group_id
    if monitor.disagg:
        sm_id = monitor.sm_id
        bbs = [BoundingBox(sm_id, sid) for sid in src_filter.sitecol.sids]
    else:
        bbs = []
    pmap = pmap_from_grp(
        sources, src_filter, imtls, gsims, truncation_level,
        bbs=bbs, monitor=monitor)
    pmap.bbs = bbs
    pmap.grp_id = src_group_id
    return pmap
Ejemplo n.º 2
0
def ucerf_classical_hazard_by_branch(branchnames, ucerf_source, src_group_id,
                                     src_filter, gsims, monitor):
    """
    :param branchnames:
        a list of branch names
    :param ucerf_source:
        a source-like object for the UCERF model
    :param src_group_id:
        an ordinal number for the source
    :param source filter:
        a filter returning the sites affected by the source
    :param gsims:
        a list of GSIMs
    :param monitor:
        a monitor instance
    :returns:
        an AccumDict rlz -> curves
    """
    truncation_level = monitor.oqparam.truncation_level
    imtls = monitor.oqparam.imtls
    trt = ucerf_source.tectonic_region_type
    max_dist = monitor.oqparam.maximum_distance[trt]
    dic = AccumDict()
    dic.bbs = []
    dic.calc_times = []
    for branchname in branchnames:
        # Two step process here - the first generates the hazard curves from
        # the rupture sets
        monitor.eff_ruptures = 0
        # Apply the initial rupture to site filtering
        rupset_idx = ucerf_source.get_rupture_indices(branchname)
        rupset_idx, s_sites = \
            ucerf_source.filter_sites_by_distance_from_rupture_set(
                rupset_idx, src_filter.sitecol, max_dist)

        if len(s_sites):
            dic[src_group_id] = hazard_curves_per_rupture_subset(
                rupset_idx, ucerf_source, src_filter, imtls, gsims,
                truncation_level, bbs=dic.bbs, monitor=monitor)

        else:
            dic[src_group_id] = ProbabilityMap(len(imtls.array), len(gsims))
        dic.calc_times += monitor.calc_times  # added by pmap_from_grp
        dic.eff_ruptures = {src_group_id: monitor.eff_ruptures}  # idem
        logging.info('Branch %s', branchname)
        # Get the background point sources
        background_sids = ucerf_source.get_background_sids(
            src_filter.sitecol, max_dist)
        bckgnd_sources = ucerf_source.get_background_sources(background_sids)
        if bckgnd_sources:
            pmap = pmap_from_grp(
                bckgnd_sources, src_filter, imtls, gsims, truncation_level,
                bbs=dic.bbs, monitor=monitor)
            dic[src_group_id] |= pmap
            dic.eff_ruptures[src_group_id] += monitor.eff_ruptures
            dic.calc_times += monitor.calc_times
    return dic
Ejemplo n.º 3
0
 def test_mutually_exclusive_ruptures(self):
     # Test the calculation of hazard curves using mutually exclusive
     # ruptures for a single source
     gsim_by_trt = [SadighEtAl1997()]
     rupture = _create_rupture(10., 6.)
     data = [(rupture, PMF([(0.7, 0), (0.3, 1)])),
             (rupture, PMF([(0.6, 0), (0.4, 1)]))]
     src = NonParametricSeismicSource('0', 'test', TRT.ACTIVE_SHALLOW_CRUST,
                                      data)
     group = SourceGroup([src], 'test', 'indep', 'mutex')
     crv = pmap_from_grp(group, self.sites, self.imtls,
                         gsim_by_trt, truncation_level=None)[0]
     npt.assert_almost_equal(numpy.array([0.35000, 0.32497, 0.10398]),
                             crv.array[:, 0], decimal=4)
Ejemplo n.º 4
0
 def test_mutually_exclusive_ruptures(self):
     # Test the calculation of hazard curves using mutually exclusive
     # ruptures for a single source
     gsim_by_trt = [SadighEtAl1997()]
     rupture = _create_rupture(10., 6.)
     data = [(rupture, PMF([(0.7, 0), (0.3, 1)])),
             (rupture, PMF([(0.6, 0), (0.4, 1)]))]
     src = NonParametricSeismicSource('0', 'test', TRT.ACTIVE_SHALLOW_CRUST,
                                      data)
     group = SourceGroup(
         src.tectonic_region_type, [src], 'test', 'indep', 'mutex')
     param = dict(imtls=self.imtls)
     crv = pmap_from_grp(group, self.sites, gsim_by_trt, param)[0]
     npt.assert_almost_equal(numpy.array([0.35000, 0.32497, 0.10398]),
                             crv.array[:, 0], decimal=4)
Ejemplo n.º 5
0
def classical(sources, src_filter, gsims, param, monitor):
    """
    :param sources:
        a list of independent sources or a SourceGroup with mutex sources
    :param src_filter:
        a SourceFilter instance
    :param gsims:
        a list of GSIMs
    :param param:
        a dictionary with parameters imtls and truncation_level
    :param monitor:
        a Monitor instance
    :returns: a dictionary grp_id -> ProbabilityMap
    """
    if getattr(sources, 'src_interdep', None) == 'mutex':
        return pmap_from_grp(sources, src_filter, gsims, param, monitor)
    else:
        return pmap_from_trt(sources, src_filter, gsims, param, monitor)
Ejemplo n.º 6
0
def classical(sources, sitecol, gsims, monitor):
    """
    :param sources:
        a non-empty sequence of sources of homogeneous tectonic region type
    :param sitecol:
        a SiteCollection instance
    :param gsims:
        a list of GSIMs for the current tectonic region type
    :param monitor:
        a monitor instance
    :returns:
        an AccumDict rlz -> curves
    """
    truncation_level = monitor.truncation_level
    imtls = monitor.imtls
    src_group_id = sources[0].src_group_id
    # sanity check: the src_group must be the same for all sources
    for src in sources[1:]:
        assert src.src_group_id == src_group_id
    trt = sources[0].tectonic_region_type
    max_dist = monitor.maximum_distance[trt]

    dic = AccumDict()
    if monitor.poes_disagg:
        sm_id = monitor.sm_id
        dic.bbs = [BoundingBox(sm_id, sid) for sid in sitecol.sids]
    else:
        dic.bbs = []
    # NB: the source_site_filter below is ESSENTIAL for performance inside
    # pmap_from_grp, since it reduces the full site collection
    # to a filtered one *before* doing the rupture filtering
    dic[src_group_id] = pmap_from_grp(
        sources, sitecol, imtls, gsims, truncation_level,
        maximum_distance=max_dist, bbs=dic.bbs, monitor=monitor)
    dic.calc_times = monitor.calc_times  # added by pmap_from_grp
    dic.eff_ruptures = {src_group_id: monitor.eff_ruptures}  # idem
    return dic
Ejemplo n.º 7
0
def classical(sources, src_filter, gsims, param, monitor):
    """
    :param sources:
        a non-empty sequence of sources of homogeneous tectonic region type
    :param src_filter:
        source filter
    :param gsims:
        a list of GSIMs for the current tectonic region type
    :param param:
        a dictionary of parameters
    :param monitor:
        a monitor instance
    :returns:
        an AccumDict rlz -> curves
    """
    truncation_level = monitor.truncation_level
    imtls = monitor.imtls
    src_group_id = sources[0].src_group_id
    # sanity check: the src_group must be the same for all sources
    for src in sources[1:]:
        assert src.src_group_id == src_group_id
    if monitor.disagg:
        sm_id = monitor.sm_id
        bbs = [BoundingBox(sm_id, sid) for sid in src_filter.sitecol.sids]
    else:
        bbs = []
    pmap = pmap_from_grp(sources,
                         src_filter,
                         imtls,
                         gsims,
                         truncation_level,
                         bbs=bbs,
                         monitor=monitor)
    pmap.bbs = bbs
    pmap.grp_id = src_group_id
    return pmap