openquake.calculators package¶
Subpackages¶
openquake.calculators.base module¶
-
exception
openquake.calculators.base.
AssetSiteAssociationError
[source]¶ Bases:
exceptions.Exception
Raised when there are no hazard sites close enough to any asset
-
class
openquake.calculators.base.
BaseCalculator
(oqparam, monitor=<Monitor dummy>, calc_id=None)[source]¶ Bases:
object
Abstract base class for all calculators.
Parameters: - oqparam – OqParam object
- monitor – monitor object
- calc_id – numeric calculation ID
-
assetcol
¶
-
csm
¶
-
execute
()[source]¶ Execution phase. Usually will run in parallel the core function and return a dictionary with the results.
-
export
(exports=None)[source]¶ Export all the outputs in the datastore in the given export formats.
Returns: dictionary output_key -> sorted list of exported paths
-
is_stochastic
= False¶
-
performance
¶
-
post_execute
(result)[source]¶ Post-processing phase of the aggregated output. It must be overridden with the export code. It will return a dictionary of output files.
-
pre_calculator
= None¶
-
run
(pre_execute=True, concurrent_tasks=None, close=True, **kw)[source]¶ Run the calculation and return the exported outputs.
-
sitecol
¶
-
taxonomies
¶
-
class
openquake.calculators.base.
HazardCalculator
(oqparam, monitor=<Monitor dummy>, calc_id=None)[source]¶ Bases:
openquake.calculators.base.BaseCalculator
Base class for hazard calculators based on source models
-
assoc_assets_sites
(sitecol)[source]¶ Parameters: sitecol – a sequence of sites Returns: a pair (filtered_sites, assets_by_site) The new site collection is different from the original one if some assets were discarded or if there were missing assets for some sites.
-
load_riskmodel
()[source]¶ Read the risk model and set the attribute .riskmodel. The riskmodel can be empty for hazard calculations. Save the loss ratios (if any) in the datastore.
-
pre_execute
()[source]¶ Check if there is a pre_calculator or a previous calculation ID. If yes, read the inputs by invoking the precalculator or by retrieving the previous calculation; if not, read the inputs directly.
-
read_exposure
()[source]¶ Read the exposure, the riskmodel and update the attributes .exposure, .sitecol, .assets_by_site, .taxonomies.
-
-
exception
openquake.calculators.base.
InvalidCalculationID
[source]¶ Bases:
exceptions.Exception
Raised when running a post-calculation on top of an incompatible pre-calculation
-
class
openquake.calculators.base.
RiskCalculator
(oqparam, monitor=<Monitor dummy>, calc_id=None)[source]¶ Bases:
openquake.calculators.base.HazardCalculator
Base class for all risk calculators. A risk calculator must set the attributes .riskmodel, .sitecol, .assets_by_site, .exposure .riskinputs in the pre_execute phase.
-
build_riskinputs
(hazards_by_rlz, eps=array([], dtype=float64))[source]¶ Parameters: - hazards_by_rlz – a dictionary rlz -> IMT -> array of length num_sites
- eps – a matrix of epsilons (possibly empty)
Returns: a list of RiskInputs objects, sorted by IMT.
-
execute
()[source]¶ Parallelize on the riskinputs and returns a dictionary of results. Require a .core_task to be defined with signature (riskinputs, riskmodel, rlzs_assoc, monitor).
-
extra_args
= ()¶
-
-
class
openquake.calculators.base.
Site
(sid, lon, lat)¶ Bases:
tuple
-
lat
¶ Alias for field number 2
-
lon
¶ Alias for field number 1
-
sid
¶ Alias for field number 0
-
-
openquake.calculators.base.
check_precalc_consistency
(calc_mode, precalc_mode)[source]¶ Defensive programming against users providing an incorrect pre-calculation ID (with
--hazard-calculation-id
)Parameters: - calc_mode – calculation_mode of the current calculation
- precalc_mode – calculation_mode of the previous calculation
-
openquake.calculators.base.
check_time_event
(oqparam, time_events)[source]¶ Check the time_event parameter in the datastore, by comparing with the periods found in the exposure.
-
openquake.calculators.base.
gsim_names
(rlz)[source]¶ Names of the underlying GSIMs separated by spaces
-
openquake.calculators.base.
set_array
(longarray, shortarray)[source]¶ Parameters: - longarray – a numpy array of floats of length L >= l
- shortarray – a numpy array of floats of length l
Fill longarray with the values of shortarray, starting from the left. If shortarry is shorter than longarray, then the remaining elements on the right are filled with numpy.nan values.
openquake.calculators.classical module¶
-
class
openquake.calculators.classical.
BBdict
(dic=None, accum=None, **kw)[source]¶ Bases:
openquake.baselib.general.AccumDict
A serializable dictionary containing bounding box information
-
dt
= dtype([('lt_model_id', '<u2'), ('site_id', '<u2'), ('min_dist', '<f8'), ('max_dist', '<f8'), ('east', '<f8'), ('west', '<f8'), ('south', '<f8'), ('north', '<f8')])¶
-
-
class
openquake.calculators.classical.
BoundingBox
(lt_model_id, site_id)[source]¶ Bases:
object
A class to store the bounding box in distances, longitudes and magnitudes, given a source model and a site. This is used for disaggregation calculations. The goal is to determine the minimum and maximum distances of the ruptures generated from the model from the site; moreover the maximum and minimum longitudes and magnitudes are stored, by taking in account the international date line.
-
bins_edges
(dist_bin_width, coord_bin_width)[source]¶ Define bin edges for disaggregation histograms, from the bin data collected from the ruptures.
Parameters: - dists – array of distances from the ruptures
- lons – array of longitudes from the ruptures
- lats – array of latitudes from the ruptures
- dist_bin_width – distance_bin_width from job.ini
- coord_bin_width – coordinate_bin_width from job.ini
-
-
class
openquake.calculators.classical.
ClassicalCalculator
(oqparam, monitor=<Monitor dummy>, calc_id=None)[source]¶ Bases:
openquake.calculators.classical.PSHACalculator
Classical PSHA calculator
-
core_task
(pmap_by_grp, sids, pstats, rlzs_assoc, monitor)¶ Parameters: - pmap_by_grp – dictionary of probability maps by source group ID
- sids – array of site IDs
- pstats – instance of PmapStats
- rlzs_assoc – instance of RlzsAssoc
- monitor – instance of Monitor
Returns: a dictionary kind -> ProbabilityMap
The “kind” is a string of the form ‘rlz-XXX’ or ‘mean’ of ‘quantile-XXX’ used to specify the kind of output.
-
gen_args
(pmap_by_grp)[source]¶ Parameters: pmap_by_grp – dictionary of ProbabilityMaps keyed by src_grp_id Yields: arguments for the function build_hcurves_and_stats
-
pre_calculator
= 'psha'¶
-
-
class
openquake.calculators.classical.
HazardCurve
(location, poes)¶ Bases:
tuple
-
location
¶ Alias for field number 0
-
poes
¶ Alias for field number 1
-
-
class
openquake.calculators.classical.
PSHACalculator
(oqparam, monitor=<Monitor dummy>, calc_id=None)[source]¶ Bases:
openquake.calculators.base.HazardCalculator
Classical PSHA calculator
-
agg_dicts
(acc, pmap)[source]¶ Aggregate dictionaries of hazard curves by updating the accumulator.
Parameters: - acc – accumulator dictionary
- pmap – a ProbabilityMap
-
core_task
(sources, src_filter, gsims, monitor)¶ Parameters: - sources – a non-empty sequence of sources of homogeneous tectonic region type
- src_filter – source filter
- gsims – a list of GSIMs for the current tectonic region type
- monitor – a monitor instance
Returns: an AccumDict rlz -> curves
-
count_eff_ruptures
(result_dict, src_group)[source]¶ Returns the number of ruptures in the src_group (after filtering) or 0 if the src_group has been filtered away.
Parameters: - result_dict – a dictionary with keys (grp_id, gsim)
- src_group – a SourceGroup instance
-
execute
()[source]¶ Run in parallel core_task(sources, sitecol, monitor), by parallelizing on the sources according to their weight and tectonic region type.
-
gen_args
(src_groups, oq, monitor)[source]¶ Used in the case of large source model logic trees.
Parameters: - src_groups – a list of SourceGroup instances
- oq – a
openquake.commonlib.oqvalidation.OqParam
instance - monitor – a
openquake.baselib.performance.Monitor
Yields: (sources, sites, gsims, monitor) tuples
-
post_execute
(pmap_by_grp_id)[source]¶ Collect the hazard curves by realization and export them.
Parameters: pmap_by_grp_id – a dictionary grp_id -> hazard curves
-
source_info
¶
-
-
openquake.calculators.classical.
build_hcurves_and_stats
(pmap_by_grp, sids, pstats, rlzs_assoc, monitor)[source]¶ Parameters: - pmap_by_grp – dictionary of probability maps by source group ID
- sids – array of site IDs
- pstats – instance of PmapStats
- rlzs_assoc – instance of RlzsAssoc
- monitor – instance of Monitor
Returns: a dictionary kind -> ProbabilityMap
The “kind” is a string of the form ‘rlz-XXX’ or ‘mean’ of ‘quantile-XXX’ used to specify the kind of output.
-
openquake.calculators.classical.
classical
(sources, src_filter, gsims, monitor)[source]¶ Parameters: - sources – a non-empty sequence of sources of homogeneous tectonic region type
- src_filter – source filter
- gsims – a list of GSIMs for the current tectonic region type
- monitor – a monitor instance
Returns: an AccumDict rlz -> curves
openquake.calculators.classical_bcr module¶
-
class
openquake.calculators.classical_bcr.
ClassicalBCRCalculator
(oqparam, monitor=<Monitor dummy>, calc_id=None)[source]¶ Bases:
openquake.calculators.classical_risk.ClassicalRiskCalculator
Classical BCR Risk calculator
-
core_task
(riskinput, riskmodel, bcr_dt, monitor)¶ Compute and return the average losses for each asset.
Parameters: - riskinput – a
openquake.risklib.riskinput.RiskInput
object - riskmodel – a
openquake.risklib.riskinput.CompositeRiskModel
instance - bcr_dt – data type with fields annual_loss_orig, annual_loss_retro, bcr
- monitor –
openquake.baselib.performance.Monitor
instance
- riskinput – a
-
-
openquake.calculators.classical_bcr.
classical_bcr
(riskinput, riskmodel, bcr_dt, monitor)[source]¶ Compute and return the average losses for each asset.
Parameters: - riskinput – a
openquake.risklib.riskinput.RiskInput
object - riskmodel – a
openquake.risklib.riskinput.CompositeRiskModel
instance - bcr_dt – data type with fields annual_loss_orig, annual_loss_retro, bcr
- monitor –
openquake.baselib.performance.Monitor
instance
- riskinput – a
openquake.calculators.classical_damage module¶
-
class
openquake.calculators.classical_damage.
ClassicalDamageCalculator
(oqparam, monitor=<Monitor dummy>, calc_id=None)[source]¶ Bases:
openquake.calculators.classical_risk.ClassicalRiskCalculator
Scenario damage calculator
-
check_poes
(curves_by_rlz)[source]¶ Raise an error if one PoE = 1, since it would produce a log(0) in
openquake.risklib.scientific.annual_frequency_of_exceedence
-
core_task
(riskinput, riskmodel, monitor)¶ Core function for a classical damage computation.
Parameters: - riskinput – a
openquake.risklib.riskinput.RiskInput
object - riskmodel – a
openquake.risklib.riskinput.CompositeRiskModel
instance - monitor –
openquake.baselib.performance.Monitor
instance
Returns: a nested dictionary rlz_idx -> asset -> <damage array>
- riskinput – a
-
-
openquake.calculators.classical_damage.
classical_damage
(riskinput, riskmodel, monitor)[source]¶ Core function for a classical damage computation.
Parameters: - riskinput – a
openquake.risklib.riskinput.RiskInput
object - riskmodel – a
openquake.risklib.riskinput.CompositeRiskModel
instance - monitor –
openquake.baselib.performance.Monitor
instance
Returns: a nested dictionary rlz_idx -> asset -> <damage array>
- riskinput – a
openquake.calculators.classical_risk module¶
-
class
openquake.calculators.classical_risk.
ClassicalRiskCalculator
(oqparam, monitor=<Monitor dummy>, calc_id=None)[source]¶ Bases:
openquake.calculators.base.RiskCalculator
Classical Risk calculator
-
core_task
(riskinput, riskmodel, monitor)¶ Compute and return the average losses for each asset.
Parameters: - riskinput – a
openquake.risklib.riskinput.RiskInput
object - riskmodel – a
openquake.risklib.riskinput.CompositeRiskModel
instance - monitor –
openquake.baselib.performance.Monitor
instance
- riskinput – a
-
pre_calculator
= 'classical'¶
-
-
openquake.calculators.classical_risk.
classical_risk
(riskinput, riskmodel, monitor)[source]¶ Compute and return the average losses for each asset.
Parameters: - riskinput – a
openquake.risklib.riskinput.RiskInput
object - riskmodel – a
openquake.risklib.riskinput.CompositeRiskModel
instance - monitor –
openquake.baselib.performance.Monitor
instance
- riskinput – a
openquake.calculators.disaggregation module¶
Disaggregation calculator core functionality
-
class
openquake.calculators.disaggregation.
DisaggregationCalculator
(oqparam, monitor=<Monitor dummy>, calc_id=None)[source]¶ Bases:
openquake.calculators.classical.ClassicalCalculator
Classical PSHA disaggregation calculator
-
agg_result
(acc, result)[source]¶ Collect the results coming from compute_disagg into self.results, a dictionary with key (sid, rlz.id, poe, imt, iml, trt_names) and values which are probability arrays.
Parameters: - acc – dictionary accumulating the results
- result – dictionary with the result coming from a task
-
get_curves
(sid)[source]¶ Get all the relevant hazard curves for the given site ordinal. Returns a dictionary {(rlz_id, imt) -> curve}.
-
save_disagg_result
(site_id, bin_edges, trt_names, matrix, rlz_id, investigation_time, imt_str, iml, poe)[source]¶ Save a computed disaggregation matrix to hzrdr.disagg_result (see
DisaggResult
).Parameters: - site_id – id of the current site
- bin_edges – The 5-uple mag, dist, lon, lat, eps
- trt_names – The list of Tectonic Region Types
- matrix – A probability array
- rlz_id – ordinal of the realization to which the results belong.
- investigation_time (float) – Investigation time (years) for the calculation.
- imt_str – Intensity measure type string (PGA, SA, etc.)
- iml (float) – Intensity measure level interpolated (using poe) from the hazard curve at the site.
- poe (float) – Disaggregation probability of exceedance value for this result.
-
-
openquake.calculators.disaggregation.
compute_disagg
(src_filter, sources, src_group_id, rlzs_assoc, trt_names, curves_dict, bin_edges, oqparam, monitor)[source]¶ Parameters: - src_filter – a
openquake.hazardlib.calc.filter.SourceFilter
instance - sources – list of hazardlib source objects
- src_group_id – numeric ID of a SourceGroup instance
- rlzs_assoc – a
openquake.commonlib.source.RlzsAssoc
instance - trt_names (dict) – a tuple of names for the given tectonic region type
- curves_dict – a dictionary with the hazard curves for sites, realizations and IMTs
- bin_egdes – a dictionary site_id -> edges
- oqparam – the parameters in the job.ini file
- monitor – monitor of the currently running job
Returns: a dictionary of probability arrays, with composite key (sid, rlz.id, poe, imt, iml, trt_names).
- src_filter – a
openquake.calculators.event_based module¶
-
class
openquake.calculators.event_based.
EventBasedCalculator
(oqparam, monitor=<Monitor dummy>, calc_id=None)[source]¶ Bases:
openquake.calculators.classical.ClassicalCalculator
Event based PSHA calculator generating the ground motion fields and the hazard curves from the ruptures, depending on the configuration parameters.
-
combine_pmaps_and_save_gmfs
(acc, res)[source]¶ Combine the hazard curves (if any) and save the gmfs (if any) sequentially; notice that the gmfs may come from different tasks in any order.
Parameters: - acc – an accumulator for the hazard curves
- res – a dictionary rlzi, imt -> [gmf_array, curves_by_imt]
Returns: a new accumulator
-
core_task
(getter, rlzs, monitor)¶ Parameters: - eb_ruptures – a list of blocks of EBRuptures of the same SESCollection
- sitecol – a
openquake.hazardlib.site.SiteCollection
instance - imts – a list of intensity measure type strings
- rlzs_by_gsim – a dictionary gsim -> associated realizations
- monitor – a Monitor instance
Returns: a dictionary with keys gmfcoll and hcurves
-
execute
()[source]¶ Run in parallel core_task(sources, sitecol, monitor), by parallelizing on the ruptures according to their weight and tectonic region type.
-
gen_args
(ruptures_by_grp)[source]¶ Parameters: ruptures_by_grp – a dictionary of EBRupture objects Yields: the arguments for compute_gmfs_and_curves
-
is_stochastic
= True¶
-
post_execute
(result)[source]¶ Parameters: result – a dictionary (src_group_id, gsim) -> haz_curves or an empty dictionary if hazard_curves_from_gmfs is false
-
pre_calculator
= 'event_based_rupture'¶
-
-
class
openquake.calculators.event_based.
EventBasedRuptureCalculator
(oqparam, monitor=<Monitor dummy>, calc_id=None)[source]¶ Bases:
openquake.calculators.classical.PSHACalculator
Event based PSHA calculator generating the ruptures only
-
agg_dicts
(acc, ruptures_by_grp_id)[source]¶ Accumulate dictionaries of ruptures and populate the events dataset in the datastore.
Parameters: - acc – accumulator dictionary
- ruptures_by_grp_id – a nested dictionary grp_id -> ruptures
-
core_task
(sources, src_filter, gsims, monitor)¶ Parameters: - sources – List of commonlib.source.Source tuples
- src_filter – a source site filter
- gsims – a list of GSIMs for the current tectonic region model
- monitor – monitor instance
Returns: a dictionary src_group_id -> [Rupture instances]
-
count_eff_ruptures
(ruptures_by_grp_id, src_group)[source]¶ Returns the number of ruptures sampled in the given src_group.
Parameters: - ruptures_by_grp_id – a dictionary with key grp_id
- src_group – a SourceGroup instance
-
init
()[source]¶ Set the random seed passed to the SourceManager and the minimum_intensity dictionary.
-
is_stochastic
= True¶
-
-
openquake.calculators.event_based.
build_eb_ruptures
(src, num_occ_by_rup, rupture_filter, random_seed, rup_mon)[source]¶ Filter the ruptures stored in the dictionary num_occ_by_rup and yield pairs (rupture, <list of associated EBRuptures>)
-
openquake.calculators.event_based.
compute_gmfs_and_curves
(getter, rlzs, monitor)[source]¶ Parameters: - eb_ruptures – a list of blocks of EBRuptures of the same SESCollection
- sitecol – a
openquake.hazardlib.site.SiteCollection
instance - imts – a list of intensity measure type strings
- rlzs_by_gsim – a dictionary gsim -> associated realizations
- monitor – a Monitor instance
Returns: a dictionary with keys gmfcoll and hcurves
-
openquake.calculators.event_based.
compute_ruptures
(sources, src_filter, gsims, monitor)[source]¶ Parameters: - sources – List of commonlib.source.Source tuples
- src_filter – a source site filter
- gsims – a list of GSIMs for the current tectonic region model
- monitor – monitor instance
Returns: a dictionary src_group_id -> [Rupture instances]
-
openquake.calculators.event_based.
get_mean_curves
(dstore)[source]¶ Extract the mean hazard curves from the datastore, as a composite array of length nsites.
-
openquake.calculators.event_based.
get_ruptures_by_grp
(dstore)[source]¶ Extracts the dictionary ruptures_by_grp from the given calculator
-
openquake.calculators.event_based.
sample_ruptures
(src, num_ses, num_samples, seed)[source]¶ Sample the ruptures contained in the given source.
Parameters: - src – a hazardlib source object
- num_ses – the number of Stochastic Event Sets to generate
- num_samples – how many samples for the given source
- seed – master seed from the job.ini file
Returns: a dictionary of dictionaries rupture -> {ses_id: num_occurrences}
openquake.calculators.event_based_risk module¶
-
class
openquake.calculators.event_based_risk.
EbrPostCalculator
(oqparam, monitor=<Monitor dummy>, calc_id=None)[source]¶ Bases:
openquake.calculators.base.RiskCalculator
-
build_agg_curve
()[source]¶ Build a single loss curve per realization. It is NOT obtained by aggregating the loss curves; instead, it is obtained without generating the loss curves, directly from the the aggregate losses.
-
pre_calculator
= 'ebrisk'¶
-
-
class
openquake.calculators.event_based_risk.
EbriskCalculator
(oqparam, monitor=<Monitor dummy>, calc_id=None)[source]¶ Bases:
openquake.calculators.base.RiskCalculator
Event based PSHA calculator generating the total losses by taxonomy
-
build_starmap
(sm_id, ruptures_by_grp, sitecol, assetcol, riskmodel, imts, trunc_level, correl_model, min_iml, monitor)[source]¶ Parameters: - sm_id – source model ordinal
- ruptures_by_grp – dictionary of ruptures by src_group_id
- sitecol – a SiteCollection instance
- assetcol – an AssetCollection instance
- riskmodel – a RiskModel instance
- imts – a list of Intensity Measure Types
- trunc_level – truncation level
- correl_model – correlation model
- min_iml – vector of minimum intensities, one per IMT
- monitor – a Monitor instance
Returns: a pair (Starmap, dictionary of attributes)
-
gen_args
(ruptures_by_grp)[source]¶ Yield the arguments required by build_ruptures, i.e. the source models, the asset collection, the riskmodel and others.
-
is_stochastic
= True¶
-
pre_calculator
= 'event_based_rupture'¶
-
-
class
openquake.calculators.event_based_risk.
EpsilonMatrix0
(num_assets, seeds)[source]¶ Bases:
object
Mock-up for a matrix of epsilons of size N x E, used when asset_correlation=0.
Parameters: - num_assets – N assets
- seeds – E seeds, set before calling numpy.random.normal
-
class
openquake.calculators.event_based_risk.
EpsilonMatrix1
(num_events, seed)[source]¶ Bases:
object
Mock-up for a matrix of epsilons of size N x E, used when asset_correlation=1.
Parameters: - num_events – number of events
- seed – seed used to generate E epsilons
-
openquake.calculators.event_based_risk.
build_agg_curve
(cb_inputs, monitor)[source]¶ Build the aggregate loss curve in parallel for each loss type and realization pair.
Parameters: - cb_inputs – a list of triples (cb, rlzname, data) where cb is a curve builder, rlzname is a string of kind rlz-%03d and data is an array of kind (rupture_id, loss) or (rupture_id, loss, loss_ins)
- monitor – a Monitor instance
Returns: a dictionary (r, l, i) -> (losses, poes, avg)
-
openquake.calculators.event_based_risk.
build_el_dtypes
(insured_losses)[source]¶ Parameters: insured_losses (bool) – job.ini configuration parameter Returns: ela_dt and elt_dt i.e. the data types for event loss assets and event loss table respectively
-
openquake.calculators.event_based_risk.
build_rcurves
(cb_inputs, assets, monitor)[source]¶ Parameters: - cb_inputs – triples (cb, rlzname, data)
- assets – full list of assets
- monitor – Monitor instance
-
openquake.calculators.event_based_risk.
event_based_risk
(riskinput, riskmodel, assetcol, monitor)[source]¶ Parameters: - riskinput – a
openquake.risklib.riskinput.RiskInput
object - riskmodel – a
openquake.risklib.riskinput.CompositeRiskModel
instance - assetcol – AssetCollection instance
- monitor –
openquake.baselib.performance.Monitor
instance
Returns: a dictionary of numpy arrays of shape (L, R)
- riskinput – a
openquake.calculators.scenario module¶
-
class
openquake.calculators.scenario.
ScenarioCalculator
(oqparam, monitor=<Monitor dummy>, calc_id=None)[source]¶ Bases:
openquake.calculators.base.HazardCalculator
Scenario hazard calculator
-
is_stochastic
= True¶
-
openquake.calculators.scenario_damage module¶
-
class
openquake.calculators.scenario_damage.
ScenarioDamageCalculator
(oqparam, monitor=<Monitor dummy>, calc_id=None)[source]¶ Bases:
openquake.calculators.base.RiskCalculator
Scenario damage calculator
-
core_task
(riskinput, riskmodel, monitor)¶ Core function for a damage computation.
Parameters: - riskinput – a
openquake.risklib.riskinput.RiskInput
object - riskmodel – a
openquake.risklib.riskinput.CompositeRiskModel
instance - monitor –
openquake.baselib.performance.Monitor
instance
Returns: - a dictionary {‘d_asset’: [(l, r, a, mean-stddev), ...],
‘d_taxonomy’: damage array of shape T, L, R, E, D, ‘c_asset’: [(l, r, a, mean-stddev), ...], ‘c_taxonomy’: damage array of shape T, L, R, E}
d_asset and d_taxonomy are related to the damage distributions whereas c_asset and c_taxonomy are the consequence distributions. If there is no consequence model c_asset is an empty list and c_taxonomy is a zero-value array.
- riskinput – a
-
is_stochastic
= True¶
-
post_execute
(result)[source]¶ Compute stats for the aggregated distributions and save the results on the datastore.
-
pre_calculator
= 'scenario'¶
-
-
openquake.calculators.scenario_damage.
dist_by_asset
(data, multi_stat_dt)[source]¶ Parameters: - data – array of shape (N, L, R, 2, ...)
- multi_stat_dt – numpy dtype for statistical outputs
Returns: array of shape (N, R) with records of type multi_stat_dt
-
openquake.calculators.scenario_damage.
dist_by_taxon
(data, multi_stat_dt)[source]¶ Parameters: - data – array of shape (T, L, R, ...)
- multi_stat_dt – numpy dtype for statistical outputs
Returns: array of shape (T, R) with records of type multi_stat_dt
-
openquake.calculators.scenario_damage.
dist_total
(data, multi_stat_dt)[source]¶ Parameters: - data – array of shape (T, L, R, ...)
- multi_stat_dt – numpy dtype for statistical outputs
Returns: array of shape (R,) with records of type multi_stat_dt
-
openquake.calculators.scenario_damage.
scenario_damage
(riskinput, riskmodel, monitor)[source]¶ Core function for a damage computation.
Parameters: - riskinput – a
openquake.risklib.riskinput.RiskInput
object - riskmodel – a
openquake.risklib.riskinput.CompositeRiskModel
instance - monitor –
openquake.baselib.performance.Monitor
instance
Returns: - a dictionary {‘d_asset’: [(l, r, a, mean-stddev), ...],
‘d_taxonomy’: damage array of shape T, L, R, E, D, ‘c_asset’: [(l, r, a, mean-stddev), ...], ‘c_taxonomy’: damage array of shape T, L, R, E}
d_asset and d_taxonomy are related to the damage distributions whereas c_asset and c_taxonomy are the consequence distributions. If there is no consequence model c_asset is an empty list and c_taxonomy is a zero-value array.
- riskinput – a
openquake.calculators.scenario_risk module¶
-
class
openquake.calculators.scenario_risk.
ScenarioRiskCalculator
(oqparam, monitor=<Monitor dummy>, calc_id=None)[source]¶ Bases:
openquake.calculators.base.RiskCalculator
Run a scenario risk calculation
-
core_task
(riskinput, riskmodel, monitor)¶ Core function for a scenario computation.
Parameters: - riskinput – a of
openquake.risklib.riskinput.RiskInput
object - riskmodel – a
openquake.risklib.riskinput.CompositeRiskModel
instance - monitor –
openquake.baselib.performance.Monitor
instance
Returns: a dictionary { ‘agg’: array of shape (E, L, R, 2), ‘avg’: list of tuples (lt_idx, rlz_idx, asset_idx, statistics) } where E is the number of simulated events, L the number of loss types, R the number of realizations and statistics is an array of shape (n, R, 4), with n the number of assets in the current riskinput object
- riskinput – a of
-
is_stochastic
= True¶
-
post_execute
(result)[source]¶ Compute stats for the aggregated distributions and save the results on the datastore.
-
pre_calculator
= 'scenario'¶
-
-
openquake.calculators.scenario_risk.
scenario_risk
(riskinput, riskmodel, monitor)[source]¶ Core function for a scenario computation.
Parameters: - riskinput – a of
openquake.risklib.riskinput.RiskInput
object - riskmodel – a
openquake.risklib.riskinput.CompositeRiskModel
instance - monitor –
openquake.baselib.performance.Monitor
instance
Returns: a dictionary { ‘agg’: array of shape (E, L, R, 2), ‘avg’: list of tuples (lt_idx, rlz_idx, asset_idx, statistics) } where E is the number of simulated events, L the number of loss types, R the number of realizations and statistics is an array of shape (n, R, 4), with n the number of assets in the current riskinput object
- riskinput – a of
openquake.calculators.ucerf_event_classical module¶
-
class
openquake.calculators.ucerf_classical.
UCERFClassicalCalculator
(oqparam, monitor=<Monitor dummy>, calc_id=None)[source]¶ Bases:
openquake.calculators.classical.ClassicalCalculator
-
pre_calculator
= 'ucerf_psha'¶
-
-
class
openquake.calculators.ucerf_classical.
UCERFControl
(source_file, id, investigation_time, min_mag, npd=<openquake.hazardlib.pmf.PMF object>, hdd=<openquake.hazardlib.pmf.PMF object>, aspect=1.5, upper_seismogenic_depth=0.0, lower_seismogenic_depth=15.0, msr=<WC1994>, mesh_spacing=1.0, trt='Active Shallow Crust', integration_distance=1000)[source]¶ Bases:
openquake.calculators.ucerf_event_based.UCERFSESControl
General control file for a UCERF branch for the classical calculator. Here we add a new method to generate a set of background sources per branch
-
filter_sites_by_distance_from_rupture_set
(rupset_idx, sites, max_dist)[source]¶ Filter sites by distances from a set of ruptures
-
-
class
openquake.calculators.ucerf_classical.
UcerfPSHACalculator
(oqparam, monitor=<Monitor dummy>, calc_id=None)[source]¶ Bases:
openquake.calculators.classical.PSHACalculator
UCERF classical calculator.
-
core_task
(branchname, ucerf_source, src_group_id, src_filter, gsims, monitor)¶ Parameters: - branchname – a branch name
- ucerf_source – a source-like object for the UCERF model
- src_group_id – an ordinal number for the source
- filter (source) – a filter returning the sites affected by the source
- gsims – a list of GSIMs
- monitor – a monitor instance
Returns: an AccumDict rlz -> curves
-
execute
()[source]¶ Run in parallel core_task(sources, sitecol, monitor), by parallelizing on the sources according to their weight and tectonic region type.
-
gen_args
(branches, ucerf_source, monitor)[source]¶ Yields: (branch, ucerf_source, grp_id, self.sitecol, gsims, monitor)
-
is_stochastic
= False¶
-
-
openquake.calculators.ucerf_classical.
convert_UCERFSource
(self, node)[source]¶ Converts the Ucerf Source node into an SES Control object
-
openquake.calculators.ucerf_classical.
hazard_curves_per_rupture_subset
(rupset_idx, ucerf_source, src_filter, imtls, cmaker, truncation_level=None, monitor=<Monitor dummy>)[source]¶ Calculates the probabilities of exceedence from a set of rupture indices
-
openquake.calculators.ucerf_classical.
ucerf_classical_hazard_by_branch
(branchname, ucerf_source, src_group_id, src_filter, gsims, monitor)[source]¶ Parameters: - branchname – a branch name
- ucerf_source – a source-like object for the UCERF model
- src_group_id – an ordinal number for the source
- filter (source) – a filter returning the sites affected by the source
- gsims – a list of GSIMs
- monitor – a monitor instance
Returns: an AccumDict rlz -> curves
-
openquake.calculators.ucerf_classical.
ucerf_classical_hazard_by_rupture_set
(rupset_idx, branchname, ucerf_source, src_group_id, src_filter, gsims, monitor)[source]¶ Parameters: - rupset_idx – indices of the rupture sets
- branchname – name of the branch
- ucerf_source – an object taking the place of a source for UCERF
- src_group_id – source group index
- src_filter – a source filter returning the sites affected by the source
- gsims – a list of GSIMs
- monitor – a monitor instance
Returns: an AccumDict rlz -> curves
-
openquake.calculators.ucerf_classical.
ucerf_poe_map
(hdf5, ucerf_source, rupset_idx, s_sites, imtls, cmaker, trunclevel, ctx_mon, pne_mon)[source]¶ Compute a ProbabilityMap generated by the given set of indices.
Parameters: - hdf5 – UCERF file as instance of open h5py.File object
- ucerf_source – UCERFControl object
- rupset_idx (list) – List of rupture indices
openquake.calculators.ucerf_event_based module¶
-
class
openquake.calculators.ucerf_event_based.
EBR
(serial, source_id, events)¶ Bases:
tuple
-
events
¶ Alias for field number 2
-
serial
¶ Alias for field number 0
-
source_id
¶ Alias for field number 1
-
-
class
openquake.calculators.ucerf_event_based.
ImperfectPlanarSurface
(mesh_spacing, strike, dip, top_left, top_right, bottom_right, bottom_left)[source]¶ Bases:
openquake.hazardlib.geo.surface.planar.PlanarSurface
The planar surface class sets a narrow tolerance for the rectangular plane to be distorted in cartesian space. Ruptures with aspect ratios << 1.0, and with a dip of less than 90 degrees, cannot be generated in a manner that is consistent with the definitions - and thus cannot be instantiated. This subclass modifies the original planar surface class such that the tolerance checks are over-ridden. We find that distance errors with respect to a simple fault surface with a mesh spacing of 0.001 km are only on the order of < 0.15 % for Rrup (< 2 % for Rjb, < 3.0E-5 % for Rx)
-
IMPERFECT_RECTANGLE_TOLERANCE
= inf¶
-
-
class
openquake.calculators.ucerf_event_based.
List
[source]¶ Bases:
list
Trivial container returned by compute_losses
-
class
openquake.calculators.ucerf_event_based.
UCERFRiskCalculator
(oqparam, monitor=<Monitor dummy>, calc_id=None)[source]¶ Bases:
openquake.calculators.event_based_risk.EbriskCalculator
Event based risk calculator for UCERF, parallelizing on the source models
-
gen_args
()[source]¶ Yield the arguments required by build_ruptures, i.e. the source models, the asset collection, the riskmodel and others.
-
pre_execute
()¶ parse the logic tree and source model input
-
-
class
openquake.calculators.ucerf_event_based.
UCERFRuptureCalculator
(oqparam, monitor=<Monitor dummy>, calc_id=None)[source]¶ Bases:
openquake.calculators.event_based.EventBasedRuptureCalculator
Event based PSHA calculator generating the ruptures only
-
is_stochastic
= True¶
-
-
class
openquake.calculators.ucerf_event_based.
UCERFSESControl
(source_file, id, investigation_time, min_mag, npd=<openquake.hazardlib.pmf.PMF object>, hdd=<openquake.hazardlib.pmf.PMF object>, aspect=1.5, upper_seismogenic_depth=0.0, lower_seismogenic_depth=15.0, msr=<WC1994>, mesh_spacing=1.0, trt='Active Shallow Crust', integration_distance=1000)[source]¶ Bases:
object
Parameters: - source_file – Path to an existing HDF5 file containing the UCERF model
- id (str) – Valid branch of UCERF
- investigation_time (float) – Investigation time of event set (years)
- min_mag (float) – Minimim magnitude for consideration of background sources
- npd – Nodal plane distribution as instance of :class: openquake.hazardlib.pmf.PMF
- hdd – Hypocentral depth distribution as instance of :class: openquake.hazardlib.pmf.PMF
- aspect (float) – Aspect ratio
- upper_seismoge nic_depth (float) – Upper seismogenic depth (km)
- lower_seismogenic_depth (float) – Lower seismogenic depth (km)
- msr – Magnitude scaling relation
- mesh_spacing (float) – Spacing (km) of fault mesh
- trt (str) – Tectonic region type
- integration_distance (float) – Maximum distance from rupture to site for consideration
-
build_idx_set
()[source]¶ Builds a dictionary of indices based on the branch code
Parameters: branch_code (str) – Code for the branch
-
generate_event_set
(background_sids)[source]¶ Generates the event set corresponding to a particular branch
-
openquake.calculators.ucerf_event_based.
compute_events
(sources, sitecol, gsims, monitor)[source]¶ Parameters: - sources – a sequence of UCERF sources
- sitecol – a SiteCollection instance
- gsims – a list of GSIMs
- monitor – a Monitor instance
Returns: an AccumDict grp_id -> EBRs
-
openquake.calculators.ucerf_event_based.
compute_losses
(ssm, sitecol, assetcol, riskmodel, imts, trunc_level, correl_model, min_iml, monitor)[source]¶ Compute the losses for a single source model.
Parameters: - ssm – CompositeSourceModel containing a single source model
- sitecol – a SiteCollection instance
- assetcol – an AssetCollection instance
- riskmodel – a RiskModel instance
- imts – a list of Intensity Measure Types
- trunc_level – truncation level
- correl_model – correlation model
- min_iml – vector of minimum intensities, one per IMT
- monitor – a Monitor instance
Returns: a List containing the losses by taxonomy and some attributes
-
openquake.calculators.ucerf_event_based.
compute_ruptures
(sources, sitecol, gsims, monitor)[source]¶ Parameters: - sources – a sequence of UCERF sources
- sitecol – a SiteCollection instance
- gsims – a list of GSIMs
- monitor – a Monitor instance
Returns: an AccumDict grp_id -> EBRuptures
-
openquake.calculators.ucerf_event_based.
convert_UCERFSource
(self, node)[source]¶ Converts the Ucerf Source node into an SES Control object
-
openquake.calculators.ucerf_event_based.
generate_background_ruptures
(tom, locations, occurrence, mag, npd, hdd, upper_seismogenic_depth, lower_seismogenic_depth, msr=<WC1994>, aspect=1.5, trt='Active Shallow Crust')[source]¶ Parameters: - tom – Temporal occurrence model as instance of :class: openquake.hazardlib.tom.TOM
- locations (numpy.ndarray) – Array of locations [Longitude, Latitude] of the point sources
- occurrence (numpy.ndarray) – Annual rates of occurrence
- mag (float) – Magnitude
- npd – Nodal plane distribution as instance of :class: openquake.hazardlib.pmf.PMF
- hdd – Hypocentral depth distribution as instance of :class: openquake.hazardlib.pmf.PMF
- upper_seismogenic_depth (float) – Upper seismogenic depth (km)
- lower_seismogenic_depth (float) – Lower seismogenic depth (km)
- msr – Magnitude scaling relation
- aspect (float) – Aspect ratio
- trt (str) – Tectonic region type
Returns: List of ruptures
-
openquake.calculators.ucerf_event_based.
get_rupture_dimensions
(mag, nodal_plane, msr, rupture_aspect_ratio, upper_seismogenic_depth, lower_seismogenic_depth)[source]¶ Calculate and return the rupture length and width for given magnitude
mag
and nodal plane.Parameters: nodal_plane – Instance of openquake.hazardlib.geo.nodalplane.NodalPlane
.Returns: Tuple of two items: rupture length in width in km. The rupture area is calculated using method
get_median_area()
of source’s magnitude-scaling relationship. In any case the returned dimensions multiplication is equal to that value. Than the area is decomposed to length and width with respect to source’s rupture aspect ratio.If calculated rupture width being inclined by nodal plane’s dip angle would not fit in between upper and lower seismogenic depth, the rupture width is shrunken to a maximum possible and rupture length is extended to preserve the same area.
-
openquake.calculators.ucerf_event_based.
get_rupture_surface
(mag, nodal_plane, hypocenter, msr, rupture_aspect_ratio, upper_seismogenic_depth, lower_seismogenic_depth, mesh_spacing=1.0)[source]¶ Create and return rupture surface object with given properties.
Parameters: - mag – Magnitude value, used to calculate rupture dimensions,
see
_get_rupture_dimensions()
. - nodal_plane – Instance of
openquake.hazardlib.geo.nodalplane.NodalPlane
describing the rupture orientation. - hypocenter – Point representing rupture’s hypocenter.
Returns: Instance of
PlanarSurface
.- mag – Magnitude value, used to calculate rupture dimensions,
see
-
openquake.calculators.ucerf_event_based.
get_ucerf_rupture
(hdf5, iloc, idx_set, tom, sites, integration_distance, mesh_spacing=1.0, trt='Active Shallow Crust')[source]¶ Parameters: - hdf5 – Source Model hdf5 object as instance of :class: h5py.File
- iloc (int) – Location of the rupture plane in the hdf5 file
- idx_set (dict) – Set of indices for the branch
- tom – Temporal occurrence model as instance of :class: openquake.hazardlib.tom.TOM
- sites – Sites for consideration (can be None!)
-
openquake.calculators.ucerf_event_based.
prefilter_background_model
(hdf5, branch_key, sites, integration_distance, msr=<WC1994>, aspect=1.5)[source]¶ Identify those points within the integration distance
Parameters: - sites – Sites under consideration
- integration_distance (float) – Maximum distance from rupture to site for consideration
- msr – Magnitude scaling relation
- aspect (float) – Aspect ratio
Returns: List of site IDs within the integration distance
-
openquake.calculators.ucerf_event_based.
prefilter_ruptures
(hdf5, ridx, idx_set, sites, integration_distance)[source]¶ Determines if a rupture is likely to be inside the integration distance by considering the set of fault plane centroids.
Parameters: - hdf5 – Source of UCERF file as h5py.File object
- ridx (list) – List of indices composing the rupture sections
- idx_set (dict) – Set of indices for the branch
- sites – Sites for consideration (can be None!)
- integration_distance (float) – Maximum distance from rupture to site for consideration
-
openquake.calculators.ucerf_event_based.
sample_background_model
(hdf5, branch_key, tom, filter_idx, min_mag, npd, hdd, upper_seismogenic_depth, lower_seismogenic_depth, msr=<WC1994>, aspect=1.5, trt='Active Shallow Crust')[source]¶ Generates a rupture set from a sample of the background model
Parameters: - branch_key – Key to indicate the branch for selecting the background model
- tom – Temporal occurrence model as instance of :class: openquake.hazardlib.tom.TOM
- filter_idx – Sites for consideration (can be None!)
- min_mag (float) – Minimim magnitude for consideration of background sources
- npd – Nodal plane distribution as instance of :class: openquake.hazardlib.pmf.PMF
- hdd – Hypocentral depth distribution as instance of :class: openquake.hazardlib.pmf.PMF
- aspect (float) – Aspect ratio
- upper_seismogenic_depth (float) – Upper seismogenic depth (km)
- lower_seismogenic_depth (float) – Lower seismogenic depth (km)
- msr – Magnitude scaling relation
- integration_distance (float) – Maximum distance from rupture to site for consideration
openquake.calculators.views module¶
-
openquake.calculators.views.
avglosses_data_transfer
(token, dstore)[source]¶ Determine the amount of average losses transferred from the workers to the controller node in a risk calculation.
-
openquake.calculators.views.
classify_gsim_lt
(gsim_lt)[source]¶ Returns: “trivial”, “simple” or “complex”
-
openquake.calculators.views.
ebr_data_transfer
(token, dstore)[source]¶ Display the data transferred in an event based risk calculation
-
openquake.calculators.views.
form
(value)[source]¶ Format numbers in a nice way.
>>> form(0) '0' >>> form(0.0) '0.0' >>> form(0.0001) '1.000E-04' >>> form(1003.4) '1,003' >>> form(103.4) '103' >>> form(9.3) '9.300' >>> form(-1.2) '-1.2'
-
openquake.calculators.views.
performance_view
(dstore)[source]¶ Returns the performance view as a numpy array.
-
openquake.calculators.views.
rst_table
(data, header=None, fmt=None)[source]¶ Build a .rst table from a matrix.
>>> tbl = [['a', 1], ['b', 2]] >>> print(rst_table(tbl, header=['Name', 'Value'])) ==== ===== Name Value ==== ===== a 1 b 2 ==== =====
-
openquake.calculators.views.
stats
(name, array, *extras)[source]¶ Returns statistics from an array of numbers.
Parameters: name – a descriptive string Returns: (name, mean, std, min, max, len)
-
openquake.calculators.views.
sum_table
(records)[source]¶ Used to compute summaries. The records are assumed to have numeric fields, except the first field which is ignored, since it typically contains a label. Here is an example:
>>> sum_table([('a', 1), ('b', 2)]) ['total', 3]
-
openquake.calculators.views.
sum_tbl
(tbl, kfield, vfields)[source]¶ Aggregate a composite array and compute the totals on a given key.
>>> dt = numpy.dtype([('name', (bytes, 10)), ('value', int)]) >>> tbl = numpy.array([('a', 1), ('a', 2), ('b', 3)], dt) >>> sum_tbl(tbl, 'name', ['value'])['value'] array([3, 3])
-
openquake.calculators.views.
view_assetcol
(token, dstore)[source]¶ Display the exposure in CSV format
-
openquake.calculators.views.
view_assets_by_site
(token, dstore)[source]¶ Display statistical information about the distribution of the assets
-
openquake.calculators.views.
view_contents
(token, dstore)[source]¶ Returns the size of the contents of the datastore and its total size
-
openquake.calculators.views.
view_exposure_info
(token, dstore)[source]¶ Display info about the exposure model
-
openquake.calculators.views.
view_fullreport
(token, dstore)[source]¶ Display an .rst report about the computation
-
openquake.calculators.views.
view_job_info
(token, dstore)[source]¶ Determine the amount of data transferred from the controller node to the workers and back in a classical calculation.
-
openquake.calculators.views.
view_loss_curves_avg
(token, dstore)[source]¶ Returns the average losses computed from the loss curves; for each asset shows all realizations.
-
openquake.calculators.views.
view_performance
(token, dstore)[source]¶ Display performance information
-
openquake.calculators.views.
view_portfolio_loss
(token, dstore)[source]¶ The loss for the full portfolio, for each realization and loss type, extracted from the event loss table.
-
openquake.calculators.views.
view_required_params_per_trt
(token, dstore)[source]¶ Display the parameters needed by each tectonic region type
-
openquake.calculators.views.
view_slow_sources
(token, dstore, maxrows=20)[source]¶ Returns the slowest sources
-
openquake.calculators.views.
view_task_durations
(token, dstore)[source]¶ Display the raw task durations. Here is an example of usage:
$ oq show task_durations:classical
-
openquake.calculators.views.
view_task_info
(token, dstore)[source]¶ Display statistical information about the tasks performance. It is possible to get full information about a specific task with a command like this one, for a classical calculation:
$ oq show task_info:classical
-
openquake.calculators.views.
view_task_slowest
(token, dstore)[source]¶ Display info about the slowest classical task.
-
openquake.calculators.views.
view_times_by_source_class
(token, dstore)[source]¶ Returns the calculation times depending on the source typology
-
openquake.calculators.views.
view_totlosses
(token, dstore)[source]¶ This is a debugging view. You can use it to check that the total losses, i.e. the losses obtained by summing the average losses on all assets are indeed equal to the aggregate losses. This is a sanity check for the correctness of the implementation.