def on_asset_complete_cb(asset, damage_distribution_asset, collapse_map): self._store_cmap(asset, collapse_map) self._store_dda(asset, scenario_damage.damage_states(fragility_model), damage_distribution_asset)
def compute_risk(self, block_id, **kwargs): """ Compute the results for a single block. Currently we support the computation of: * damage distributions per asset * damage distributions per building taxonomy * total damage distribution * collapse maps :param block_id: id of the region block data. :type block_id: integer :keyword fmodel: fragility model associated to this computation. :type fmodel: instance of :py:class:`openquake.db.models.FragilityModel` :return: the sum of the fractions (for each damage state) per asset taxonomy for the computed block. :rtype: `dict` where each key is a string representing a taxonomy and each value is the sum of fractions of all the assets related to that taxonomy (represented as a 2d `numpy.array`) """ fragility_model = _fm(self.job_ctxt.oq_job) fragility_functions = fragility_model.functions_by_taxonomy() block = general.Block.from_kvs(self.job_ctxt.job_id, block_id) hazard_getter = lambda site: general.load_gmvs_at( self.job_ctxt.job_id, general.hazard_input_site( self.job_ctxt, site)) assets_getter = lambda site: general.BaseRiskCalculator.assets_at( self.job_ctxt.job_id, site) calculator = api.scenario_damage(fragility_model, fragility_functions) for asset_output in api.compute_on_sites(block.sites, assets_getter, hazard_getter, calculator): self._store_cmap(asset_output.asset, asset_output.collapse_map) self._store_dda(asset_output.asset, scenario_damage.damage_states(fragility_model), asset_output.damage_distribution_asset) return calculator.damage_distribution_by_taxonomy
def _store_total_distribution(self): """ Store the total damage distribution. """ [dd] = DmgDistTotal.objects.filter( output__owner=self.job_ctxt.oq_job.owner, output__oq_job=self.job_ctxt.oq_job, output__output_type="dmg_dist_total") fm = _fm(self.job_ctxt.oq_job) for x in xrange(len(self.total_distribution_means)): DmgDistTotalData( dmg_dist_total=dd, dmg_state=scenario_damage.damage_states(fm)[x], mean=self.total_distribution_means[x], stddev=self.total_distribution_stddevs[x]).save()
def _store_ddt(self): """ Store the damage distribution per building taxonomy. """ [ddt] = DmgDistPerTaxonomy.objects.filter( output__owner=self.job_ctxt.oq_job.owner, output__oq_job=self.job_ctxt.oq_job, output__output_type="dmg_dist_per_taxonomy") fm = _fm(self.job_ctxt.oq_job) damage_states = scenario_damage.damage_states(fm) for taxonomy in self.dd_taxonomy_means.keys(): for x in xrange(len(self.dd_taxonomy_means[taxonomy])): DmgDistPerTaxonomyData( dmg_dist_per_taxonomy=ddt, taxonomy=taxonomy, dmg_state=damage_states[x], mean=self.dd_taxonomy_means[taxonomy][x], stddev=self.dd_taxonomy_stddevs[taxonomy][x]).save()
def pre_execute(self): """ Perform the following pre-execution tasks: * store the exposure model specified in the configuration file into database * store the fragility model specified in the configuration file into database * split the interested sites into blocks for later processing * write the initial database container records for calculation results """ self.store_exposure_assets() self.store_fragility_model() self.partition() oq_job = self.job_ctxt.oq_job fm = _fm(oq_job) damage_states = scenario_damage.damage_states(fm) output = Output( owner=oq_job.owner, oq_job=oq_job, display_name="SDA (damage distributions per asset) " "results for calculation id %s" % oq_job.id, db_backed=True, output_type="dmg_dist_per_asset") output.save() DmgDistPerAsset( output=output, dmg_states=damage_states).save() output = Output( owner=oq_job.owner, oq_job=oq_job, display_name="SDA (damage distributions per taxonomy) " "results for calculation id %s" % oq_job.id, db_backed=True, output_type="dmg_dist_per_taxonomy") output.save() DmgDistPerTaxonomy( output=output, dmg_states=damage_states).save() output = Output( owner=oq_job.owner, oq_job=oq_job, display_name="SDA (total damage distributions) " "results for calculation id %s" % oq_job.id, db_backed=True, output_type="dmg_dist_total") output.save() DmgDistTotal( output=output, dmg_states=damage_states).save() output = Output( owner=oq_job.owner, oq_job=oq_job, display_name="SDA (collapse map) " "results for calculation id %s" % oq_job.id, db_backed=True, output_type="collapse_map") output.save() [ism] = inputs4job(oq_job.id, input_type="exposure") [em] = ExposureModel.objects.filter(input=ism, owner=oq_job.owner) CollapseMap( output=output, exposure_model=em).save()