예제 #1
0
    def post_execute(self, pmap_by_key):
        """
        Collect the hazard curves by realization and export them.

        :param pmap_by_key:
            a dictionary key -> hazard curves
        """
        oq = self.oqparam
        data = []
        weights = [rlz.weight for rlz in self.realizations]
        pgetter = getters.PmapGetter(self.datastore, weights)
        with self.monitor('saving probability maps'):
            for key, pmap in pmap_by_key.items():
                if isinstance(key, str):  # disagg_by_src
                    serial = self.csm.source_info[key][readinput.SERIAL]
                    self.datastore['disagg_by_src'][..., serial] = (
                        pgetter.get_hcurves(
                            {'grp-%02d' % gid: pmap[gid]
                             for gid in pmap}))
                elif pmap:  # pmap can be missing if the group is filtered away
                    # key is the group ID
                    base.fix_ones(pmap)  # avoid saving PoEs == 1
                    trt = self.full_lt.trt_by_grp[key]
                    name = 'poes/grp-%02d' % key
                    self.datastore[name] = pmap
                    extreme = max(
                        get_extreme_poe(pmap[sid].array, oq.imtls)
                        for sid in pmap)
                    data.append((key, trt, extreme))
        if oq.hazard_calculation_id is None and 'poes' in self.datastore:
            self.datastore['disagg_by_grp'] = numpy.array(
                sorted(data), grp_extreme_dt)
            self.calc_stats()
예제 #2
0
    def post_execute(self, pmap_by_grp_id):
        """
        Collect the hazard curves by realization and export them.

        :param pmap_by_grp_id:
            a dictionary grp_id -> hazard curves
        """
        oq = self.oqparam
        data = []
        with self.monitor('saving probability maps'):
            for grp_id, pmap in pmap_by_grp_id.items():
                if pmap:  # pmap can be missing if the group is filtered away
                    base.fix_ones(pmap)  # avoid saving PoEs == 1
                    trt = self.full_lt.trt_by_grp[grp_id]
                    key = 'poes/grp-%02d' % grp_id
                    self.datastore[key] = pmap
                    self.datastore.set_attrs(key, trt=trt)
                    extreme = max(
                        get_extreme_poe(pmap[sid].array, oq.imtls)
                        for sid in pmap)
                    data.append((grp_id, trt, extreme))
        if oq.hazard_calculation_id is None and 'poes' in self.datastore:
            self.datastore['disagg_by_grp'] = numpy.array(
                sorted(data), grp_extreme_dt)
            self.calc_stats()
예제 #3
0
 def store_poes(self, grp_id, pmap):
     """
     Store the pmap of the given group inside the _poes dataset
     """
     cmaker = self.cmakers[grp_id]
     base.fix_ones(pmap)  # avoid saving PoEs == 1, fast
     arr = numpy.array([pmap[sid].array for sid in pmap]).transpose(2, 0, 1)
     self.datastore['_poes'][cmaker.slc] = arr  # shape GNL
     extreme = max(
         get_extreme_poe(pmap[sid].array, self.imtls) for sid in pmap)
     self.data.append((grp_id, cmaker.trt, extreme))
예제 #4
0
 def store_poes(self, grp_id, pmap):
     """
     Store the pmap of the given group inside the _poes dataset
     """
     trt = self.full_lt.trt_by_et[self.et_ids[grp_id][0]]
     base.fix_ones(pmap)  # avoid saving PoEs == 1, fast
     arr = numpy.array([pmap[sid].array for sid in pmap]).transpose(2, 0, 1)
     self.datastore['_poes'][self.slice_by_g[grp_id]] = arr  # shape GNL
     extreme = max(
         get_extreme_poe(pmap[sid].array, self.imtls)
         for sid in pmap)
     self.data.append((grp_id, trt, extreme))
예제 #5
0
    def post_execute(self, pmap_by_key):
        """
        Collect the hazard curves by realization and export them.

        :param pmap_by_key:
            a dictionary key -> hazard curves
        """
        nr = {
            name: len(dset['mag'])
            for name, dset in self.datastore.items() if name.startswith('rup_')
        }
        if nr:  # few sites, log the number of ruptures per magnitude
            logging.info('%s', nr)
        oq = self.oqparam
        if oq.calculation_mode.endswith(('risk', 'damage', 'bcr')):
            with hdf5.File(self.datastore.tempname, 'a') as cache:
                cache['oqparam'] = oq
                cache['rlzs_by_grp'] = self.full_lt.get_rlzs_by_grp()
        data = []
        weights = [rlz.weight for rlz in self.realizations]
        pgetter = getters.PmapGetter(self.datastore, weights,
                                     self.sitecol.sids, oq.imtls)
        with self.monitor('saving probability maps'):
            for key, pmap in pmap_by_key.items():
                if isinstance(key, str):  # disagg_by_src
                    serial = self.csm.source_info[key][readinput.SERIAL]
                    self.datastore['disagg_by_src'][..., serial] = (
                        pgetter.get_hcurves(
                            {'grp-%02d' % gid: pmap[gid]
                             for gid in pmap}))
                elif pmap:  # pmap can be missing if the group is filtered away
                    # key is the group ID
                    base.fix_ones(pmap)  # avoid saving PoEs == 1
                    trt = self.full_lt.trt_by_grp[key]
                    name = 'poes/grp-%02d' % key
                    self.datastore[name] = pmap
                    if oq.calculation_mode.endswith(('risk', 'damage', 'bcr')):
                        with hdf5.File(self.datastore.tempname, 'a') as cache:
                            cache[name] = pmap
                    extreme = max(
                        get_extreme_poe(pmap[sid].array, oq.imtls)
                        for sid in pmap)
                    data.append((key, trt, extreme))
        if oq.hazard_calculation_id is None and 'poes' in self.datastore:
            self.datastore['disagg_by_grp'] = numpy.array(
                sorted(data), grp_extreme_dt)
            self.calc_stats()
예제 #6
0
    def post_execute(self, pmap_by_key):
        """
        Collect the hazard curves by realization and export them.

        :param pmap_by_key:
            a dictionary key -> hazard curves
        """
        nr = {
            name: len(dset['mag'])
            for name, dset in self.datastore.items() if name.startswith('rup_')
        }
        if nr:  # few sites, log the number of ruptures per magnitude
            logging.info('%s', nr)
        oq = self.oqparam
        et_ids = self.datastore['et_ids'][:]
        rlzs_by_gsim_list = self.full_lt.get_rlzs_by_gsim_list(et_ids)
        slice_by_g = getters.get_slice_by_g(rlzs_by_gsim_list)
        data = []
        weights = [rlz.weight for rlz in self.realizations]
        pgetter = getters.PmapGetter(self.datastore, weights,
                                     self.sitecol.sids, oq.imtls)
        logging.info('Saving _poes')
        enum = enumerate(self.datastore['source_info']['source_id'])
        srcid = {source_id: i for i, source_id in enum}
        with self.monitor('saving probability maps'):
            for key, pmap in pmap_by_key.items():
                if isinstance(key, str):  # disagg_by_src
                    rlzs_by_gsim = rlzs_by_gsim_list[pmap.grp_id]
                    self.datastore['disagg_by_src'][..., srcid[key]] = (
                        pgetter.get_hcurves(pmap, rlzs_by_gsim))
                elif pmap:  # pmap can be missing if the group is filtered away
                    # key is the group ID
                    trt = self.full_lt.trt_by_et[et_ids[key][0]]
                    # avoid saving PoEs == 1
                    base.fix_ones(pmap)
                    sids = sorted(pmap)
                    arr = numpy.array([pmap[sid].array for sid in sids])
                    self.datastore['_poes'][sids, :, slice_by_g[key]] = arr
                    extreme = max(
                        get_extreme_poe(pmap[sid].array, oq.imtls)
                        for sid in pmap)
                    data.append((key, trt, extreme))
        if oq.hazard_calculation_id is None and '_poes' in self.datastore:
            self.datastore['disagg_by_grp'] = numpy.array(
                sorted(data), grp_extreme_dt)
            self.datastore.swmr_on()  # needed
            self.calc_stats()
예제 #7
0
    def post_execute(self, pmap_by_grp_id):
        """
        Collect the hazard curves by realization and export them.

        :param pmap_by_grp_id:
            a dictionary grp_id -> hazard curves
        """
        oq = self.oqparam
        try:
            csm_info = self.csm.info
        except AttributeError:
            csm_info = self.datastore['csm_info']
        trt_by_grp = csm_info.grp_by("trt")
        grp_name = {
            grp.id: grp.name
            for sm in csm_info.source_models for grp in sm.src_groups
        }
        data = []
        with self.monitor('saving probability maps', autoflush=True):
            for grp_id, pmap in pmap_by_grp_id.items():
                if pmap:  # pmap can be missing if the group is filtered away
                    base.fix_ones(pmap)  # avoid saving PoEs == 1
                    trt = trt_by_grp[grp_id]
                    key = 'poes/grp-%02d' % grp_id
                    self.datastore[key] = pmap
                    self.datastore.set_attrs(key, trt=trt)
                    extreme = max(
                        get_extreme_poe(pmap[sid].array, oq.imtls)
                        for sid in pmap)
                    data.append((grp_id, grp_name[grp_id], extreme))
                    if 'rup' in set(self.datastore):
                        self.datastore.set_nbytes('rup/grp-%02d' % grp_id)
                        tot_ruptures = sum(
                            len(r) for r in self.datastore['rup'].values())
                        self.datastore.set_attrs('rup',
                                                 tot_ruptures=tot_ruptures)
        if oq.hazard_calculation_id is None and 'poes' in self.datastore:
            self.datastore.set_nbytes('poes')
            self.datastore['disagg_by_grp'] = numpy.array(
                sorted(data), grp_extreme_dt)

            # save a copy of the poes in hdf5cache
            with hdf5.File(self.hdf5cache) as cache:
                cache['oqparam'] = oq
                self.datastore.hdf5.copy('poes', cache)
            self.calc_stats(self.hdf5cache)
예제 #8
0
 def store(self, imtls, pmap_by_key):
     for key, pmap in pmap_by_key.items():
         if isinstance(key, str):  # disagg_by_src
             rlzs_by_gsim = self.rlzs_by_gsim_list[pmap.grp_id]
             self.datastore['disagg_by_src'][..., self.srcidx[key]] = (
                 self.get_hcurves(pmap, rlzs_by_gsim))
         else:
             # key is the group ID
             trt = self.full_lt.trt_by_et[self.et_ids[key][0]]
             # avoid saving PoEs == 1
             base.fix_ones(pmap)
             arr = numpy.array([pmap[sid].array for sid in pmap])
             logging.info('Storing _poes for source group #%d', key)
             self.datastore['_poes'][:, :, self.slice_by_g[key]] = arr
             extreme = max(
                 get_extreme_poe(pmap[sid].array, imtls) for sid in pmap)
             self.data.append((key, trt, extreme))
예제 #9
0
    def post_execute(self, pmap_by_grp_id):
        """
        Collect the hazard curves by realization and export them.

        :param pmap_by_grp_id:
            a dictionary grp_id -> hazard curves
        """
        oq = self.oqparam
        csm_info = self.datastore['csm_info']
        grp_trt = csm_info.grp_by("trt")
        grp_source = csm_info.grp_by("name")
        if oq.disagg_by_src:
            src_name = {
                src.src_group_id: src.name
                for src in self.csm.get_sources()
            }
        data = []
        with self.monitor('saving probability maps', autoflush=True):
            for grp_id, pmap in pmap_by_grp_id.items():
                if pmap:  # pmap can be missing if the group is filtered away
                    base.fix_ones(pmap)  # avoid saving PoEs == 1
                    key = 'poes/grp-%02d' % grp_id
                    self.datastore[key] = pmap
                    self.datastore.set_attrs(key, trt=grp_trt[grp_id])
                    if oq.disagg_by_src:
                        data.append(
                            (grp_id, grp_source[grp_id], src_name[grp_id]))
        if oq.hazard_calculation_id is None and 'poes' in self.datastore:
            self.datastore.set_nbytes('poes')
            if oq.disagg_by_src and csm_info.get_num_rlzs() == 1:
                # this is useful for disaggregation, which is implemented
                # only for the case of a single realization
                self.datastore['disagg_by_src/source_id'] = numpy.array(
                    sorted(data), grp_source_dt)

            # save a copy of the poes in hdf5cache
            if hasattr(self, 'hdf5cache'):
                with hdf5.File(self.hdf5cache) as cache:
                    cache['oqparam'] = oq
                    self.datastore.hdf5.copy('poes', cache)
                self.calc_stats(self.hdf5cache)
            else:
                self.calc_stats(self.datastore)
예제 #10
0
    def post_execute(self, pmap_by_grp_id):
        """
        Collect the hazard curves by realization and export them.

        :param pmap_by_grp_id:
            a dictionary grp_id -> hazard curves
        """
        oq = self.oqparam
        try:
            csm_info = self.csm.info
        except AttributeError:
            csm_info = self.datastore['csm_info']
        trt_by_grp = csm_info.grp_by("trt")
        grp_name = {grp.id: grp.name for sm in csm_info.source_models
                    for grp in sm.src_groups}
        data = []
        with self.monitor('saving probability maps', autoflush=True):
            for grp_id, pmap in pmap_by_grp_id.items():
                if pmap:  # pmap can be missing if the group is filtered away
                    base.fix_ones(pmap)  # avoid saving PoEs == 1
                    trt = trt_by_grp[grp_id]
                    key = 'poes/grp-%02d' % grp_id
                    self.datastore[key] = pmap
                    self.datastore.set_attrs(key, trt=trt)
                    extreme = max(
                        get_extreme_poe(pmap[sid].array, oq.imtls)
                        for sid in pmap)
                    data.append((grp_id, grp_name[grp_id], extreme))
                    if 'rup' in set(self.datastore):
                        self.datastore.set_nbytes('rup/grp-%02d' % grp_id)
        if oq.hazard_calculation_id is None and 'poes' in self.datastore:
            self.datastore.set_nbytes('poes')
            self.datastore['disagg_by_grp'] = numpy.array(
                sorted(data), grp_extreme_dt)

            # save a copy of the poes in hdf5cache
            with hdf5.File(self.hdf5cache) as cache:
                cache['oqparam'] = oq
                self.datastore.hdf5.copy('poes', cache)
            self.calc_stats(self.hdf5cache)