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.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
get_data()[source]

Shortcut returning the hazard data when there is a single realization

get_hazards()[source]

Return a list of Hazard instances for the given IMT.

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.

init_assocs()[source]

Stores the associations asset <-> site into the database

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)
openquake.engine.calculators.risk.hazard_getters.haz_out_to_ses_coll(ho)[source]
openquake.engine.calculators.risk.hazard_getters.make_epsilons(asset_count, num_samples, seed, correlation)[source]
Parameters:
  • asset_count (int) – the number of assets
  • num_ruptures (int) – the number of ruptures
  • seed (int) – a random seed
  • correlation (float) – the correlation coefficient

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.

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'>]
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.

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
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

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.ExposureHasRetrofittedCosts'>]
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

Small wrapper around the oq-lite event based risk calculator

class openquake.engine.calculators.risk.event_based_risk.core.EBRCalculator(job)[source]

Bases: openquake.calculators.event_based_risk.EventBasedRiskCalculator

Smaller Event Based risk calculator for the event loss table.

clean_up()[source]

Scenario Calculator

Core functionality for the scenario risk calculator.

class openquake.engine.calculators.risk.scenario_risk.core.ScenarioRiskCalculator(job)[source]

Bases: openquake.calculators.scenario_risk.ScenarioRiskCalculator

Scenario Risk calculator. Computes damage distributions.

clean_up()[source]

Scenario Damage Calculator

Core functionality for the scenario_damage risk calculator.

class openquake.engine.calculators.risk.scenario_damage.core.ScenarioDamageCalculator(job)[source]

Bases: openquake.calculators.scenario_damage.ScenarioDamageCalculator

Scenario Damage calculator. Computes damage distributions.

clean_up()[source]