def scenario_damage(workflow, getter, outputdict, params, monitor): """ Celery task for the scenario damage risk calculator. :param workflow: A :class:`openquake.risklib.workflows.Workflow` instance :param getter: A HazardGetter instance :param outputdict: An instance of :class:`..writers.OutputDict` containing output container instances (in this case only `LossMap`) :param params: An instance of :class:`..base.CalcParams` used to compute derived outputs :param monitor: A monitor instance :returns: A matrix of fractions and a taxonomy string """ [ffs] = workflow.risk_functions # and no output containers assert len(outputdict) == 0, outputdict with monitor('computing risk', autoflush=True): out = workflow( 'damage', getter.assets, getter.get_data(), None) aggfractions = sum(out.damages[i] * asset.number_of_units for i, asset in enumerate(out.assets)) with monitor('saving damage per assets', autoflush=True): writers.damage_distribution( getter.assets, out.damages, params.damage_state_ids) return {getter.assets[0].taxonomy: aggfractions}
def do_scenario_damage(unit, params, profile): with profile('getting hazard'): _hid, assets, ground_motion_values = unit.getter().next() if not len(assets): logs.LOG.warn("Exit from task as no asset could be processed") return None, None elif not len(ground_motion_values): # NB: (MS) this should not happen, but I saw it happens; # should it happen again, to debug this situation you should run # the query in GroundMotionValuesGetter.assets_gen and see # how it is possible that sites without gmvs are returned raise RuntimeError("No GMVs for assets %s" % assets) with profile('computing risk'): fraction_matrix = unit.workflow(ground_motion_values) aggfractions = sum(fraction_matrix[i] * asset.number_of_units for i, asset in enumerate(assets)) with profile('saving damage per assets'): writers.damage_distribution(assets, fraction_matrix, params.damage_state_ids) return aggfractions, assets[0].taxonomy
def do_scenario_damage(unit, params, profile): with profile('getting hazard'): _hid, assets, ground_motion_values = unit.getter().next() if not len(assets): logs.LOG.warn("Exit from task as no asset could be processed") return None, None elif not len(ground_motion_values): # NB: (MS) this should not happen, but I saw it happens; # should it happen again, to debug this situation you should run # the query in GroundMotionValuesGetter.assets_gen and see # how it is possible that sites without gmvs are returned raise RuntimeError("No GMVs for assets %s" % assets) with profile('computing risk'): fraction_matrix = unit.workflow(ground_motion_values) aggfractions = sum(fraction_matrix[i] * asset.number_of_units for i, asset in enumerate(assets)) with profile('saving damage per assets'): writers.damage_distribution( assets, fraction_matrix, params.damage_state_ids) return aggfractions, assets[0].taxonomy
def scenario_damage(workflow, getter, outputdict, params, monitor): """ Celery task for the scenario damage risk calculator. :param workflow: A :class:`openquake.risklib.workflows.Workflow` instance :param getter: A HazardGetter instance :param outputdict: An instance of :class:`..writers.OutputDict` containing output container instances (in this case only `LossMap`) :param params: An instance of :class:`..base.CalcParams` used to compute derived outputs :param monitor: A monitor instance :returns: A matrix of fractions and a taxonomy string """ [ffs] = workflow.risk_functions # and no output containers assert len(outputdict) == 0, outputdict with monitor('computing risk', autoflush=True): out = workflow('damage', getter.assets, getter.get_data(), None) aggfractions = sum(out.damages[i] * asset.number_of_units for i, asset in enumerate(out.assets)) with monitor('saving damage per assets', autoflush=True): writers.damage_distribution(getter.assets, out.damages, params.damage_state_ids) return {getter.assets[0].taxonomy: aggfractions}
def do_scenario_damage(unit, params, profile): with profile('getting hazard'): assets, ground_motion_values = unit.getter() if not len(assets): logs.LOG.warn("Exit from task as no asset could be processed") return None, None with profile('computing risk'): fraction_matrix = unit.calc(ground_motion_values) aggfractions = sum(fraction_matrix[i] * asset.number_of_units for i, asset in enumerate(assets)) with profile('saving damage per assets'): writers.damage_distribution( assets, fraction_matrix, params.damage_state_ids) return aggfractions, assets[0].taxonomy
def scenario_damage(job_id, risk_model, getters, outputdict, params): """ Celery task for the scenario damage risk calculator. :param int job_id: ID of the currently running job :param risk_model: A :class:`openquake.risklib.workflows.RiskModel` instance :param getters: A list of callable hazard getters :param outputdict: An instance of :class:`..writers.OutputDict` containing output container instances (in this case only `LossMap`) :param params: An instance of :class:`..base.CalcParams` used to compute derived outputs :returns: A matrix of fractions and a taxonomy string """ monitor = EnginePerformanceMonitor( None, job_id, scenario_damage, tracing=True) # in scenario damage calculation the only loss_type is 'damage' [getter] = getters [ffs] = risk_model.vulnerability_functions # and NO containes assert len(outputdict) == 0 with db.transaction.commit_on_success(using='job_init'): with monitor.copy('getting hazard'): ground_motion_values = getter.get_data(ffs.imt) with monitor.copy('computing risk'): fractions = risk_model.workflow(ground_motion_values) aggfractions = sum(fractions[i] * asset.number_of_units for i, asset in enumerate(getter.assets)) with monitor.copy('saving damage per assets'): writers.damage_distribution( getter.assets, fractions, params.damage_state_ids) return aggfractions, risk_model.taxonomy