Пример #1
0
def export_hmaps_xml_json(ekey, dstore):
    key, kind, fmt = get_kkf(ekey)
    oq = dstore['oqparam']
    sitecol = dstore['sitecol']
    sitemesh = get_mesh(sitecol)
    rlzs_assoc = dstore['csm_info'].get_rlzs_assoc()
    fnames = []
    writercls = hazard_writers.HazardMapXMLWriter
    nsites = len(sitemesh)
    for kind, hcurves in PmapGetter(dstore, rlzs_assoc).items():
        hmaps = calc.make_hmap_array(hcurves, oq.imtls, oq.poes, nsites)
        if kind.startswith('rlz-'):
            rlz = rlzs_assoc.realizations[int(kind[4:])]
            smlt_path = '_'.join(rlz.sm_lt_path)
            gsimlt_path = rlz.gsim_rlz.uid
        else:
            smlt_path = ''
            gsimlt_path = ''
        for imt in oq.imtls:
            for poe in oq.poes:
                suffix = '-%s-%s' % (poe, imt)
                fname = hazard_curve_name(
                    dstore, ekey, kind + suffix, rlzs_assoc)
                data = [HazardMap(site[0], site[1], hmap['%s-%s' % (imt, poe)])
                        for site, hmap in zip(sitemesh, hmaps)]
                writer = writercls(
                    fname, investigation_time=oq.investigation_time,
                    imt=imt, poe=poe,
                    smlt_path=smlt_path, gsimlt_path=gsimlt_path)
                writer.serialize(data)
                fnames.append(fname)
    return sorted(fnames)
Пример #2
0
 def save_hmaps(self):
     """
     Save hazard maps generated from the hazard curves
     """
     oq = self.oqparam
     if oq.poes:
         mon = self.monitor('computing hazard maps')
         logging.info('Computing hazard maps for PoEs=%s', oq.poes)
         with mon:
             N = len(self.sitecol.complete)
             ct = oq.concurrent_tasks or 1
             if 'hcurves' in self.datastore:
                 kinds = self.datastore['hcurves']
                 hmaps_dt = numpy.dtype(
                     [('%s-%s' % (imt, poe), F32)
                      for imt in oq.imtls for poe in oq.poes])
                 for kind in kinds:
                     self.datastore.create_dset(
                         'hmaps/' + kind, hmaps_dt, (N,), fillvalue=None)
                 allargs = []
                 for slc in general.split_in_slices(N, ct):
                     hcurves_by_kind = {
                         kind: self.datastore['hcurves/' + kind][slc]
                         for kind in kinds}
                     allargs.append((hcurves_by_kind, slc,
                                     oq.imtls, oq.poes, mon))
                 for dic, slc in Starmap(build_hmaps, allargs):
                     for kind, hmaps in dic.items():
                         self.datastore['hmaps/' + kind][slc] = hmaps
             else:  # single realization
                 pg = PmapGetter(self.datastore, self.rlzs_assoc)
                 self.datastore['hmaps/mean'] = calc.make_hmap_array(
                     pg.get_mean(), oq.imtls, oq.poes, N)
Пример #3
0
def build_hmaps(hcurves_by_kind, slice_, imtls, poes, monitor):
    """
    Build hazard maps from a slice of hazard curves.
    :returns: a pair ({kind: hmaps}, slice)
    """
    dic = {}
    for kind, hcurves in hcurves_by_kind.items():
        dic[kind] = calc.make_hmap_array(hcurves, imtls, poes, len(hcurves))
    return dic, slice_
Пример #4
0
def build_hmaps(hcurves_by_kind, slice_, imtls, poes, monitor):
    """
    Build hazard maps from a slice of hazard curves.
    :returns: a pair ({kind: hmaps}, slice)
    """
    dic = {}
    for kind, hcurves in hcurves_by_kind.items():
        dic[kind] = calc.make_hmap_array(hcurves, imtls, poes, len(hcurves))
    return dic, slice_
Пример #5
0
 def save_hmaps(self):
     """
     Save hazard maps generated from the hazard curves
     """
     oq = self.oqparam
     if oq.poes:
         logging.info('Computing hazard maps for PoEs=%s', oq.poes)
         with self.monitor('computing hazard maps',
                           autoflush=True, measuremem=True):
             N = len(self.sitecol.complete)
             if 'hcurves' in self.datastore:
                 # TODO: we could parallelize this branch
                 for kind in self.datastore['hcurves']:
                     self.datastore['hmaps/' + kind] = calc.make_hmap_array(
                         self.datastore['hcurves/' + kind],
                         oq.imtls, oq.poes, N)
             else:  # single realization
                 pg = PmapGetter(self.datastore, self.rlzs_assoc)
                 self.datastore['hmaps/mean'] = calc.make_hmap_array(
                     pg.get_mean(), oq.imtls, oq.poes, N)
Пример #6
0
def view_hmap(token, dstore):
    """
    Display the highest 20 points of the mean hazard map. Called as
    $ oq show hmap:0.1  # 10% PoE
    """
    try:
        poe = valid.probability(token.split(':')[1])
    except IndexError:
        poe = 0.1
    mean = dict(extract(dstore, 'hcurves?kind=mean'))['mean']
    oq = dstore['oqparam']
    hmap = calc.make_hmap_array(mean, oq.imtls, [poe], len(mean))
    dt = numpy.dtype([('sid', U32)] + [(imt, F32) for imt in oq.imtls])
    array = numpy.zeros(len(hmap), dt)
    for i, vals in enumerate(hmap):
        array[i] = (i, ) + tuple(vals)
    array.sort(order=list(oq.imtls)[0])
    return rst_table(array[:20])
Пример #7
0
def view_hmap(token, dstore):
    """
    Display the highest 20 points of the mean hazard map. Called as
    $ oq show hmap:0.1  # 10% PoE
    """
    try:
        poe = valid.probability(token.split(':')[1])
    except IndexError:
        poe = 0.1
    mean = dict(extract(dstore, 'hcurves?kind=mean'))['mean']
    oq = dstore['oqparam']
    hmap = calc.make_hmap_array(mean, oq.imtls, [poe], len(mean))
    dt = numpy.dtype([('sid', U32)] + [(imt, F32) for imt in oq.imtls])
    array = numpy.zeros(len(hmap), dt)
    for i, vals in enumerate(hmap):
        array[i] = (i, ) + tuple(vals)
    array.sort(order=list(oq.imtls)[0])
    return rst_table(array[:20])
Пример #8
0
def extract_uhs(dstore, what):
    """
    Extracts uniform hazard spectra. Use it as /extract/uhs/mean or
    /extract/uhs/rlz-0, etc
    """
    oq = dstore['oqparam']
    imts = oq.imt_periods()
    mesh = get_mesh(dstore['sitecol'])
    rlzs_assoc = dstore['csm_info'].get_rlzs_assoc()
    dic = {}
    imts_dt = numpy.dtype([(str(imt), F32) for imt in imts])
    uhs_dt = numpy.dtype([(str(poe), imts_dt) for poe in oq.poes])
    for name, hcurves in getters.PmapGetter(dstore, rlzs_assoc).items(what):
        hmap = calc.make_hmap_array(hcurves, oq.imtls, oq.poes, len(mesh))
        uhs = numpy.zeros(len(hmap), uhs_dt)
        for field in hmap.dtype.names:
            imt, poe = field.split('-')
            if imt in imts_dt.names:
                uhs[poe][imt] = hmap[field]
        dic[name] = uhs
    return hazard_items(dic, mesh, investigation_time=oq.investigation_time)