Risk Calculators¶
General¶
Hazard Getters¶
Hazard input management for Risk calculators.
-
exception
openquake.engine.calculators.risk.hazard_getters.
AssetSiteAssociationError
[source]¶ Bases:
exceptions.Exception
-
class
openquake.engine.calculators.risk.hazard_getters.
GroundMotionGetter
(imt, taxonomy, hazard_outputs, assets)[source]¶ Bases:
openquake.engine.calculators.risk.hazard_getters.HazardGetter
-
class
openquake.engine.calculators.risk.hazard_getters.
Hazard
(hazard_output, data, imt)[source]¶ Bases:
object
Hazard objects have attributes .hazard_output, .data and .imt. Moreover you can extract the .hid (hazard_output.id) and the .weight associated to the underlying realization. The hazard .data is a numpy array of shape (N, R) where N is the number of assets and R the number of seismic events (ruptures) or the resolution of the hazard curve, depending on the calculator.
-
hid
¶ Return the id of the given hazard output
-
weight
¶ Return the realization weight of the hazard output
-
-
class
openquake.engine.calculators.risk.hazard_getters.
HazardCurveGetter
(imt, taxonomy, hazard_outputs, assets)[source]¶ Bases:
openquake.engine.calculators.risk.hazard_getters.HazardGetter
-
class
openquake.engine.calculators.risk.hazard_getters.
HazardGetter
(imt, taxonomy, hazard_outputs, assets)[source]¶ Bases:
object
A HazardGetter instance stores a chunk of assets and their associated hazard data. In the case of scenario and event based calculators it also stores the ruptures and the epsilons. The HazardGetter must be pickable such that it should be possible to use different strategies (e.g. distributed or not, using postgis or not).
attr assets: The assets for which we want to extract the hazard Attr site_ids: The ids of the sites associated to the hazards -
hid
¶ Return the id of the hazard output, when there is a single realization
-
-
class
openquake.engine.calculators.risk.hazard_getters.
RiskInitializer
(taxonomy, calc)[source]¶ Bases:
object
A facility providing the brigde between the hazard (sites and outputs) and the risk (assets and risk models). When .init_assocs is called, populates the asset_site table with the associations between the assets in the current exposure model and the sites in the previous hazard calculation.
Parameters: - hazard_outputs – outputs of the previous hazard calculation
- taxonomy – the taxonomy of the assets we are interested in
- calc – a risk calculator
Warning: instantiating a RiskInitializer may perform a potentially expensive geospatial query.
-
calc_nbytes
(epsilon_sampling=None)[source]¶ Parameters: epsilon_sampling – flag saying if the epsilon_sampling feature is enabled Returns: the number of bytes to be allocated (a guess) If the hazard_outputs come from an event based or scenario computation, populate the .epsilons_shape dictionary.
-
init_epsilons
(epsilon_sampling=None)[source]¶ Parameters: epsilon_sampling – flag saying if the epsilon_sampling feature is enabled Populate the .epsilons_shape and the ._rupture_ids dictionaries. For the calculators event_based_risk and scenario_risk also stores the epsilons in the database for each asset_site association.
-
openquake.engine.calculators.risk.hazard_getters.
expand
(array, N)[source]¶ Given a non-empty array with n elements, expands it to a larger array with N elements.
>>> expand([1], 3) array([1, 1, 1]) >>> expand([1, 2, 3], 10) array([1, 2, 3, 1, 2, 3, 1, 2, 3, 1]) >>> expand(numpy.zeros((2, 10)), 5).shape (5, 10)
Classical PSHA Calculator¶
Core functionality for the classical PSHA risk calculator.
-
class
openquake.engine.calculators.risk.classical_risk.core.
ClassicalRiskCalculator
(job)[source]¶ Bases:
openquake.engine.calculators.risk.base.RiskCalculator
Classical PSHA risk calculator. Computes loss curves and loss maps for a given set of assets.
-
static
core
(workflow, getter, outputdict, params, monitor)¶ Celery task for the classical risk calculator.
Parameters: - workflow – A
openquake.risklib.riskinput.RiskModel
instance - getter – A HazardGetter instance
- outputdict – An instance of
writers.OutputDict
containing output container instances (e.g. a LossCurve) - params – An instance of
base.CalcParams
used to compute derived outputs - monitor – A monitor instance
For each calculation unit we compute loss curves, loss maps and loss fractions. Then if the number of units are bigger than 1, we compute mean and quantile artifacts.
- workflow – A
-
getter_class
¶ alias of
HazardCurveGetter
-
output_builders
= [<class 'openquake.engine.calculators.risk.writers.LossCurveMapBuilder'>, <class 'openquake.engine.calculators.risk.writers.ConditionalLossFractionBuilder'>]¶
-
validators
= [<class 'openquake.engine.calculators.risk.validation.HazardIMT'>, <class 'openquake.engine.calculators.risk.validation.EmptyExposure'>, <class 'openquake.engine.calculators.risk.validation.OrphanTaxonomies'>, <class 'openquake.engine.calculators.risk.validation.ExposureLossTypes'>, <class 'openquake.engine.calculators.risk.validation.NoRiskModels'>, <class 'openquake.engine.calculators.risk.validation.ExposureHasInsuranceBounds'>]¶
-
static
-
openquake.engine.calculators.risk.classical_risk.core.
classical
(workflow, getter, outputdict, params, monitor)[source]¶ Celery task for the classical risk calculator.
Parameters: - workflow – A
openquake.risklib.riskinput.RiskModel
instance - getter – A HazardGetter instance
- outputdict – An instance of
writers.OutputDict
containing output container instances (e.g. a LossCurve) - params – An instance of
base.CalcParams
used to compute derived outputs - monitor – A monitor instance
For each calculation unit we compute loss curves, loss maps and loss fractions. Then if the number of units are bigger than 1, we compute mean and quantile artifacts.
- workflow – A
-
openquake.engine.calculators.risk.classical_risk.core.
save_individual_outputs
(outputdict, outs, params)[source]¶ Save loss curves, loss maps and loss fractions associated with a calculation unit
Parameters: - outputdict – a
openquake.engine.calculators.risk.writers.OutputDict
instance holding the reference to the output container objects - outs – a
openquake.risklib.workflows.Classical.Output
holding the output data for a calculation unit - params – a
openquake.engine.calculators.risk.base.CalcParams
holding the parameters for this calculation
- outputdict – a
-
openquake.engine.calculators.risk.classical_risk.core.
save_statistical_output
(outputdict, stats, params)[source]¶ Save statistical outputs (mean and quantile loss curves, mean and quantile loss maps, mean and quantile loss fractions) for the calculation.
Parameters: - outputdict – a
openquake.engine.calculators.risk.writers.OutputDict
instance holding the reference to the output container objects - outs – a
openquake.risklib.workflows.Classical.StatisticalOutput
holding the statistical output data - params – a
openquake.engine.calculators.risk.base.CalcParams
holding the parameters for this calculation
- outputdict – a
Classical PSHA BCR Calculator¶
Core functionality for the classical PSHA risk calculator.
-
class
openquake.engine.calculators.risk.classical_bcr.core.
ClassicalBCRRiskCalculator
(job)[source]¶ Bases:
openquake.engine.calculators.risk.classical_risk.core.ClassicalRiskCalculator
Classical BCR risk calculator. Computes BCR distributions for a given set of assets.
Attr dict vulnerability_functions_retrofitted: A dictionary mapping each taxonomy to a vulnerability functions for the retrofitted losses computation -
static
core
(workflow, getter, outputdict, params, monitor)¶ Celery task for the BCR risk calculator based on the classical calculator.
Instantiates risklib calculators, computes BCR and stores the results to db in a single transaction.
Parameters: - job_id (int) – ID of the currently running job
- workflow – A
openquake.risklib.workflows.Workflow
instance - getter – A HazardGetter instance
- outputdict – An instance of
writers.OutputDict
containing output container instances (in this case only BCRDistribution) - params – An instance of
base.CalcParams
used to compute derived outputs - monitor – A monitor instance
-
getter_class
¶ alias of
HazardCurveGetter
-
output_builders
= [<class 'openquake.engine.calculators.risk.writers.BCRMapBuilder'>]¶
-
validators
= [<class 'openquake.engine.calculators.risk.validation.HazardIMT'>, <class 'openquake.engine.calculators.risk.validation.EmptyExposure'>, <class 'openquake.engine.calculators.risk.validation.OrphanTaxonomies'>, <class 'openquake.engine.calculators.risk.validation.ExposureLossTypes'>, <class 'openquake.engine.calculators.risk.validation.NoRiskModels'>, <class 'openquake.engine.calculators.risk.validation.ExposureHasInsuranceBounds'>, <class 'openquake.engine.calculators.risk.validation.ExposureHasRetrofittedCosts'>]¶
-
static
-
openquake.engine.calculators.risk.classical_bcr.core.
classical_bcr
(workflow, getter, outputdict, params, monitor)[source]¶ Celery task for the BCR risk calculator based on the classical calculator.
Instantiates risklib calculators, computes BCR and stores the results to db in a single transaction.
Parameters: - job_id (int) – ID of the currently running job
- workflow – A
openquake.risklib.workflows.Workflow
instance - getter – A HazardGetter instance
- outputdict – An instance of
writers.OutputDict
containing output container instances (in this case only BCRDistribution) - params – An instance of
base.CalcParams
used to compute derived outputs - monitor – A monitor instance
Event-Based PSHA Calculator¶
Core functionality for the classical PSHA risk calculator.
-
class
openquake.engine.calculators.risk.event_based_risk.core.
DisaggregationOutputs
(assets_disagg, magnitude_distance, coordinate, fractions)[source]¶ Bases:
object
-
class
openquake.engine.calculators.risk.event_based_risk.core.
EventBasedRiskCalculator
(job)[source]¶ Bases:
openquake.engine.calculators.risk.base.RiskCalculator
Probabilistic Event Based PSHA risk calculator. Computes loss curves, loss maps, aggregate losses and insured losses for a given set of assets.
-
agg_result
(*args)¶
-
static
core
(workflow, getter, outputdict, params, monitor)¶ Celery task for the event based risk calculator.
Parameters: - job_id – the id of the current
openquake.engine.db.models.OqJob
- workflow – A
openquake.risklib.workflows.Workflow
instance - getter – A
HazardGetter
instance - outputdict – An instance of
writers.OutputDict
containing output container instances (e.g. a LossCurve) - params – An instance of
base.CalcParams
used to compute derived outputs - monitor – A monitor instance
Returns: A dictionary {loss_type: event_loss_table}
- job_id – the id of the current
-
getter_class
¶ alias of
GroundMotionGetter
-
output_builders
= [<class 'openquake.engine.calculators.risk.writers.EventLossCurveMapBuilder'>, <class 'openquake.engine.calculators.risk.writers.LossFractionBuilder'>]¶
-
validators
= [<class 'openquake.engine.calculators.risk.validation.HazardIMT'>, <class 'openquake.engine.calculators.risk.validation.EmptyExposure'>, <class 'openquake.engine.calculators.risk.validation.OrphanTaxonomies'>, <class 'openquake.engine.calculators.risk.validation.ExposureLossTypes'>, <class 'openquake.engine.calculators.risk.validation.NoRiskModels'>, <class 'openquake.engine.calculators.risk.validation.ExposureHasInsuranceBounds'>]¶
-
-
openquake.engine.calculators.risk.event_based_risk.core.
disaggregate
(outputs, ruptures, params)[source]¶ Compute disaggregation outputs given the individual outputs and params
Parameters: - outputs – an instance of
openquake.risklib.workflows.ProbabilisticEventBased.Output
- params – an instance of
base.CalcParams
- rupture_ids (list) – a list of
openquake.engine.db.models.SESRupture
IDs
Returns: an instance of
DisaggregationOutputs
- outputs – an instance of
-
openquake.engine.calculators.risk.event_based_risk.core.
event_based
(workflow, getter, outputdict, params, monitor)[source]¶ Celery task for the event based risk calculator.
Parameters: - job_id – the id of the current
openquake.engine.db.models.OqJob
- workflow – A
openquake.risklib.workflows.Workflow
instance - getter – A
HazardGetter
instance - outputdict – An instance of
writers.OutputDict
containing output container instances (e.g. a LossCurve) - params – An instance of
base.CalcParams
used to compute derived outputs - monitor – A monitor instance
Returns: A dictionary {loss_type: event_loss_table}
- job_id – the id of the current
-
openquake.engine.calculators.risk.event_based_risk.core.
save_individual_outputs
(outputdict, outputs, disagg_outputs, params)[source]¶ Save loss curves, loss maps and loss fractions associated with a calculation unit
Parameters: - outputdict – a
openquake.engine.calculators.risk.writers.OutputDict
instance holding the reference to the output container objects - outputs – a
openquake.risklib.workflows.ProbabilisticEventBased.Output
holding the output data for a calculation unit - disagg_outputs – a
DisaggregationOutputs
holding the disaggreation output data for a calculation unit - params – a
openquake.engine.calculators.risk.base.CalcParams
holding the parameters for this calculation
- outputdict – a
-
openquake.engine.calculators.risk.event_based_risk.core.
save_statistical_output
(outputdict, stats, params)[source]¶ Save statistical outputs (mean and quantile loss curves, mean and quantile loss maps) for the calculation.
Parameters: - outputdict – a
openquake.engine.calculators.risk.writers.OutputDict
instance holding the reference to the output container objects - stats –
class: openquake.risklib.workflows.ProbabilisticEventBased.StatisticalOutput holding the statistical output data
- params – a
openquake.engine.calculators.risk.base.CalcParams
holding the parameters for this calculation
- outputdict – a
Event-Based PSHA BCR Calculator¶
Core functionality for the Event Based BCR Risk calculator.
-
class
openquake.engine.calculators.risk.event_based_bcr.core.
EventBasedBCRRiskCalculator
(job)[source]¶ Bases:
openquake.engine.calculators.risk.event_based_risk.core.EventBasedRiskCalculator
Event based BCR risk calculator. Computes BCR distributions for a given set of assets.
-
agg_result
(acc, event_loss_tables)[source]¶ No need to update event loss tables in the BCR calculator
-
static
core
(workflow, getter, outputdict, params, monitor)¶ Celery task for the BCR risk calculator based on the event based calculator.
Instantiates risklib calculators, computes bcr and stores results to db in a single transaction.
Parameters: - job_id (int) – ID of the currently running job
- workflow – A
openquake.risklib.workflows.Workflow
instance - getter – A HazardGetter instance
- outputdict – An instance of
writers.OutputDict
containing output container instances (in this case only BCRDistribution) - params – An instance of
base.CalcParams
used to compute derived outputs - monitor – A monitor instance
-
output_builders
= [<class 'openquake.engine.calculators.risk.writers.BCRMapBuilder'>]¶
-
validators
= [<class 'openquake.engine.calculators.risk.validation.HazardIMT'>, <class 'openquake.engine.calculators.risk.validation.EmptyExposure'>, <class 'openquake.engine.calculators.risk.validation.OrphanTaxonomies'>, <class 'openquake.engine.calculators.risk.validation.ExposureLossTypes'>, <class 'openquake.engine.calculators.risk.validation.NoRiskModels'>, <class 'openquake.engine.calculators.risk.validation.ExposureHasInsuranceBounds'>, <class 'openquake.engine.calculators.risk.validation.ExposureHasRetrofittedCosts'>]¶
-
-
openquake.engine.calculators.risk.event_based_bcr.core.
event_based_bcr
(workflow, getter, outputdict, params, monitor)[source]¶ Celery task for the BCR risk calculator based on the event based calculator.
Instantiates risklib calculators, computes bcr and stores results to db in a single transaction.
Parameters: - job_id (int) – ID of the currently running job
- workflow – A
openquake.risklib.workflows.Workflow
instance - getter – A HazardGetter instance
- outputdict – An instance of
writers.OutputDict
containing output container instances (in this case only BCRDistribution) - params – An instance of
base.CalcParams
used to compute derived outputs - monitor – A monitor instance
Scenario Calculator¶
Core functionality for the scenario risk calculator.
-
class
openquake.engine.calculators.risk.scenario_risk.core.
ScenarioRiskCalculator
(job)[source]¶ Bases:
openquake.engine.calculators.risk.base.RiskCalculator
Scenario Risk Calculator. Computes a Loss Map, for a given set of assets.
-
agg_result
(*args)¶
-
static
core
(workflow, getter, outputdict, params, monitor)¶ Celery task for the scenario risk calculator.
Parameters: - workflow (list) – A
openquake.risklib.workflows.Workflow
instance - getter – A HazardGetter instance
- outputdict – An instance of
writers.OutputDict
containing output container instances (in this case only LossMap) - params – An instance of
base.CalcParams
used to compute derived outputs - monitor – A monitor instance
- workflow (list) – A
-
getter_class
¶ alias of
GroundMotionGetter
-
output_builders
= [<class 'openquake.engine.calculators.risk.writers.LossMapBuilder'>]¶
-
validators
= [<class 'openquake.engine.calculators.risk.validation.HazardIMT'>, <class 'openquake.engine.calculators.risk.validation.EmptyExposure'>, <class 'openquake.engine.calculators.risk.validation.OrphanTaxonomies'>, <class 'openquake.engine.calculators.risk.validation.ExposureLossTypes'>, <class 'openquake.engine.calculators.risk.validation.NoRiskModels'>, <class 'openquake.engine.calculators.risk.validation.ExposureHasInsuranceBounds'>, <class 'openquake.engine.calculators.risk.validation.ExposureHasTimeEvent'>]¶
-
-
openquake.engine.calculators.risk.scenario_risk.core.
scenario
(workflow, getter, outputdict, params, monitor)[source]¶ Celery task for the scenario risk calculator.
Parameters: - workflow (list) – A
openquake.risklib.workflows.Workflow
instance - getter – A HazardGetter instance
- outputdict – An instance of
writers.OutputDict
containing output container instances (in this case only LossMap) - params – An instance of
base.CalcParams
used to compute derived outputs - monitor – A monitor instance
- workflow (list) – A
-
openquake.engine.calculators.risk.scenario_risk.core.
workflow_argdict
(loss_type, assets, gmfs, epsilons)[source]¶ Parameters: - loss_type – loss type string
- assets – list of N assets
- gmfs – list of N ground motion arrays
- epsilons – list of N epsilon arrays
Returns: a dictionary with the loss_type and three lists with N - M elements, where M is the number of assets without value (usually 0).
Scenario Damage Calculator¶
Core functionality for the scenario_damage risk calculator.
-
class
openquake.engine.calculators.risk.scenario_damage.core.
ScenarioDamageRiskCalculator
(job)[source]¶ Bases:
openquake.engine.calculators.risk.base.RiskCalculator
Scenario Damage Risk Calculator. Computes four kinds of damage distributions: per asset, per taxonomy, total and collapse map.
Attr dict fragility_functions: A dictionary of dictionary mapping taxonomy -> (limit state -> fragility function) where a fragility function is an instance of openquake.risklib.scientific.FragilityFunctionContinuous
oropenquake.risklib.scientific.FragilityFunctionDiscrete
.-
agg_result
(*args)¶
-
static
core
(workflow, getter, outputdict, params, monitor)¶ The core calculation celery task function
-
getter_class
¶ alias of
GroundMotionGetter
-
output_builders
= []¶
-
validators
= [<class 'openquake.engine.calculators.risk.validation.HazardIMT'>, <class 'openquake.engine.calculators.risk.validation.EmptyExposure'>, <class 'openquake.engine.calculators.risk.validation.OrphanTaxonomies'>, <class 'openquake.engine.calculators.risk.validation.NoRiskModels'>]¶
-
-
openquake.engine.calculators.risk.scenario_damage.core.
scenario_damage
(workflow, getter, outputdict, params, monitor)[source]¶ Celery task for the scenario damage risk calculator.
param workflow: A openquake.risklib.workflows.Workflow
instanceparam getter: A HazardGetter instance param outputdict: An instance of writers.OutputDict
containing output container instances (in this case only LossMap)param params: An instance of base.CalcParams
used to compute derived outputsparam monitor: A monitor instance Returns: A matrix of fractions and a taxonomy string