コード例 #1
0
ファイル: getters.py プロジェクト: jamesmarek/oq-engine
 def compute_gmfs_curves(self, monitor):
     """
     :returns: a dict with keys gmfdata, hcurves
     """
     oq = self.oqparam
     mon = monitor('getting ruptures', measuremem=True)
     hcurves = {}  # key -> poes
     if oq.hazard_curves_from_gmfs:
         hc_mon = monitor('building hazard curves', measuremem=False)
         gmfdata = self.get_gmfdata(mon)  # returned later
         hazard = self.get_hazard_by_sid(data=gmfdata)
         for sid, hazardr in hazard.items():
             dic = general.group_array(hazardr, 'rlz')
             for rlzi, array in dic.items():
                 with hc_mon:
                     poes = gmvs_to_poes(
                         array['gmv'].T, oq.imtls,
                         oq.ses_per_logic_tree_path)
                     for m, imt in enumerate(oq.imtls):
                         hcurves[rsi2str(rlzi, sid, imt)] = poes[m]
     if not oq.ground_motion_fields:
         return dict(gmfdata=(), hcurves=hcurves)
     if not oq.hazard_curves_from_gmfs:
         gmfdata = self.get_gmfdata(mon)
     if len(gmfdata) == 0:
         return dict(gmfdata=[])
     times = numpy.array([tup + (monitor.task_no,) for tup in self.times],
                         time_dt)
     times.sort(order='rup_id')
     res = dict(gmfdata=gmfdata, hcurves=hcurves, times=times,
                sig_eps=numpy.array(self.sig_eps, self.sig_eps_dt))
     return res
コード例 #2
0
ファイル: getters.py プロジェクト: pheresi/oq-engine
 def compute_gmfs_curves(self, monitor):
     """
     :returns: a dict with keys gmfdata, hcurves
     """
     oq = self.oqparam
     mon = monitor('getting ruptures', measuremem=True)
     hcurves = {}  # key -> poes
     if oq.hazard_curves_from_gmfs:
         hc_mon = monitor('building hazard curves', measuremem=False)
         gmfdata = self.get_gmfdata(mon)  # returned later
         if len(gmfdata) == 0:
             return dict(gmfdata=(), hcurves=hcurves)
         for (sid, rlz), df in gmfdata.groupby(['sid', 'rlz']):
             with hc_mon:
                 poes = calc.gmvs_to_poes(
                     df, oq.imtls, oq.ses_per_logic_tree_path)
                 for m, imt in enumerate(oq.imtls):
                     hcurves[rsi2str(rlz, sid, imt)] = poes[m]
     if not oq.ground_motion_fields:
         return dict(gmfdata=(), hcurves=hcurves)
     if not oq.hazard_curves_from_gmfs:
         gmfdata = self.get_gmfdata(mon)
     if len(gmfdata) == 0:
         return dict(gmfdata=[])
     times = numpy.array([tup + (monitor.task_no,) for tup in self.times],
                         time_dt)
     times.sort(order='rup_id')
     res = dict(gmfdata=strip_zeros(gmfdata), hcurves=hcurves, times=times,
                sig_eps=numpy.array(self.sig_eps, self.sig_eps_dt))
     return res
コード例 #3
0
def compute_gmfs_and_curves(getters, oq, monitor):
    """
    :param getters:
        a list of GmfGetter instances
    :param oq:
        an OqParam instance
    :param monitor:
        a Monitor instance
    :returns:
        a list of dictionaries with keys gmfcoll and hcurves
    """
    results = []
    for getter in getters:
        with monitor('GmfGetter.init', measuremem=True):
            getter.init()
        hcurves = {}  # key -> poes
        if oq.hazard_curves_from_gmfs:
            hc_mon = monitor('building hazard curves', measuremem=False)
            duration = oq.investigation_time * oq.ses_per_logic_tree_path
            with monitor('building hazard', measuremem=True):
                gmfdata = numpy.fromiter(getter.gen_gmv(), getter.gmf_data_dt)
                hazard = getter.get_hazard(data=gmfdata)
            for sid, hazardr in zip(getter.sids, hazard):
                for rlzi, array in hazardr.items():
                    if len(array) == 0:  # no data
                        continue
                    with hc_mon:
                        gmvs = array['gmv']
                        for imti, imt in enumerate(getter.imtls):
                            poes = calc._gmvs_to_haz_curve(
                                gmvs[:, imti], oq.imtls[imt],
                                oq.investigation_time, duration)
                            hcurves[rsi2str(rlzi, sid, imt)] = poes
        else:  # fast lane
            with monitor('building hazard', measuremem=True):
                gmfdata = numpy.fromiter(getter.gen_gmv(), getter.gmf_data_dt)
        indices = []
        if oq.ground_motion_fields:
            gmfdata.sort(order=('sid', 'rlzi', 'eid'))
            start = stop = 0
            for sid, rows in itertools.groupby(gmfdata['sid']):
                for row in rows:
                    stop += 1
                indices.append((sid, start, stop))
                start = stop
        else:
            gmfdata = None
        res = dict(gmfdata=gmfdata,
                   hcurves=hcurves,
                   gmdata=getter.gmdata,
                   taskno=monitor.task_no,
                   indices=numpy.array(indices, (U32, 3)))
        if len(getter.gmdata):
            results.append(res)
    return results
コード例 #4
0
def compute_gmfs_and_curves(getter, rlzs, monitor):
    """
    :param eb_ruptures:
        a list of blocks of EBRuptures of the same SESCollection
    :param sitecol:
        a :class:`openquake.hazardlib.site.SiteCollection` instance
    :param imts:
        a list of intensity measure type strings
    :param rlzs_by_gsim:
        a dictionary gsim -> associated realizations
    :param monitor:
        a Monitor instance
    :returns:
        a dictionary with keys gmfcoll and hcurves
   """
    oq = monitor.oqparam
    haz = {sid: {} for sid in getter.sids}
    gmfcoll = {}  # rlz -> gmfa
    for rlz in rlzs:
        gmfcoll[rlz] = []
        for sid, gmvdict in zip(getter.sids, getter(rlz)):
            if gmvdict:
                for imti, imt in enumerate(getter.imts):
                    if oq.hazard_curves_from_gmfs:
                        try:
                            gmv = gmvdict[imt]
                        except KeyError:
                            # no gmv for the given imt, this may happen
                            pass
                        else:
                            haz[sid][imt, rlz] = gmv
                    for rec in gmvdict.get(imt, []):
                        gmfcoll[rlz].append(
                            (sid, rec['eid'], imti, rec['gmv']))
    for rlz in gmfcoll:
        gmfcoll[rlz] = numpy.array(gmfcoll[rlz], gmv_dt)
    result = dict(gmfcoll=gmfcoll if oq.ground_motion_fields else None,
                  hcurves={})
    if oq.hazard_curves_from_gmfs:
        with monitor('building hazard curves', measuremem=False):
            duration = oq.investigation_time * oq.ses_per_logic_tree_path
            for sid, haz_by_imt_rlz in haz.items():
                for imt, rlz in haz_by_imt_rlz:
                    gmvs = haz_by_imt_rlz[imt, rlz]['gmv']
                    poes = calc._gmvs_to_haz_curve(
                        gmvs, oq.imtls[imt], oq.investigation_time, duration)
                    key = rsi2str(rlz.ordinal, sid, imt)
                    result['hcurves'][key] = poes
    return result
コード例 #5
0
ファイル: event_based.py プロジェクト: panagop/oq-engine
def compute_gmfs_and_curves(getter, oq, monitor):
    """
    :param getter:
        a GmfGetter instance
    :param oq:
        an OqParam instance
    :param monitor:
        a Monitor instance
    :returns:
        a dictionary with keys gmfcoll and hcurves
   """
    with monitor('making contexts', measuremem=True):
        getter.init()
    grp_id = getter.grp_id
    hcurves = {}  # key -> poes
    gmfcoll = {}  # grp_id, rlz -> gmfa
    if oq.hazard_curves_from_gmfs:
        hc_mon = monitor('building hazard curves', measuremem=False)
        duration = oq.investigation_time * oq.ses_per_logic_tree_path
        for gsim in getter.rlzs_by_gsim:
            with monitor('building hazard', measuremem=True):
                gmfcoll[grp_id,
                        gsim] = data = numpy.fromiter(getter.gen_gmv(gsim),
                                                      gmf_data_dt)
                hazard = getter.get_hazard(gsim, data)
            for r, rlz in enumerate(getter.rlzs_by_gsim[gsim]):
                hazardr = hazard[r]
                lst = []
                for sid in getter.sids:
                    for imti, imt in enumerate(getter.imts):
                        array = hazardr[sid, imti]
                        if len(array) == 0:  # no data
                            continue
                        for rec in array:
                            lst.append((sid, rec['eid'], imti, rec['gmv']))
                        with hc_mon:
                            poes = calc._gmvs_to_haz_curve(
                                array['gmv'], oq.imtls[imt],
                                oq.investigation_time, duration)
                            hcurves[rsi2str(rlz.ordinal, sid, imt)] = poes
    else:  # fast lane
        for gsim in getter.rlzs_by_gsim:
            with monitor('building hazard', measuremem=True):
                gmfcoll[grp_id, gsim] = numpy.fromiter(getter.gen_gmv(gsim),
                                                       gmf_data_dt)
    return dict(gmfcoll=gmfcoll if oq.ground_motion_fields else None,
                hcurves=hcurves,
                gmdata=getter.gmdata)
コード例 #6
0
 def compute_gmfs_curves(self, monitor):
     """
     :returns: a dict with keys gmdata, gmfdata, indices, hcurves
     """
     oq = self.oqparam
     dt = oq.gmf_data_dt()
     with monitor('GmfGetter.init', measuremem=True):
         self.init()
     hcurves = {}  # key -> poes
     if oq.hazard_curves_from_gmfs:
         hc_mon = monitor('building hazard curves', measuremem=False)
         duration = oq.investigation_time * oq.ses_per_logic_tree_path
         with monitor('building hazard', measuremem=True):
             gmfdata = numpy.fromiter(self.gen_gmv(), dt)
             hazard = self.get_hazard(data=gmfdata)
         for sid, hazardr in zip(self.sids, hazard):
             for rlzi, array in hazardr.items():
                 if len(array) == 0:  # no data
                     continue
                 with hc_mon:
                     gmvs = array['gmv']
                     for imti, imt in enumerate(oq.imtls):
                         poes = _gmvs_to_haz_curve(gmvs[:, imti],
                                                   oq.imtls[imt],
                                                   oq.investigation_time,
                                                   duration)
                         hcurves[rsi2str(rlzi, sid, imt)] = poes
     elif oq.ground_motion_fields:  # fast lane
         with monitor('building hazard', measuremem=True):
             gmfdata = numpy.fromiter(self.gen_gmv(), dt)
     else:
         return {}
     indices = []
     gmfdata.sort(order=('sid', 'rlzi', 'eid'))
     start = stop = 0
     for sid, rows in itertools.groupby(gmfdata['sid']):
         for row in rows:
             stop += 1
         indices.append((sid, start, stop))
         start = stop
     res = dict(gmfdata=gmfdata,
                hcurves=hcurves,
                gmdata=self.gmdata,
                indices=numpy.array(indices, (U32, 3)))
     return res
コード例 #7
0
 def compute_gmfs_curves(self, rlzs, monitor):
     """
     :param rlzs: an array of shapeE
     :returns: a dict with keys gmfdata, indices, hcurves
     """
     oq = self.oqparam
     mon = monitor('getting ruptures', measuremem=True)
     hcurves = {}  # key -> poes
     if oq.hazard_curves_from_gmfs:
         hc_mon = monitor('building hazard curves', measuremem=False)
         gmfdata = self.get_gmfdata(mon)  # returned later
         hazard = self.get_hazard_by_sid(data=gmfdata)
         for sid, hazardr in hazard.items():
             dic = group_by_rlz(hazardr, rlzs)
             for rlzi, array in dic.items():
                 with hc_mon:
                     gmvs = array['gmv']
                     for imti, imt in enumerate(oq.imtls):
                         poes = _gmvs_to_haz_curve(
                             gmvs[:, imti], oq.imtls[imt],
                             oq.ses_per_logic_tree_path)
                         hcurves[rsi2str(rlzi, sid, imt)] = poes
     if not oq.ground_motion_fields:
         return dict(gmfdata=(), hcurves=hcurves)
     gmfdata = self.get_gmfdata(mon)
     if len(gmfdata) == 0:
         return dict(gmfdata=[])
     indices = []
     gmfdata.sort(order=('sid', 'eid'))
     start = stop = 0
     for sid, rows in itertools.groupby(gmfdata['sid']):
         for row in rows:
             stop += 1
         indices.append((sid, start, stop))
         start = stop
     times = numpy.array([tup + (monitor.task_no, ) for tup in self.times],
                         time_dt)
     times.sort(order='rup_id')
     res = dict(gmfdata=gmfdata,
                hcurves=hcurves,
                times=times,
                sig_eps=numpy.array(self.sig_eps, self.sig_eps_dt),
                indices=numpy.array(indices, (U32, 3)))
     return res
コード例 #8
0
ファイル: getters.py プロジェクト: ventycn/oq-engine
 def compute_gmfs_curves(self, monitor):
     """
     :returns: a dict with keys gmfdata, indices, hcurves
     """
     oq = self.oqparam
     with monitor('GmfGetter.init', measuremem=True):
         self.init()
     hcurves = {}  # key -> poes
     if oq.hazard_curves_from_gmfs:
         hc_mon = monitor('building hazard curves', measuremem=False)
         with monitor('building hazard', measuremem=True):
             gmfdata = self.get_gmfdata()  # returned later
             hazard = self.get_hazard_by_sid(data=gmfdata)
         for sid, hazardr in hazard.items():
             dic = group_by_rlz(hazardr, self.eid2rlz)
             for rlzi, array in dic.items():
                 with hc_mon:
                     gmvs = array['gmv']
                     for imti, imt in enumerate(oq.imtls):
                         poes = _gmvs_to_haz_curve(
                             gmvs[:, imti], oq.imtls[imt],
                             oq.ses_per_logic_tree_path)
                         hcurves[rsi2str(rlzi, sid, imt)] = poes
     elif oq.ground_motion_fields:  # fast lane
         with monitor('building hazard', measuremem=True):
             gmfdata = self.get_gmfdata()
     else:
         return dict(gmfdata=(), hcurves=hcurves)
     if len(gmfdata) == 0:
         return dict(gmfdata=[])
     indices = []
     gmfdata.sort(order=('sid', 'eid'))
     start = stop = 0
     for sid, rows in itertools.groupby(gmfdata['sid']):
         for row in rows:
             stop += 1
         indices.append((sid, start, stop))
         start = stop
     res = dict(gmfdata=gmfdata,
                hcurves=hcurves,
                sig_eps=numpy.array(self.sig_eps, self.sig_eps_dt),
                indices=numpy.array(indices, (U32, 3)))
     return res
コード例 #9
0
ファイル: event_based.py プロジェクト: treviallen/oq-engine
def compute_gmfs_and_curves(getter, oq, monitor):
    """
    :param getter:
        a GmfGetter instance
    :param oq:
        an OqParam instance
    :param monitor:
        a Monitor instance
    :returns:
        a dictionary with keys gmfcoll and hcurves
   """
    with monitor('making contexts', measuremem=True):
        getter.init()
    grp_id = getter.grp_id
    hcurves = {}  # key -> poes
    gmfcoll = {}  # grp_id, rlz -> gmfa
    if oq.hazard_curves_from_gmfs:
        hc_mon = monitor('building hazard curves', measuremem=False)
        duration = oq.investigation_time * oq.ses_per_logic_tree_path
        with monitor('building hazard', measuremem=True):
            gmfcoll[grp_id] = data = numpy.fromiter(getter.gen_gmv(),
                                                    getter.gmf_data_dt)
            hazard = sorted(getter.get_hazard(data).items())
        for rlzi, hazardr in hazard:
            for sid in getter.sids:
                array = hazardr[sid]
                if len(array) == 0:  # no data
                    continue
                with hc_mon:
                    gmvs = array['gmv']
                    for imti, imt in enumerate(getter.imts):
                        poes = calc._gmvs_to_haz_curve(gmvs[:, imti],
                                                       oq.imtls[imt],
                                                       oq.investigation_time,
                                                       duration)
                        hcurves[rsi2str(rlzi, sid, imt)] = poes
    else:  # fast lane
        with monitor('building hazard', measuremem=True):
            gmfcoll[grp_id] = numpy.fromiter(getter.gen_gmv(),
                                             getter.gmf_data_dt)
    return dict(gmfcoll=gmfcoll if oq.ground_motion_fields else None,
                hcurves=hcurves,
                gmdata=getter.gmdata)
コード例 #10
0
ファイル: getters.py プロジェクト: digitalsatori/oq-engine
 def compute_gmfs_curves(self, monitor):
     """
     :returns: a dict with keys gmfdata, indices, hcurves
     """
     oq = self.oqparam
     with monitor('GmfGetter.init', measuremem=True):
         self.init()
     hcurves = {}  # key -> poes
     if oq.hazard_curves_from_gmfs:
         hc_mon = monitor('building hazard curves', measuremem=False)
         with monitor('building hazard', measuremem=True):
             gmfdata = self.get_gmfdata()  # returned later
             hazard = self.get_hazard(data=gmfdata)
         for sid, hazardr in hazard.items():
             dic = group_by_rlz(hazardr, self.eid2rlz)
             for rlzi, array in dic.items():
                 with hc_mon:
                     gmvs = array['gmv']
                     for imti, imt in enumerate(oq.imtls):
                         poes = _gmvs_to_haz_curve(
                             gmvs[:, imti], oq.imtls[imt],
                             oq.ses_per_logic_tree_path)
                         hcurves[rsi2str(rlzi, sid, imt)] = poes
     elif oq.ground_motion_fields:  # fast lane
         with monitor('building hazard', measuremem=True):
             gmfdata = self.get_gmfdata()
     else:
         return {}
     if len(gmfdata) == 0:
         return dict(gmfdata=[])
     indices = []
     gmfdata.sort(order=('sid', 'eid'))
     start = stop = 0
     for sid, rows in itertools.groupby(gmfdata['sid']):
         for row in rows:
             stop += 1
         indices.append((sid, start, stop))
         start = stop
     res = dict(gmfdata=gmfdata, hcurves=hcurves,
                sig_eps=numpy.array(self.sig_eps, self.sig_eps_dt),
                indices=numpy.array(indices, (U32, 3)))
     return res
コード例 #11
0
ファイル: event_based.py プロジェクト: mascandola/oq-engine
def event_based(proxies, full_lt, oqparam, dstore, monitor):
    """
    Compute GMFs and optionally hazard curves
    """
    alldata = AccumDict(accum=[])
    sig_eps = []
    times = []  # rup_id, nsites, dt
    hcurves = {}  # key -> poes
    trt_smr = proxies[0]['trt_smr']
    fmon = monitor('filtering ruptures', measuremem=False)
    cmon = monitor('computing gmfs', measuremem=False)
    with dstore:
        trt = full_lt.trts[trt_smr // len(full_lt.sm_rlzs)]
        srcfilter = SourceFilter(dstore['sitecol'],
                                 oqparam.maximum_distance(trt))
        rupgeoms = dstore['rupgeoms']
        rlzs_by_gsim = full_lt._rlzs_by_gsim(trt_smr)
        param = vars(oqparam).copy()
        param['imtls'] = oqparam.imtls
        param['min_iml'] = oqparam.min_iml
        param['maximum_distance'] = oqparam.maximum_distance(trt)
        cmaker = ContextMaker(trt, rlzs_by_gsim, param)
        min_mag = getdefault(oqparam.minimum_magnitude, trt)
        for proxy in proxies:
            t0 = time.time()
            with fmon:
                if proxy['mag'] < min_mag:
                    continue
                sids = srcfilter.close_sids(proxy, trt)
                if len(sids) == 0:  # filtered away
                    continue
                proxy.geom = rupgeoms[proxy['geom_id']]
                ebr = proxy.to_ebr(cmaker.trt)  # after the geometry is set
                try:
                    computer = GmfComputer(ebr,
                                           srcfilter.sitecol.filtered(sids),
                                           cmaker, oqparam.correl_model,
                                           oqparam.cross_correl,
                                           oqparam._amplifier,
                                           oqparam._sec_perils)
                except FarAwayRupture:
                    continue
            with cmon:
                data = computer.compute_all(sig_eps)
            dt = time.time() - t0
            times.append((computer.ebrupture.id, len(computer.ctx.sids), dt))
            for key in data:
                alldata[key].extend(data[key])
    for key, val in sorted(alldata.items()):
        if key in 'eid sid rlz':
            alldata[key] = U32(alldata[key])
        else:
            alldata[key] = F32(alldata[key])
    gmfdata = strip_zeros(pandas.DataFrame(alldata))
    if len(gmfdata) and oqparam.hazard_curves_from_gmfs:
        hc_mon = monitor('building hazard curves', measuremem=False)
        for (sid, rlz), df in gmfdata.groupby(['sid', 'rlz']):
            with hc_mon:
                poes = calc.gmvs_to_poes(df, oqparam.imtls,
                                         oqparam.ses_per_logic_tree_path)
                for m, imt in enumerate(oqparam.imtls):
                    hcurves[rsi2str(rlz, sid, imt)] = poes[m]
    times = numpy.array([tup + (monitor.task_no, ) for tup in times], time_dt)
    times.sort(order='rup_id')
    if not oqparam.ground_motion_fields:
        gmfdata = ()
    return dict(gmfdata=gmfdata,
                hcurves=hcurves,
                times=times,
                sig_eps=numpy.array(sig_eps, sig_eps_dt(oqparam.imtls)))