def compute_losses(ssm, sitecol, assetcol, riskmodel, imts, trunc_level, correl_model, min_iml, monitor): """ Compute the losses for a single source model. :param ssm: CompositeSourceModel containing a single source model :param sitecol: a SiteCollection instance :param assetcol: an AssetCollection instance :param riskmodel: a RiskModel instance :param imts: a list of Intensity Measure Types :param trunc_level: truncation level :param correl_model: correlation model :param min_iml: vector of minimum intensities, one per IMT :param monitor: a Monitor instance :returns: a List containing the losses by taxonomy and some attributes """ [grp] = ssm.src_groups res = List() gsims = ssm.gsim_lt.values[DEFAULT_TRT] res.ruptures_by_grp = compute_ruptures(grp, sitecol, gsims, monitor) [(grp_id, ebruptures)] = res.ruptures_by_grp.items() rlzs_assoc = ssm.info.get_rlzs_assoc() num_rlzs = len(rlzs_assoc.realizations) ri = riskinput.RiskInputFromRuptures( DEFAULT_TRT, rlzs_assoc, imts, sitecol, ebruptures, trunc_level, correl_model, min_iml) res.append(event_based_risk(ri, riskmodel, assetcol, monitor)) res.sm_id = ssm.sm_id res.num_events = len(ri.eids) start = res.sm_id * num_rlzs res.rlz_slice = slice(start, start + num_rlzs) # don't return back the ruptures, only the events and rup_data res.ruptures_by_grp[grp_id] = [EBR(ebr.serial, ebr.source_id, ebr.events) for ebr in ebruptures] return res
def compute_losses(ssm, src_filter, param, riskmodel, imts, trunc_level, correl_model, min_iml, monitor): """ Compute the losses for a single source model. Returns the ruptures as an attribute `.ruptures_by_grp` of the list of losses. :param ssm: CompositeSourceModel containing a single source model :param sitecol: a SiteCollection instance :param param: a dictionary of parameters :param riskmodel: a RiskModel instance :param imts: a list of Intensity Measure Types :param trunc_level: truncation level :param correl_model: correlation model :param min_iml: vector of minimum intensities, one per IMT :param monitor: a Monitor instance :returns: a List containing the losses by taxonomy and some attributes """ [grp] = ssm.src_groups res = List() gsims = ssm.gsim_lt.values[DEFAULT_TRT] ruptures_by_grp = compute_ruptures( grp, src_filter, gsims, param, monitor) [(grp_id, ebruptures)] = ruptures_by_grp.items() rlzs_assoc = ssm.info.get_rlzs_assoc() samples = ssm.info.get_samples_by_grp() num_rlzs = len(rlzs_assoc.realizations) rlzs_by_gsim = rlzs_assoc.get_rlzs_by_gsim(DEFAULT_TRT) getter = getters.GmfGetter( rlzs_by_gsim, ebruptures, src_filter.sitecol, imts, min_iml, src_filter.integration_distance, trunc_level, correl_model, samples[grp_id]) ri = riskinput.RiskInput(getter, param['assetcol'].assets_by_site()) res.append(event_based_risk(ri, riskmodel, param, monitor)) res.sm_id = ssm.sm_id res.num_events = len(ri.hazard_getter.eids) start = res.sm_id * num_rlzs res.rlz_slice = slice(start, start + num_rlzs) res.events_by_grp = ruptures_by_grp.events_by_grp res.eff_ruptures = ruptures_by_grp.eff_ruptures return res