openquake.calculators package¶
Subpackages¶
base module¶
-
class
openquake.calculators.base.
BaseCalculator
(oqparam, calc_id=None)[source]¶ Bases:
object
Abstract base class for all calculators.
Parameters: - oqparam – OqParam object
- monitor – monitor object
- calc_id – numeric calculation ID
-
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.
-
class
openquake.calculators.base.
HazardCalculator
(oqparam, calc_id=None)[source]¶ Bases:
openquake.calculators.base.BaseCalculator
Base class for hazard calculators based on source models
-
block_splitter
(sources, weight=operator.attrgetter('weight'), key=<function HazardCalculator.<lambda>>)[source]¶ Parameters: - sources – a list of sources
- weight – a weight function (default .weight)
- key – None or ‘src_group_id’
Returns: an iterator over blocks of sources
-
can_read_parent
()[source]¶ Returns: the parent datastore if it is present and can be read from the workers, None otherwise
-
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
(pre_calculator=None)[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.
-
precalc
= None¶
-
read_exposure
(haz_sitecol=None)[source]¶ Read the exposure, the riskmodel and update the attributes .sitecol, .assetcol
-
src_filter
¶ Returns: a SourceFilter/UcerfFilter
-
-
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=None)[source]¶ Bases:
openquake.calculators.base.HazardCalculator
Base class for all risk calculators. A risk calculator must set the attributes .riskmodel, .sitecol, .assetcol, .riskinputs in the pre_execute phase.
-
R
¶ Returns: the number of realizations as read from csm_info
-
build_riskinputs
(kind, eps=None, num_events=0)[source]¶ Parameters: - kind – kind of hazard getter, can be ‘poe’ or ‘gmf’
- eps – a matrix of epsilons (or None)
- num_events – how many events there are
Returns: a list of RiskInputs objects, sorted by IMT.
-
-
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.
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, occupancy_periods)[source]¶ Check the time_event parameter in the datastore, by comparing with the periods found in the exposure.
-
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_gmv_data
(sids, gmfs)[source]¶ Convert an array of shape (R, N, E, I) into an array of type gmv_data_dt
-
openquake.calculators.base.
get_idxs
(data, eid2idx)[source]¶ Convert from event IDs to event indices.
Parameters: - data – an array with a field eid
- eid2idx – a dictionary eid -> idx
Returns: the array of event indices
-
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_gmf_data
(dstore, sitecol, gmfs, imts, eids=())[source]¶ Parameters: - dstore – a
openquake.baselib.datastore.DataStore
instance - sitecol – a
openquake.hazardlib.site.SiteCollection
instance - gmfs – an array of shape (R, N, E, M)
- imts – a list of IMT strings
- eids – E event IDs or the empty tuple
- dstore – a
-
openquake.calculators.base.
save_gmfs
(calculator)[source]¶ Parameters: calculator – a scenario_risk/damage or event_based_risk calculator Returns: a pair (eids, R) where R is the number of realizations
-
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
(rlzs_by_gsim, ebruptures, sitecol, oqparam, min_iml)[source]¶ Bases:
object
An hazard getter with methods .gen_gmv and .get_hazard returning ground motion values.
-
gen_gmv
()[source]¶ Compute the GMFs for the given realization and yields tuples of the form (sid, eid, imti, gmv).
-
get_hazard
(data=None)[source]¶ Parameters: data – if given, an iterator of records of dtype gmf_data_dt Returns: an array (rlzi, sid, imti) -> array(gmv, eid)
-
imtls
¶
-
imts
¶
-
sids
¶
-
-
class
openquake.calculators.getters.
PmapGetter
(dstore, rlzs_assoc=None, sids=None)[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)
- rlzs_assoc – a RlzsAssoc instance (if None, infers it)
-
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_hcurves
(imtls=None)[source]¶ Parameters: imtls – intensity measure types and levels Returns: an array of (R, N) hazard curves
-
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_pmaps
(sids)[source]¶ Parameters: sids – an array of S site IDs Returns: a list of R probability maps
-
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.
-
pmap_by_grp
¶ Returns: dictionary “grp-XXX” -> ProbabilityMap instance
-
weights
¶
-
class
openquake.calculators.getters.
RuptureGetter
(hdf5path, code2cls, rup_array, trt, samples, rlzs_by_gsim)[source]¶ Bases:
object
Iterable over ruptures.
Parameters: - hdf5path – path to an HDF5 file with a dataset names ruptures
- rup_array – an array of rupture parameters with homogeneous grp_id
classical module¶
-
class
openquake.calculators.classical.
ClassicalCalculator
(oqparam, calc_id=None)[source]¶ Bases:
openquake.calculators.base.HazardCalculator
Classical PSHA calculator
-
agg_dicts
(acc, dic)[source]¶ Aggregate dictionaries of hazard curves by updating the accumulator.
Parameters: - acc – accumulator dictionary
- dic – dictionary with keys pmap, calc_times, eff_ruptures
-
core_task
(group, src_filter, gsims, param, monitor=<Monitor [jenkins]>)¶ Compute the hazard curves for a set of sources belonging to the same tectonic region type for all the GSIMs associated to that TRT. The arguments are the same as in
calc_hazard_curves()
, except forgsims
, which is a list of GSIM instances.Returns: a dictionary {grp_id: pmap} with attributes .grp_ids, .calc_times, .eff_ruptures
-
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
()[source]¶ Used in the case of large source model logic trees. :yields: (sources, sites, gsims) triples
-
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=None)[source]¶ Bases:
openquake.calculators.classical.ClassicalCalculator
Calculator to filter the sources and compute the number of effective ruptures
-
openquake.calculators.classical.
build_hazard_stats
(pgetter, hstats, individual_curves, monitor)[source]¶ Parameters: - pgetter – an
openquake.commonlib.getters.PmapGetter
- hstats – a list of pairs (statname, statfunc)
- individual_curves – if True, also build the individual curves
- 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
classical_bcr module¶
-
class
openquake.calculators.classical_bcr.
ClassicalBCRCalculator
(oqparam, calc_id=None)[source]¶ Bases:
openquake.calculators.classical_risk.ClassicalRiskCalculator
Classical BCR Risk calculator
-
core_task
(riskinputs, riskmodel, param, monitor)¶ Compute and return the average losses for each asset.
Parameters: - riskinputs –
openquake.risklib.riskinput.RiskInput
objects - riskmodel – 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, riskmodel, param, monitor)[source]¶ Compute and return the average losses for each asset.
Parameters: - riskinputs –
openquake.risklib.riskinput.RiskInput
objects - riskmodel – 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=None)[source]¶ Bases:
openquake.calculators.classical_risk.ClassicalRiskCalculator
Scenario damage calculator
-
core_task
(riskinputs, riskmodel, param, monitor)¶ Core function for a classical damage computation.
Parameters: - riskinputs –
openquake.risklib.riskinput.RiskInput
objects - riskmodel – 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, riskmodel, param, monitor)[source]¶ Core function for a classical damage computation.
Parameters: - riskinputs –
openquake.risklib.riskinput.RiskInput
objects - riskmodel – 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=None)[source]¶ Bases:
openquake.calculators.base.RiskCalculator
Classical Risk calculator
-
core_task
(riskinputs, riskmodel, param, monitor)¶ Compute and return the average losses for each asset.
Parameters: - riskinputs –
openquake.risklib.riskinput.RiskInput
objects - riskmodel – a
openquake.risklib.riskinput.CompositeRiskModel
instance - param – dictionary of extra parameters
- monitor –
openquake.baselib.performance.Monitor
instance
- riskinputs –
-
-
openquake.calculators.classical_risk.
classical_risk
(riskinputs, riskmodel, param, monitor)[source]¶ Compute and return the average losses for each asset.
Parameters: - riskinputs –
openquake.risklib.riskinput.RiskInput
objects - riskmodel – 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=None)[source]¶ Bases:
openquake.calculators.base.HazardCalculator
Classical PSHA disaggregation calculator
-
POE_TOO_BIG
= "You are trying to disaggregate for poe=%s.\nHowever the source model #%d, '%s',\nproduces at most probabilities of %.7f for rlz=#%d, IMT=%s.\nThe disaggregation PoE is too big or your model is wrong,\nproducing too small PoEs."¶
-
agg_result
(acc, result)[source]¶ Collect the results coming from compute_disagg into self.results, a dictionary with key (sid, rlzi, poe, imt, trti) and values which are probability arrays.
Parameters: - acc – dictionary k -> dic accumulating the results
- result – dictionary with the result coming from a task
-
build_disagg_by_src
(iml4)[source]¶ Parameters: - dstore – a datastore
- iml4 – 4D array of IMLs with shape (N, 1, M, P)
-
build_stats
(results, hstats)[source]¶ Parameters: - results – dict key -> 6D disagg_matrix
- hstats – (statname, statfunc) pairs
-
check_poes_disagg
(curves)[source]¶ Raise an error if the given poes_disagg are too small compared to the hazard curves.
-
full_disaggregation
(curves)[source]¶ Run the disaggregation phase.
Parameters: curves – a list of hazard curves, one per site The curves can be all None if iml_disagg is set in the job.ini
-
get_curves
(sid)[source]¶ Get all the relevant hazard curves for the given site ordinal. Returns a dictionary rlz_id -> curve_by_imt.
-
-
openquake.calculators.disaggregation.
agg_probs
(*probs)[source]¶ Aggregate probabilities withe the usual formula 1 - (1 - P1) … (1 - Pn)
-
openquake.calculators.disaggregation.
compute_disagg
(src_filter, sources, cmaker, iml4, trti, bin_edges, oqparam, monitor)[source]¶ Parameters: - src_filter – a
openquake.hazardlib.calc.filter.SourceFilter
instance - sources – list of hazardlib source objects
- cmaker – a
openquake.hazardlib.gsim.base.ContextMaker
instance - iml4 – an array of intensities of shape (N, R, M, P)
- trti (dict) – tectonic region type index
- 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, rlzi, poe, imt, iml, trti).
- src_filter – a
event_based module¶
-
class
openquake.calculators.event_based.
EventBasedCalculator
(oqparam, calc_id=None)[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.
-
agg_dicts
(acc, result)[source]¶ Parameters: - acc – accumulator dictionary
- result – an AccumDict with events, ruptures, gmfs and hcurves
-
build_ruptures
(sources, param, monitor=<Monitor [jenkins]>)¶ Parameters: - sources – a sequence of (prefiltered) sources of the same group
- param – a dictionary of additional parameters including ses_per_logic_tree_path
- monitor – monitor instance
Yields: dictionaries with keys rup_array, calc_times, eff_ruptures
-
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). They could be relaxed in the future.
-
core_task
(rupgetter, srcfilter, param, monitor)¶ Compute GMFs and optionally hazard curves
-
csm_info
¶ Returns: a cached CompositionInfo object
-
is_stochastic
= True¶
-
-
openquake.calculators.event_based.
compute_gmfs
(rupgetter, srcfilter, param, monitor)[source]¶ Compute GMFs and optionally hazard curves
-
openquake.calculators.event_based.
get_mean_curves
(dstore)[source]¶ Extract the mean hazard curves from the datastore, as a composite array of length nsites.
event_based_risk module¶
-
class
openquake.calculators.event_based_risk.
EbrCalculator
(oqparam, calc_id=None)[source]¶ Bases:
openquake.calculators.base.RiskCalculator
Event based PSHA calculator generating the total losses by taxonomy
-
core_task
(riskinputs, riskmodel, param, monitor)¶ Parameters: - riskinputs –
openquake.risklib.riskinput.RiskInput
objects - riskmodel – 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¶
-
-
openquake.calculators.event_based_risk.
build_loss_tables
(dstore)[source]¶ Compute the total losses by rupture and losses by rlzi.
-
openquake.calculators.event_based_risk.
event_based_risk
(riskinputs, riskmodel, param, monitor)[source]¶ Parameters: - riskinputs –
openquake.risklib.riskinput.RiskInput
objects - riskmodel – 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', 'csm_info': 'Composite source model', 'dupl_sources': 'Duplicated sources', 'required_params_per_trt': 'Required parameters per tectonic region type', 'ruptures_per_trt': 'Number of ruptures per tectonic region type', 'ruptures_events': 'Specific information for event based', 'rlzs_assoc': 'Realizations per (TRT, GSIM)', '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', 'short_source_info': 'Slowest sources', 'task_hazard:0': 'Fastest task', 'task_hazard:-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=None)[source]¶ Bases:
openquake.calculators.base.HazardCalculator
Scenario hazard calculator
-
is_stochastic
= True¶
-
scenario_damage module¶
-
class
openquake.calculators.scenario_damage.
ScenarioDamageCalculator
(oqparam, calc_id=None)[source]¶ Bases:
openquake.calculators.base.RiskCalculator
Scenario damage calculator
-
core_task
(riskinputs, riskmodel, param, monitor)¶ Core function for a damage computation.
Parameters: - riskinputs –
openquake.risklib.riskinput.RiskInput
objects - riskmodel – 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’: damage array of shape R, L, E, D, ‘c_asset’: [(l, r, a, mean-stddev), …], ‘c_event’: damage array of shape R, L, E}
d_asset and d_tag are related to the damage distributions whereas c_asset and c_tag are the consequence distributions. If there is no consequence model c_asset is an empty list and c_tag is a zero-valued array.
- riskinputs –
-
is_stochastic
= True¶
-
-
openquake.calculators.scenario_damage.
dist_by_asset
(data, multi_stat_dt, number)[source]¶ Parameters: - data – array of shape (N, R, L, 2, …)
- multi_stat_dt – numpy dtype for statistical outputs
- number – expected number of units per asset
Returns: array of shape (N, R) with records of type multi_stat_dt
-
openquake.calculators.scenario_damage.
scenario_damage
(riskinputs, riskmodel, param, monitor)[source]¶ Core function for a damage computation.
Parameters: - riskinputs –
openquake.risklib.riskinput.RiskInput
objects - riskmodel – 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’: damage array of shape R, L, E, D, ‘c_asset’: [(l, r, a, mean-stddev), …], ‘c_event’: damage array of shape R, L, E}
d_asset and d_tag are related to the damage distributions whereas c_asset and c_tag are the consequence distributions. If there is no consequence model c_asset is an empty list and c_tag is a zero-valued array.
- riskinputs –
scenario_risk module¶
-
class
openquake.calculators.scenario_risk.
ScenarioRiskCalculator
(oqparam, calc_id=None)[source]¶ Bases:
openquake.calculators.base.RiskCalculator
Run a scenario risk calculation
-
core_task
(riskinputs, riskmodel, param, monitor)¶ Core function for a scenario computation.
Parameters: - riskinput – a of
openquake.risklib.riskinput.RiskInput
object - riskmodel – 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¶
-
-
openquake.calculators.scenario_risk.
scenario_risk
(riskinputs, riskmodel, param, monitor)[source]¶ Core function for a scenario computation.
Parameters: - riskinput – a of
openquake.risklib.riskinput.RiskInput
object - riskmodel – 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¶
-
class
openquake.calculators.ucerf_classical.
UcerfClassicalCalculator
(oqparam, calc_id=None)[source]¶ Bases:
openquake.calculators.classical.ClassicalCalculator
UCERF classical calculator.
ucerf_event_based module¶
-
class
openquake.calculators.ucerf_event_based.
UCERFHazardCalculator
(oqparam, calc_id=None)[source]¶ Bases:
openquake.calculators.event_based.EventBasedCalculator
Event based PSHA calculator generating the ruptures and GMFs together
-
build_ruptures
(sources, param, monitor)¶ Parameters: - sources – a list with a single UCERF source
- param – extra parameters
- monitor – a Monitor instance
Returns: an AccumDict grp_id -> EBRuptures
-
-
openquake.calculators.ucerf_event_based.
build_ruptures
(sources, param, monitor)[source]¶ Parameters: - sources – a list with a single UCERF source
- param – extra parameters
- monitor – a Monitor instance
Returns: an AccumDict grp_id -> EBRuptures
-
openquake.calculators.ucerf_event_based.
generate_event_set
(ucerf, background_sids, src_filter, ses_idx, seed)[source]¶ Generates the event set corresponding to a particular branch
-
openquake.calculators.ucerf_event_based.
sample_background_model
(hdf5, branch_key, tom, seed, 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
- seed – Random seed to use in the call to tom.sample_number_of_occurrences
- 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
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.30000' >>> 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_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_dupl_sources
(token, dstore)[source]¶ Display the duplicated sources from source_info
-
openquake.calculators.views.
view_elt
(token, dstore)[source]¶ Display the event loss table averaged by event
-
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_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_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_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_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_hazard
(token, dstore)[source]¶ Display info about a given task. Here are a few examples of usage:
$ oq show task_hazard:0 # the fastest task $ oq show task_hazard:-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_task_risk
(token, dstore)[source]¶ Display info about a given risk task. Here are a few examples of usage:
$ oq show task_risk:0 # the fastest task $ oq show task_risk:-1 # the slowest 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.
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), extract(dstore, ‘asset_values/0’) etc.
-
openquake.calculators.extract.
build_damage_array
(data, damage_dt)[source]¶ Parameters: - data – an array of length N with fields ‘mean’ and ‘stddev’
- 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.
curves_by_tag
(dstore, tag)[source]¶ Statistical loss curves by tag. For instance call
$ oq extract curves_by_tag/occupancy
-
openquake.calculators.extract.
extract_
(dstore, dspath)[source]¶ Extracts an HDF5 path object from the datastore, for instance extract(‘sitecol’, dstore). It is also possibly to extract the attributes, for instance with extract(‘sitecol.attrs’, dstore).
-
openquake.calculators.extract.
extract_agg_curves
(dstore, what)[source]¶ Aggregate loss curves of the given loss type and tags for event based risk calculations. Use it as /extract/agg_curves/structural?taxonomy=RC&zipcode=20126
Returns: array of shape (S, P), being P the number of return periods and S the number of statistics
-
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 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_by
(dstore, what)[source]¶ /extract/aggregate_by/taxonomy,occupancy/curves/structural yield pairs (<stat>, <array of shape (T, O, S, P)>)
/extract/aggregate_by/taxonomy,occupancy/avg_losses/structural yield pairs (<stat>, <array of shape (T, O, S)>)
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_asset_values
(dstore, sid)[source]¶ Extract an array of asset values for the given sid. Use it as /extract/asset_values/0
Returns: (aid, loss_type1, …, loss_typeN) composite array
-
openquake.calculators.extract.
extract_hazard
(dstore, what)[source]¶ Extracts hazard curves and possibly hazard maps and/or uniform hazard spectra. Use it as /extract/hazard/mean or /extract/hazard/rlz-0, etc
-
openquake.calculators.extract.
extract_hcurves
(dstore, what)[source]¶ Extracts hazard curves. Use it as /extract/hcurves/mean or /extract/hcurves/rlz-0, /extract/hcurves/stats, /extract/hcurves/rlzs etc
-
openquake.calculators.extract.
extract_hmaps
(dstore, what)[source]¶ Extracts hazard maps. Use it as /extract/hmaps/mean or /extract/hmaps/rlz-0, etc
-
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
-
openquake.calculators.extract.
extract_realizations
(dstore, dummy)[source]¶ Extract an array of realizations. Use it as /extract/realizations
-
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_uhs
(dstore, what)[source]¶ Extracts uniform hazard spectra. Use it as /extract/uhs/mean or /extract/uhs/rlz-0, etc
-
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.
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