def get_assets_by_taxo(assets, tempname=None): """ :param assets: an array of assets :param tempname: hdf5 file where the epsilons are (or None) :returns: assets_by_taxo with attributes eps and idxs """ assets_by_taxo = AccumDict(group_array(assets, 'taxonomy')) assets_by_taxo.assets = assets assets_by_taxo.idxs = numpy.argsort( numpy.concatenate([a['ordinal'] for a in assets_by_taxo.values()])) assets_by_taxo.eps = {} if tempname is None: # no epsilons return assets_by_taxo # otherwise read the epsilons and group them by taxonomy with hdf5.File(tempname, 'r') as h5: dset = h5['epsilon_matrix'] for taxo, assets in assets_by_taxo.items(): lst = [dset[aid] for aid in assets['ordinal']] assets_by_taxo.eps[taxo] = numpy.array(lst) return assets_by_taxo
def out_by_lr(self, imt, assets, hazard, epsilons, eids=None): """ :param imt: restrict the risk functions to this IMT :param assets: an array of assets of homogeneous taxonomy :param hazard: a dictionary rlz -> hazard :param epsilons: an array of epsilons per each asset :param eids: rupture indices (only for event based) :returns: a dictionary (l, r) -> output """ out_by_lr = AccumDict() out_by_lr.assets = assets out_by_lr.eids = eids loss_types = self.get_loss_types(imt) # extract the realizations from the first asset for rlz in sorted(hazard): r = rlz.ordinal for loss_type in loss_types: out = self(loss_type, assets, hazard[rlz], epsilons, eids) if out: l = self.compositemodel.lti[loss_type] out.hid = r out.weight = rlz.weight out_by_lr[l, r] = out return out_by_lr
def out_by_lr(self, imt, assets, hazard, epsgetter): """ :param imt: restrict the risk functions to this IMT :param assets: an array of assets of homogeneous taxonomy :param hazard: a dictionary rlz -> hazard :param epsgetter: a callable returning epsilons for the given eids :returns: a dictionary (l, r) -> output """ out_by_lr = AccumDict() out_by_lr.assets = assets loss_types = self.get_loss_types(imt) for rlz in sorted(hazard): haz = hazard[rlz] if len(haz) == 0: continue r = rlz.ordinal for loss_type in loss_types: out = self(loss_type, assets, haz, epsgetter) if out: # can be None in scenario_risk with no valid values l = self.compositemodel.lti[loss_type] out.hid = r out.weight = rlz.weight out_by_lr[l, r] = out return out_by_lr
def out_by_lr(self, imt, assets, hazard, epsgetter): """ :param imt: restrict the risk functions to this IMT :param assets: an array of assets of homogeneous taxonomy :param hazard: a dictionary rlz -> hazard :param epsgetter: a callable returning epsilons for the given eids :returns: a dictionary (l, r) -> output """ out_by_lr = AccumDict() out_by_lr.assets = assets loss_types = self.get_loss_types(imt) for rlz in sorted(hazard): haz = hazard[rlz] if len(haz) == 0: continue r = rlz.ordinal for loss_type in loss_types: out = self(loss_type, assets, haz, epsgetter) if out: # can be None in scenario_risk with no valid values l = self.compositemodel.lti[loss_type] out.hid = r out.weight = rlz.weight out_by_lr[l, r] = out return out_by_lr