Exemplo n.º 1
0
def extract_disagg_layer(dstore, what):
    """
    Extract a disaggregation layer containing all sites and outputs
    Example:
    http://127.0.0.1:8800/v1/calc/30/extract/disagg_layer?
    """
    qdict = parse(what)
    oq = dstore['oqparam']
    oq.maximum_distance = filters.MagDepDistance(oq.maximum_distance)
    if 'kind' in qdict:
        kinds = qdict['kind']
    else:
        kinds = oq.disagg_outputs
    sitecol = dstore['sitecol']
    poes_disagg = oq.poes_disagg or (None, )
    edges, shapedic = disagg.get_edges_shapedic(oq, sitecol,
                                                dstore['source_mags'])
    dt = _disagg_output_dt(shapedic, kinds, oq.imtls, poes_disagg)
    out = numpy.zeros(len(sitecol), dt)
    realizations = numpy.array(dstore['full_lt'].get_realizations())
    hmap4 = dstore['hmap4'][:]
    best_rlzs = dstore['best_rlzs'][:]
    arr = {kind: dstore['disagg/' + kind][:] for kind in kinds}
    for sid, lon, lat, rec in zip(sitecol.sids, sitecol.lons, sitecol.lats,
                                  out):
        rlzs = realizations[best_rlzs[sid]]
        rec['site_id'] = sid
        rec['lon'] = lon
        rec['lat'] = lat
        rec['lon_bins'] = edges[2][sid]
        rec['lat_bins'] = edges[3][sid]
        for m, imt in enumerate(oq.imtls):
            ws = numpy.array([rlz.weight[imt] for rlz in rlzs])
            ws /= ws.sum()  # normalize to 1
            for p, poe in enumerate(poes_disagg):
                for kind in kinds:
                    key = '%s-%s-%s' % (kind, imt, poe)
                    rec[key] = arr[kind][sid, m, p] @ ws
                rec['iml-%s-%s' % (imt, poe)] = hmap4[sid, m, p]
    return ArrayWrapper(
        out,
        dict(mag=edges[0],
             dist=edges[1],
             eps=edges[-2],
             trt=numpy.array(encode(edges[-1]))))
Exemplo n.º 2
0
 def __init__(self, rupgetter, srcfilter, oqparam, amplifier=None,
              sec_perils=()):
     self.rlzs_by_gsim = rupgetter.rlzs_by_gsim
     self.rupgetter = rupgetter
     self.srcfilter = srcfilter
     self.sitecol = srcfilter.sitecol.complete
     self.oqparam = oqparam
     self.amplifier = amplifier
     self.sec_perils = sec_perils
     self.min_iml = oqparam.min_iml
     self.N = len(self.sitecol)
     self.num_rlzs = sum(len(rlzs) for rlzs in self.rlzs_by_gsim.values())
     self.sig_eps_dt = sig_eps_dt(oqparam.imtls)
     md = (filters.MagDepDistance(oqparam.maximum_distance)
           if isinstance(oqparam.maximum_distance, dict)
           else oqparam.maximum_distance)
     param = {'imtls': oqparam.imtls, 'maximum_distance': md}
     self.cmaker = ContextMaker(
         rupgetter.trt, rupgetter.rlzs_by_gsim, param)
     self.correl_model = oqparam.correl_model