openquake.calculators package¶
Subpackages¶
base module¶
-
class
openquake.calculators.base.
BaseCalculator
(oqparam, calc_id)[source]¶ Bases:
object
Abstract base class for all calculators.
Parameters: - oqparam – OqParam object
- monitor – monitor object
- calc_id – numeric calculation ID
-
accept_precalc
= []¶
-
check_precalc
(precalc_mode)[source]¶ Defensive programming against users providing an incorrect pre-calculation ID (with
--hazard-calculation-id
).Parameters: precalc_mode – calculation_mode of the previous calculation
-
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. Individual outputs are not exported if there are multiple realizations.
-
from_engine
= False¶
-
is_stochastic
= False¶
-
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.
-
precalc
= None¶
-
class
openquake.calculators.base.
HazardCalculator
(oqparam, calc_id)[source]¶ Bases:
openquake.calculators.base.BaseCalculator
Base class for hazard calculators based on source models
-
E
¶ Returns: the number of stored events
-
N
¶ Returns: the total number of sites
-
R
¶ Returns: the number of realizations
-
few_sites
¶ Returns: True if there are less than max_sites_disagg
-
load_crmodel
()[source]¶ Read the risk models and set the attribute .crmodel. The crmodel can be empty for hazard calculations. Save the loss ratios (if any) in the datastore.
-
load_insurance_data
(ins_types, ins_files)[source]¶ Read the insurance files and populate the policy_dict
-
pre_execute
()[source]¶ Check if there is a previous calculation ID. If yes, read the inputs by retrieving the previous calculation; if not, read the inputs directly.
-
read_exposure
(haz_sitecol)[source]¶ Read the exposure, the risk models and update the attributes .sitecol, .assetcol
-
-
exception
openquake.calculators.base.
InvalidCalculationID
[source]¶ Bases:
Exception
Raised when running a post-calculation on top of an incompatible pre-calculation
-
class
openquake.calculators.base.
RiskCalculator
(oqparam, calc_id)[source]¶ Bases:
openquake.calculators.base.HazardCalculator
Base class for all risk calculators. A risk calculator must set the attributes .crmodel, .sitecol, .assetcol, .riskinputs in the pre_execute phase.
-
build_riskinputs
(kind)[source]¶ Parameters: kind – kind of hazard getter, can be ‘poe’ or ‘gmf’ 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, crmodel, param, monitor).
-
-
openquake.calculators.base.
build_hmaps
(hcurves_by_kind, slice_, imtls, poes, monitor)[source]¶ Build hazard maps from a slice of hazard curves. :returns: a pair ({kind: hmaps}, slice)
-
openquake.calculators.base.
build_weights
(realizations, imt_dt)[source]¶ Returns: an array with the realization weights of shape R
-
openquake.calculators.base.
check_amplification
(dstore)[source]¶ Make sure the amplification codes in the site collection match the ones in the amplification table
-
openquake.calculators.base.
check_time_event
(oqparam, occupancy_periods)[source]¶ Check the time_event parameter in the datastore, by comparing with the periods found in the exposure.
-
openquake.calculators.base.
consistent
(dic1, dic2)[source]¶ Check if two dictionaries with default are consistent:
>>> consistent({'PGA': 0.05, 'SA(0.3)': 0.05}, {'default': 0.05}) True >>> consistent({'SA(0.3)': 0.1, 'SA(0.6)': 0.05}, ... {'default': 0.1, 'SA(0.3)': 0.1, 'SA(0.6)': 0.05}) True
-
openquake.calculators.base.
fix_ones
(pmap)[source]¶ Physically, an extremely small intensity measure level can have an extremely large probability of exceedence, however that probability cannot be exactly 1 unless the level is exactly 0. Numerically, the PoE can be 1 and this give issues when calculating the damage (there is a log(0) in
openquake.risklib.scientific.annual_frequency_of_exceedence
). Here we solve the issue by replacing the unphysical probabilities 1 with .9999999999999999 (the float64 closest to 1).
-
openquake.calculators.base.
get_calc
(job_ini, calc_id)[source]¶ Factory function returning a Calculator instance
Parameters: - job_ini – path to job.ini file
- calc_id – calculation ID
-
openquake.calculators.base.
import_gmfs
(dstore, fname, sids)[source]¶ Import in the datastore a ground motion field CSV file.
Parameters: - dstore – the datastore
- fname – the CSV file
- sids – the site IDs (complete)
Returns: event_ids, num_rlzs
-
openquake.calculators.base.
save_exposed_values
(dstore, assetcol, lossnames, tagnames)[source]¶ Store 2^n arrays where n is the number of tagNames. For instance with the tags country, occupancy it stores 2^2 = 4 arrays:
exposed_values/agg_country_occupancy # shape (T1, T2, L) exposed_values/agg_country # shape (T1, L) exposed_values/agg_occupancy # shape (T2, L) exposed_values/agg # shape (L,)
-
openquake.calculators.base.
save_gmf_data
(dstore, sitecol, gmfs, imts, events=())[source]¶ Parameters: - dstore – a
openquake.baselib.datastore.DataStore
instance - sitecol – a
openquake.hazardlib.site.SiteCollection
instance - gmfs – an array of shape (N, E, M)
- imts – a list of IMT strings
- events – E event IDs or the empty tuple
- dstore – a
-
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.
getters module¶
-
class
openquake.calculators.getters.
GmfDataGetter
(dstore, sids, num_rlzs)[source]¶ Bases:
collections.abc.Mapping
A dictionary-like object {sid: dictionary by realization index}
-
class
openquake.calculators.getters.
GmfGetter
(rupgetter, srcfilter, oqparam, amplifier=None)[source]¶ Bases:
object
An hazard getter with methods .get_gmfdata and .get_hazard returning ground motion values.
-
compute_gmfs_curves
(rlzs, monitor)[source]¶ Parameters: rlzs – an array of shapeE Returns: a dict with keys gmfdata, indices, hcurves
-
get_hazard_by_sid
(data=None)[source]¶ Parameters: data – if given, an iterator of records of dtype gmf_dt Returns: sid -> records
-
imtls
¶
-
imts
¶
-
sids
¶
-
-
class
openquake.calculators.getters.
PmapGetter
(dstore, weights, sids=None, poes=())[source]¶ Bases:
object
Read hazard curves from the datastore for all realizations or for a specific realization.
Parameters: - dstore – a DataStore instance or file system path to it
- sids – the subset of sites to consider (if None, all sites)
-
get
(rlzi, grp=None)[source]¶ Parameters: - rlzi – a realization index
- grp – None (all groups) or a string of the form “grp-XX”
Returns: the hazard curves for the given realization
-
get_hazard
(gsim=None)[source]¶ Parameters: gsim – ignored Returns: R probability curves for the given site
-
get_mean
(grp=None)[source]¶ Compute the mean curve as a ProbabilityMap
Parameters: grp – if not None must be a string of the form “grp-XX”; in that case returns the mean considering only the contribution for group XX
-
get_pcurve
(s, r, g)[source]¶ Parameters: - s – site ID
- r – realization ID
- g – group ID
Returns: a probability curves with shape L (or None, if missing)
-
imts
¶
-
items
(kind='')[source]¶ Extract probability maps from the datastore, possibly generating on the fly the ones corresponding to the individual realizations. Yields pairs (tag, pmap).
Parameters: kind – the kind of PoEs to extract; if not given, returns the realization if there is only one or the statistics otherwise.
-
class
openquake.calculators.getters.
RuptureGetter
(proxies, filename, grp_id, trt, samples, rlzs_by_gsim)[source]¶ Bases:
object
Parameters: - proxies – a list of RuptureProxies
- filename – path to the HDF5 file containing a ‘rupgeoms’ dataset
- grp_id – source group index
- trt – tectonic region type string
- samples – number of samples of the group
- rlzs_by_gsim – dictionary gsim -> rlzs for the group
-
num_ruptures
¶
-
openquake.calculators.getters.
build_stat_curve
(poes, imtls, stat, weights)[source]¶ Build statistics by taking into account IMT-dependent weights
-
openquake.calculators.getters.
gen_rgetters
(dstore, slc=slice(None, None, None))[source]¶ Yields: unfiltered RuptureGetters
-
openquake.calculators.getters.
gen_rupture_getters
(dstore, srcfilter, ct)[source]¶ Parameters: - dstore – a
openquake.baselib.datastore.DataStore
- srcfilter – a
openquake.hazardlib.calc.filters.SourceFilter
- ct – number of concurrent tasks
Yields: filtered RuptureGetters
- dstore – a
classical module¶
-
class
openquake.calculators.classical.
ClassicalCalculator
(oqparam, calc_id)[source]¶ Bases:
openquake.calculators.base.HazardCalculator
Classical PSHA calculator
-
accept_precalc
= ['classical']¶
-
agg_dicts
(acc, dic)[source]¶ Aggregate dictionaries of hazard curves by updating the accumulator.
Parameters: - acc – accumulator dictionary
- dic – dict with keys pmap, calc_times, rup_data
-
core_task
(srcs, srcfilter, gsims, params, monitor)¶ Split the given sources, filter the subsources and the compute the PoEs. Yield back subtasks if the split sources contain more than maxweight ruptures.
-
execute
()[source]¶ Run in parallel core_task(sources, sitecol, monitor), by parallelizing on the sources according to their weight and tectonic region type.
-
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
-
-
class
openquake.calculators.classical.
PreCalculator
(oqparam, calc_id)[source]¶ Bases:
openquake.calculators.classical.ClassicalCalculator
Calculator to filter the sources and compute the number of effective ruptures
-
core_task
(srcs, srcfilter, gsims, params, monitor)¶ Split and prefilter the sources
-
-
openquake.calculators.classical.
build_hazard
(pgetter, N, hstats, individual_curves, max_sites_disagg, amplifier, monitor)[source]¶ Parameters: - pgetter – an
openquake.commonlib.getters.PmapGetter
- N – the total number of sites
- hstats – a list of pairs (statname, statfunc)
- individual_curves – if True, also build the individual curves
- max_sites_disagg – if there are less sites than this, store rup info
- amplifier – instance of Amplifier or None
- 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.
- pgetter – an
-
openquake.calculators.classical.
classical_split_filter
(srcs, srcfilter, gsims, params, monitor)[source]¶ Split the given sources, filter the subsources and the compute the PoEs. Yield back subtasks if the split sources contain more than maxweight ruptures.
classical_bcr module¶
-
class
openquake.calculators.classical_bcr.
ClassicalBCRCalculator
(oqparam, calc_id)[source]¶ Bases:
openquake.calculators.classical_risk.ClassicalRiskCalculator
Classical BCR Risk calculator
-
accept_precalc
= ['classical']¶
-
core_task
(riskinputs, crmodel, param, monitor)¶ Compute and return the average losses for each asset.
Parameters: - riskinputs –
openquake.risklib.riskinput.RiskInput
objects - crmodel – a
openquake.risklib.riskinput.CompositeRiskModel
instance - param – dictionary of extra parameters
- monitor –
openquake.baselib.performance.Monitor
instance
- riskinputs –
-
-
openquake.calculators.classical_bcr.
classical_bcr
(riskinputs, crmodel, param, monitor)[source]¶ Compute and return the average losses for each asset.
Parameters: - riskinputs –
openquake.risklib.riskinput.RiskInput
objects - crmodel – a
openquake.risklib.riskinput.CompositeRiskModel
instance - param – dictionary of extra parameters
- monitor –
openquake.baselib.performance.Monitor
instance
- riskinputs –
classical_damage module¶
-
class
openquake.calculators.classical_damage.
ClassicalDamageCalculator
(oqparam, calc_id)[source]¶ Bases:
openquake.calculators.classical_risk.ClassicalRiskCalculator
Scenario damage calculator
-
accept_precalc
= ['classical']¶
-
core_task
(riskinputs, crmodel, param, monitor)¶ Core function for a classical damage computation.
Parameters: - riskinputs –
openquake.risklib.riskinput.RiskInput
objects - crmodel – a
openquake.risklib.riskinput.CompositeRiskModel
instance - param – dictionary of extra parameters
- monitor –
openquake.baselib.performance.Monitor
instance
Returns: a nested dictionary lt_idx, rlz_idx -> asset_idx -> <damage array>
- riskinputs –
-
-
openquake.calculators.classical_damage.
classical_damage
(riskinputs, crmodel, param, monitor)[source]¶ Core function for a classical damage computation.
Parameters: - riskinputs –
openquake.risklib.riskinput.RiskInput
objects - crmodel – a
openquake.risklib.riskinput.CompositeRiskModel
instance - param – dictionary of extra parameters
- monitor –
openquake.baselib.performance.Monitor
instance
Returns: a nested dictionary lt_idx, rlz_idx -> asset_idx -> <damage array>
- riskinputs –
classical_risk module¶
-
class
openquake.calculators.classical_risk.
ClassicalRiskCalculator
(oqparam, calc_id)[source]¶ Bases:
openquake.calculators.base.RiskCalculator
Classical Risk calculator
-
accept_precalc
= ['classical']¶
-
core_task
(riskinputs, crmodel, param, monitor)¶ Compute and return the average losses for each asset.
Parameters: - riskinputs –
openquake.risklib.riskinput.RiskInput
objects - crmodel – a
openquake.risklib.riskinput.CompositeRiskModel
instance - param – dictionary of extra parameters
- monitor –
openquake.baselib.performance.Monitor
instance
- riskinputs –
-
post_execute
(result)[source]¶ Saving loss curves in the datastore.
Parameters: result – aggregated result of the task classical_risk
-
precalc
= 'classical'¶
-
-
openquake.calculators.classical_risk.
classical_risk
(riskinputs, crmodel, param, monitor)[source]¶ Compute and return the average losses for each asset.
Parameters: - riskinputs –
openquake.risklib.riskinput.RiskInput
objects - crmodel – a
openquake.risklib.riskinput.CompositeRiskModel
instance - param – dictionary of extra parameters
- monitor –
openquake.baselib.performance.Monitor
instance
- riskinputs –
disaggregation module¶
Disaggregation calculator core functionality
-
class
openquake.calculators.disaggregation.
DisaggregationCalculator
(oqparam, calc_id)[source]¶ Bases:
openquake.calculators.base.HazardCalculator
Classical PSHA disaggregation calculator
-
accept_precalc
= ['classical', 'disaggregation']¶
-
agg_result
(acc, result)[source]¶ Collect the results coming from compute_disagg into self.results.
Parameters: - acc – dictionary sid -> trti -> 8D array
- result – dictionary with the result coming from a task
-
check_poes_disagg
(curves, rlzs)[source]¶ Raise an error if the given poes_disagg are too small compared to the hazard curves.
-
get_curve
(sid, rlzs)[source]¶ Get the hazard curves for the given site ID and realizations.
Parameters: - sid – site ID
- rlzs – a matrix of indices of shape Z
Returns: a list of Z arrays of PoEs
-
post_execute
(results)[source]¶ Save all the results of the disaggregation. NB: the number of results to save is #sites * #rlzs * #disagg_poes * #IMTs.
Parameters: results – a dictionary sid -> trti -> disagg matrix
-
precalc
= 'classical'¶
-
-
openquake.calculators.disaggregation.
agg_probs
(*probs)[source]¶ Aggregate probabilities withe the usual formula 1 - (1 - P1) … (1 - Pn)
-
openquake.calculators.disaggregation.
compute_disagg
(dstore, idxs, cmaker, iml4, trti, bin_edges, monitor)[source]¶ - :param dstore
- a DataStore instance
Parameters: - idxs – an array of indices to ruptures
- cmaker – a
openquake.hazardlib.gsim.base.ContextMaker
instance - iml4 – an ArrayWrapper of shape (N, M, P, Z)
- trti – tectonic region type index
- bin_egdes – a quintet (mag_edges, dist_edges, lon_edges, lat_edges, eps_edges)
- monitor – monitor of the currently running job
Returns: a dictionary sid -> 8D-array
event_based module¶
-
class
openquake.calculators.event_based.
EventBasedCalculator
(oqparam, calc_id)[source]¶ Bases:
openquake.calculators.base.HazardCalculator
Event based PSHA calculator generating the ground motion fields and the hazard curves from the ruptures, depending on the configuration parameters.
-
accept_precalc
= ['event_based', 'ebrisk', 'event_based_risk']¶
-
agg_dicts
(acc, result)[source]¶ Parameters: - acc – accumulator dictionary
- result – an AccumDict with events, ruptures, gmfs and hcurves
-
build_events_from_sources
(srcfilter)[source]¶ Prefilter the composite source model and store the source_info
-
check_overflow
()[source]¶ Raise a ValueError if the number of sites is larger than 65,536 or the number of IMTs is larger than 256 or the number of ruptures is larger than 4,294,967,296. The limits are due to the numpy dtype used to store the GMFs (gmv_dt). There also a limit of max_potential_gmfs on the number of sites times the number of events, to avoid producing too many GMFs. In that case split the calculation or be smarter.
-
core_task
(rupgetter, srcfilter, param, monitor)¶ Compute GMFs and optionally hazard curves
-
is_stochastic
= True¶
-
event_based_risk module¶
-
class
openquake.calculators.event_based_risk.
EbrCalculator
(oqparam, calc_id)[source]¶ Bases:
openquake.calculators.base.RiskCalculator
Event based PSHA calculator generating the total losses by taxonomy
-
accept_precalc
= ['event_based', 'event_based_risk', 'ebrisk']¶
-
core_task
(riskinputs, crmodel, param, monitor)¶ Parameters: - riskinputs –
openquake.risklib.riskinput.RiskInput
objects - crmodel – a
openquake.risklib.riskinput.CompositeRiskModel
instance - param – a dictionary of parameters
- monitor –
openquake.baselib.performance.Monitor
instance
Returns: a dictionary of numpy arrays of shape (L, R)
- riskinputs –
-
is_stochastic
= True¶
-
precalc
= 'event_based'¶
-
-
openquake.calculators.event_based_risk.
event_based_risk
(riskinputs, crmodel, param, monitor)[source]¶ Parameters: - riskinputs –
openquake.risklib.riskinput.RiskInput
objects - crmodel – a
openquake.risklib.riskinput.CompositeRiskModel
instance - param – a dictionary of parameters
- monitor –
openquake.baselib.performance.Monitor
instance
Returns: a dictionary of numpy arrays of shape (L, R)
- riskinputs –
reportwriter module¶
Utilities to build a report writer generating a .rst report for a calculation
-
class
openquake.calculators.reportwriter.
ReportWriter
(dstore)[source]¶ Bases:
object
A particularly smart view over the datastore
-
title
= {'params': 'Parameters', 'inputs': 'Input files', 'full_lt': 'Composite source model', 'required_params_per_trt': 'Required parameters per tectonic region type', 'ruptures_events': 'Specific information for event based', 'job_info': 'Data transfer', 'biggest_ebr_gmf': 'Maximum memory allocated for the GMFs', 'avglosses_data_transfer': 'Estimated data transfer for the avglosses', 'exposure_info': 'Exposure model', 'slow_sources': 'Slowest sources', 'task:classical_split_filter:0': 'Fastest task', 'task:classical_split_filter:-1': 'Slowest task', 'task_info': 'Information about the tasks', 'times_by_source_class': 'Computation times by source typology', 'performance': 'Slowest operations'}¶
-
-
openquake.calculators.reportwriter.
build_report
(job_ini, output_dir=None)[source]¶ Write a report.csv file with information about the calculation without running it
Parameters: - job_ini – full pathname of the job.ini file
- output_dir – the directory where the report is written (default the input directory)
scenario module¶
-
class
openquake.calculators.scenario.
ScenarioCalculator
(oqparam, calc_id)[source]¶ Bases:
openquake.calculators.base.HazardCalculator
Scenario hazard calculator
-
is_stochastic
= True¶
-
scenario_damage module¶
-
class
openquake.calculators.scenario_damage.
EventBasedDamageCalculator
(oqparam, calc_id)[source]¶ Bases:
openquake.calculators.scenario_damage.ScenarioDamageCalculator
Event Based Damage calculator, able to compute dmg_by_asset, dmg_by_event and consequences.
-
accept_precalc
= ['event_based', 'event_based_risk']¶
-
core_task
(riskinputs, crmodel, param, monitor)¶ Core function for a damage computation.
Parameters: - riskinputs –
openquake.risklib.riskinput.RiskInput
objects - crmodel – a
openquake.risklib.riskinput.CompositeRiskModel
instance - monitor –
openquake.baselib.performance.Monitor
instance - param – dictionary of extra parameters
Returns: - a dictionary {‘d_asset’: [(l, r, a, mean-stddev), …],
’d_event’: dict eid -> array of shape (L, D) + optional consequences}
d_asset and d_tag are related to the damage distributions.
- riskinputs –
-
precalc
= 'event_based'¶
-
-
class
openquake.calculators.scenario_damage.
ScenarioDamageCalculator
(oqparam, calc_id)[source]¶ Bases:
openquake.calculators.base.RiskCalculator
Scenario damage calculator
-
accept_precalc
= ['scenario']¶
-
core_task
(riskinputs, crmodel, param, monitor)¶ Core function for a damage computation.
Parameters: - riskinputs –
openquake.risklib.riskinput.RiskInput
objects - crmodel – a
openquake.risklib.riskinput.CompositeRiskModel
instance - monitor –
openquake.baselib.performance.Monitor
instance - param – dictionary of extra parameters
Returns: - a dictionary {‘d_asset’: [(l, r, a, mean-stddev), …],
’d_event’: dict eid -> array of shape (L, D) + optional consequences}
d_asset and d_tag are related to the damage distributions.
- riskinputs –
-
is_stochastic
= True¶
-
post_execute
(result)[source]¶ Compute stats for the aggregated distributions and save the results on the datastore.
-
precalc
= 'scenario'¶
-
-
openquake.calculators.scenario_damage.
approx_ddd
(fractions, n, seed=None)[source]¶ Converting fractions into uint16 discrete damage distributions using round
-
openquake.calculators.scenario_damage.
bin_ddd
(fractions, n, seed)[source]¶ Converting fractions into discrete damage distributions using bincount and numpy.random.choice
-
openquake.calculators.scenario_damage.
floats_in
(numbers)[source]¶ Parameters: numbers – an array of numbers Returns: number of non-uint32 number
-
openquake.calculators.scenario_damage.
scenario_damage
(riskinputs, crmodel, param, monitor)[source]¶ Core function for a damage computation.
Parameters: - riskinputs –
openquake.risklib.riskinput.RiskInput
objects - crmodel – a
openquake.risklib.riskinput.CompositeRiskModel
instance - monitor –
openquake.baselib.performance.Monitor
instance - param – dictionary of extra parameters
Returns: - a dictionary {‘d_asset’: [(l, r, a, mean-stddev), …],
’d_event’: dict eid -> array of shape (L, D) + optional consequences}
d_asset and d_tag are related to the damage distributions.
- riskinputs –
scenario_risk module¶
-
class
openquake.calculators.scenario_risk.
ScenarioRiskCalculator
(oqparam, calc_id)[source]¶ Bases:
openquake.calculators.base.RiskCalculator
Run a scenario risk calculation
-
accept_precalc
= ['scenario']¶
-
combine
(acc, res)[source]¶ Combine the outputs from scenario_risk and incrementally store the asset loss table
-
core_task
(riskinputs, crmodel, param, monitor)¶ Core function for a scenario computation.
Parameters: - riskinput – a of
openquake.risklib.riskinput.RiskInput
object - crmodel – a
openquake.risklib.riskinput.CompositeRiskModel
instance - param – dictionary of extra parameters
- 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_ordinal, 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_execute
()[source]¶ Compute the GMFs, build the epsilons, the riskinputs, and a dictionary with the unit of measure, used in the export phase.
-
precalc
= 'scenario'¶
-
-
openquake.calculators.scenario_risk.
ael_dt
(loss_names, rlz=False)[source]¶ Returns: (asset_id, event_id, loss) or (asset_id, event_id, rlzi, loss)
-
openquake.calculators.scenario_risk.
scenario_risk
(riskinputs, crmodel, param, monitor)[source]¶ Core function for a scenario computation.
Parameters: - riskinput – a of
openquake.risklib.riskinput.RiskInput
object - crmodel – a
openquake.risklib.riskinput.CompositeRiskModel
instance - param – dictionary of extra parameters
- 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_ordinal, 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
ucerf_event_classical module¶
views module¶
-
class
openquake.calculators.views.
Source
(source_id, code, num_ruptures, checksum)¶ Bases:
tuple
-
checksum
¶ Alias for field number 3
-
code
¶ Alias for field number 1
-
num_ruptures
¶ Alias for field number 2
-
source_id
¶ Alias for field number 0
-
-
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.
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.30000' >>> form(-1.2) '-1.2'
-
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.
view_act_ruptures_by_src
(token, dstore)[source]¶ Display the actual number of ruptures by source in event based calculations
-
openquake.calculators.views.
view_assets_by_site
(token, dstore)[source]¶ Display statistical information about the distribution of the assets
-
openquake.calculators.views.
view_bad_ruptures
(token, dstore)[source]¶ Display the ruptures degenerating to a point
-
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_elt
(token, dstore)[source]¶ Display the event loss table averaged by event
-
openquake.calculators.views.
view_events_by_mag
(token, dstore)[source]¶ Show how many events there are for each magnitude
-
openquake.calculators.views.
view_exposure_info
(token, dstore)[source]¶ Display info about the exposure model
-
openquake.calculators.views.
view_extreme_groups
(token, dstore)[source]¶ Show the source groups contributing the most to the highest IML
-
openquake.calculators.views.
view_fullreport
(token, dstore)[source]¶ Display an .rst report about the computation
-
openquake.calculators.views.
view_global_gmfs
(token, dstore)[source]¶ Display GMFs averaged on everything for debugging purposes
-
openquake.calculators.views.
view_global_hcurves
(token, dstore)[source]¶ Display the global hazard curves for the calculation. They are used for debugging purposes when comparing the results of two calculations. They are the mean over the sites of the mean hazard curves.
-
openquake.calculators.views.
view_global_hmaps
(token, dstore)[source]¶ Display the global hazard maps for the calculation. They are used for debugging purposes when comparing the results of two calculations. They are the mean over the sites of the mean hazard maps.
-
openquake.calculators.views.
view_global_poes
(token, dstore)[source]¶ Display global probabilities averaged on all sites and all GMPEs
-
openquake.calculators.views.
view_gmv_by_rup
(token, dstore)[source]¶ Display a synthetic gmv per rupture serial for debugging purposes
-
openquake.calculators.views.
view_gmvs_to_hazard
(token, dstore)[source]¶ Show the number of GMFs over the highest IML
-
openquake.calculators.views.
view_hmap
(token, dstore)[source]¶ Display the highest 20 points of the mean hazard map. Called as $ oq show hmap:0.1 # 10% PoE
-
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_maximum_intensity
(token, dstore)[source]¶ Show intensities at minimum and maximum distance for the highest magnitude
-
openquake.calculators.views.
view_mean_disagg
(token, dstore)[source]¶ Display mean quantities for the disaggregation. Useful for checking differences between two calculations.
-
openquake.calculators.views.
view_num_units
(token, dstore)[source]¶ Display the number of units by taxonomy
-
openquake.calculators.views.
view_performance
(token, dstore)[source]¶ Display performance information
-
openquake.calculators.views.
view_pmap
(token, dstore)[source]¶ Display the mean ProbabilityMap associated to a given source group name
-
openquake.calculators.views.
view_portfolio_loss
(token, dstore)[source]¶ The mean and stddev loss for the full portfolio for each loss type, extracted from the event loss table, averaged over the realizations
-
openquake.calculators.views.
view_portfolio_losses
(token, dstore)[source]¶ The losses 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_ruptures
(token, dstore, maxrows=25)[source]¶ Show the slowest ruptures
-
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_ebrisk
(token, dstore)[source]¶ Display info about ebrisk tasks:
$ oq show task_ebrisk:-1 # the slowest task
-
openquake.calculators.views.
view_task_hazard
(token, dstore)[source]¶ Display info about a given task. Here are a few examples of usage:
$ oq show task:classical:0 # the fastest task $ oq show task:classical:-1 # the slowest task
-
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_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.
extract module¶
-
class
openquake.calculators.extract.
Extract
[source]¶ Bases:
dict
A callable dictionary of functions with a single instance called extract. Then extract(dstore, fullkey) dispatches to the function determined by the first part of fullkey (a slash-separated string) by passing as argument the second part of fullkey.
For instance extract(dstore, ‘sitecol’).
-
class
openquake.calculators.extract.
Extractor
(calc_id)[source]¶ Bases:
object
A class to extract data from a calculation.
Parameters: calc_id – a calculation ID NB: instantiating the Extractor opens the datastore.
-
class
openquake.calculators.extract.
RuptureData
(trt, samples, gsims)[source]¶ Bases:
object
Container for information about the ruptures of a given tectonic region type.
-
exception
openquake.calculators.extract.
WebAPIError
[source]¶ Bases:
RuntimeError
Wrapper for an error on a WebAPI server
-
class
openquake.calculators.extract.
WebExtractor
(calc_id, server=None, username=None, password=None)[source]¶ Bases:
openquake.calculators.extract.Extractor
A class to extract data from the WebAPI.
Parameters: - calc_id – a calculation ID
- server – hostname of the webapi server (can be ‘’)
- username – login username (can be ‘’)
- password – login password (can be ‘’)
NB: instantiating the WebExtractor opens a session.
-
openquake.calculators.extract.
build_damage_array
(data, damage_dt)[source]¶ Parameters: - data – an array of shape (A, L, 1, D) or (A, L, 2, D)
- damage_dt – a damage composite data type loss_type -> states
Returns: a composite array of length N and dtype damage_dt
-
openquake.calculators.extract.
build_damage_dt
(dstore, mean_std=True)[source]¶ Parameters: - dstore – a datastore instance
- mean_std – a flag (default True)
Returns: a composite dtype loss_type -> (mean_ds1, stdv_ds1, …) or loss_type -> (ds1, ds2, …) depending on the flag mean_std
-
openquake.calculators.extract.
crm_attrs
(dstore, what)[source]¶ Returns: the attributes of the risk model, i.e. limit_states, loss_types, min_iml and covs, needed by the risk exporters.
-
openquake.calculators.extract.
disagg_output
(dstore, imt, sid, poe_id, rlz=None)[source]¶ Returns: a datagroup
-
openquake.calculators.extract.
extract_
(dstore, dspath)[source]¶ Extracts an HDF5 path object from the datastore, for instance extract(dstore, ‘sitecol’).
-
openquake.calculators.extract.
extract_agg_curves
(dstore, what)[source]¶ Aggregate loss curves from the ebrisk calculator:
/extract/agg_curves? kind=stats&absolute=1&loss_type=occupants&occupancy=RES
Returns an array of shape (P, S, 1…) or (P, R, 1…)
-
openquake.calculators.extract.
extract_agg_damages
(dstore, what)[source]¶ Aggregate damages of the given loss type and tags. Use it as /extract/agg_damages/structural?taxonomy=RC&zipcode=20126
Returns: array of shape (R, D), being R the number of realizations and D the number of damage states, or an array of length 0 if there is no data for the given tags
-
openquake.calculators.extract.
extract_agg_losses
(dstore, what)[source]¶ Aggregate losses of the given loss type and tags. Use it as /extract/agg_losses/structural?taxonomy=RC&zipcode=20126 /extract/agg_losses/structural?taxonomy=RC&zipcode=*
Returns: an array of shape (T, R) if one of the tag names has a * value an array of shape (R,), being R the number of realizations an array of length 0 if there is no data for the given tags
-
openquake.calculators.extract.
extract_aggregate
(dstore, what)[source]¶ /extract/aggregate/avg_losses? kind=mean&loss_type=structural&tag=taxonomy&tag=occupancy
-
openquake.calculators.extract.
extract_asset_risk
(dstore, what)[source]¶ Extract an array of assets + risk fields, optionally filtered by tag. Use it as /extract/asset_risk?taxonomy=RC&taxonomy=MSBC&occupancy=RES
Extract an array of asset tags for the given tagname. Use it as /extract/asset_tags or /extract/asset_tags/taxonomy
-
openquake.calculators.extract.
extract_assets
(dstore, what)[source]¶ Extract an array of assets, optionally filtered by tag. Use it as /extract/assets?taxonomy=RC&taxonomy=MSBC&occupancy=RES
-
openquake.calculators.extract.
extract_curves
(dstore, what, tot)[source]¶ Porfolio loss curves from the ebrisk calculator:
/extract/tot_curves? kind=stats&absolute=1&loss_type=occupants
Returns an array of shape (P, S) or (P, R)
-
openquake.calculators.extract.
extract_disagg
(dstore, what)[source]¶ Extract a disaggregation output Example: http://127.0.0.1:8800/v1/calc/30/extract/ disagg?kind=Mag_Dist&imt=PGA&poe_id=0&site_id=1&rlz=0
-
openquake.calculators.extract.
extract_disagg_layer
(dstore, what)[source]¶ Extract a disaggregation output containing all sites for the first realization or the mean. Example: http://127.0.0.1:8800/v1/calc/30/extract/ disagg_layer?kind=Mag_Dist&imt=PGA&poe_id=0
-
openquake.calculators.extract.
extract_effect
(dstore, what)[source]¶ Extracts the effect of ruptures. Use it as /extract/effect
-
openquake.calculators.extract.
extract_event_info
(dstore, eidx)[source]¶ Extract information about the given event index. Example: http://127.0.0.1:8800/v1/calc/30/extract/event_info/0
-
openquake.calculators.extract.
extract_exposure_metadata
(dstore, what)[source]¶ Extract the loss categories and the tags of the exposure. Use it as /extract/exposure_metadata
-
openquake.calculators.extract.
extract_gsims_by_trt
(dstore, what)[source]¶ Extract the dictionary gsims_by_trt
-
openquake.calculators.extract.
extract_hcurves
(dstore, what)[source]¶ Extracts hazard curves. Use it as /extract/hcurves?kind=mean or /extract/hcurves?kind=rlz-0, /extract/hcurves?kind=stats, /extract/hcurves?kind=rlzs etc
-
openquake.calculators.extract.
extract_hmaps
(dstore, what)[source]¶ Extracts hazard maps. Use it as /extract/hmaps?imt=PGA
-
openquake.calculators.extract.
extract_mean_std_curves
(dstore, what)[source]¶ Yield imls/IMT and poes/IMT containg mean and stddev for all sites
-
openquake.calculators.extract.
extract_mfd
(dstore, what)[source]¶ Display num_ruptures by magnitude for event based calculations. Example: http://127.0.0.1:8800/v1/calc/30/extract/event_based_mfd?kind=mean
-
openquake.calculators.extract.
extract_num_events
(dstore, what)[source]¶ Returns: the number of events (if any)
-
openquake.calculators.extract.
extract_realizations
(dstore, dummy)[source]¶ Extract an array of realizations. Use it as /extract/realizations
-
openquake.calculators.extract.
extract_rups_by_mag_dist
(dstore, what)[source]¶ Extracts the number of ruptures by mag, dist. Use it as /extract/rups_by_mag_dist
-
openquake.calculators.extract.
extract_rupture
(dstore, rup_id)[source]¶ Extract information about the given event index. Example: http://127.0.0.1:8800/v1/calc/30/extract/rupture/1066
-
openquake.calculators.extract.
extract_rupture_info
(dstore, what)[source]¶ Extract some information about the ruptures, including the boundary. Example: http://127.0.0.1:8800/v1/calc/30/extract/rupture_info?min_mag=6
-
openquake.calculators.extract.
extract_sitecol
(dstore, what)[source]¶ Extracts the site collection array (not the complete object, otherwise it would need to be pickled). Use it as /extract/sitecol
-
openquake.calculators.extract.
extract_sources
(dstore, what)[source]¶ Extract information about a source model. Use it as /extract/sources?limit=10 or /extract/sources?source_id=1&source_id=2 or /extract/sources?code=A&code=B
-
openquake.calculators.extract.
extract_src_loss_table
(dstore, loss_type)[source]¶ Extract the source loss table for a give loss type, ordered in decreasing order. Example: http://127.0.0.1:8800/v1/calc/30/extract/src_loss_table/structural
-
openquake.calculators.extract.
extract_task_info
(dstore, what)[source]¶ Extracts the task distribution. Use it as /extract/task_info?kind=classical
-
openquake.calculators.extract.
extract_uhs
(dstore, what)[source]¶ Extracts uniform hazard spectra. Use it as /extract/uhs?kind=mean or /extract/uhs?kind=rlz-0, etc
-
openquake.calculators.extract.
get_info
(dstore)[source]¶ Returns: {‘stats’: dic, ‘loss_types’: dic, ‘num_rlzs’: R}
-
openquake.calculators.extract.
get_mesh
(sitecol, complete=True)[source]¶ Returns: a lon-lat or lon-lat-depth array depending if the site collection is at sea level or not
-
openquake.calculators.extract.
get_ruptures_within
(dstore, bbox)[source]¶ Extract the ruptures within the given bounding box, a string minlon,minlat,maxlon,maxlat. Example: http://127.0.0.1:8800/v1/calc/30/extract/ruptures_with/8,44,10,46
-
openquake.calculators.extract.
hazard_items
(dic, mesh, *extras, **kw)[source]¶ Parameters: - dic – dictionary of arrays of the same shape
- mesh – a mesh array with lon, lat fields of the same length
- extras – optional triples (field, dtype, values)
- kw – dictionary of parameters (like investigation_time)
Returns: a list of pairs (key, value) suitable for storage in .npz format
-
openquake.calculators.extract.
lit_eval
(string)[source]¶ ast.literal_eval the string if possible, otherwise returns it unchanged
-
openquake.calculators.extract.
parse
(query_string, info={})[source]¶ Returns: a normalized query_dict as in the following examples: >>> parse('kind=stats', {'stats': {'mean': 0, 'max': 1}}) {'kind': ['mean', 'max'], 'k': [0, 1], 'rlzs': False} >>> parse('kind=rlzs', {'stats': {}, 'num_rlzs': 3}) {'kind': ['rlz-000', 'rlz-001', 'rlz-002'], 'k': [0, 1, 2], 'rlzs': True} >>> parse('kind=mean', {'stats': {'mean': 0, 'max': 1}}) {'kind': ['mean'], 'k': [0], 'rlzs': False} >>> parse('kind=rlz-3&imt=PGA&site_id=0', {'stats': {}}) {'kind': ['rlz-3'], 'imt': ['PGA'], 'site_id': [0], 'k': [3], 'rlzs': True}