Exemple #1
0
def make_hmap_array(pmap, imtls, poes, nsites):
    """
    :returns: a compound array of hazard maps of shape nsites
    """
    hmap = make_hmap(pmap, imtls, poes)
    pdic = general.DictArray({imt: poes for imt in imtls})
    return convert_to_array(hmap, nsites, pdic)
Exemple #2
0
def plot(calc_id, other_id=None, sites='0', imti='all'):
    """
    Hazard curves plotter.
    """
    # read the hazard data
    haz = util.read(calc_id)
    other = util.read(other_id) if other_id else None
    oq = haz['oqparam']
    if imti == 'all':
        imtls = oq.imtls
    else:
        imti = int(imti)
        imt = list(oq.imtls)[imti]
        imls = oq.imtls[imt]
        imtls = general.DictArray({imt: imls})
    indices = numpy.array(list(map(int, sites.split(','))))
    n_sites = len(haz['sitecol'])
    if not set(indices) <= set(range(n_sites)):
        invalid = sorted(set(indices) - set(range(n_sites)))
        print('The indices %s are invalid: no graph for them' % invalid)
    valid = sorted(set(range(n_sites)) & set(indices))
    print('Found %d site(s); plotting %d of them' % (n_sites, len(valid)))
    if other is None:
        mean_curves, others = get_hcurves(haz)
        plt = make_figure(valid, n_sites, imtls, mean_curves, others, 'mean')
    else:
        mean1, _ = get_hcurves(haz)
        mean2, _ = get_hcurves(other)
        plt = make_figure(valid, n_sites, imtls, mean1, [mean2], 'reference')
    plt.show()
Exemple #3
0
def make_hmap_array(pmap, imtls, poes, nsites):
    """
    :returns: a compound array of hazard maps of shape nsites
    """
    if isinstance(pmap, probability_map.ProbabilityMap):
        # this is here for compatibility with the
        # past, it could be removed in the future
        hmap = make_hmap(pmap, imtls, poes)
        pdic = general.DictArray({imt: poes for imt in imtls})
        return convert_to_array(hmap, nsites, pdic)
    try:
        hcurves = pmap.value
    except AttributeError:
        hcurves = pmap
    dtlist = [('%s-%s' % (imt, poe), F32) for imt in imtls for poe in poes]
    array = numpy.zeros(len(pmap), dtlist)
    for imt, imls in imtls.items():
        curves = hcurves[:, imtls(imt)]
        for poe in poes:
            array['%s-%s' % (imt, poe)] = compute_hazard_maps(
                curves, imls, poe).flat
    return array  # array of shape N