openquake.hazardlib.calc package#

Hazardlib calculators#

Disaggregation (disagg)#

openquake.hazardlib.calc.disagg contains Disaggregator, disaggregation() as well as several aggregation functions for extracting a specific PMF from the result of disaggregation().

class openquake.hazardlib.calc.disagg.BinData(dists, lons, lats, pnes)#

Bases: tuple

dists#

Alias for field number 0

lats#

Alias for field number 2

lons#

Alias for field number 1

pnes#

Alias for field number 3

class openquake.hazardlib.calc.disagg.Disaggregator(srcs_or_ctxs, site, cmaker, bin_edges)[source]#

Bases: object

A class to perform single-site disaggregation with methods .disagg_by_magi (called in standard disaggregation) and .disagg_mag_dist_eps (called in disaggregation by relevant source). Internally the attributes .mea and .std are set, with shape (G, M, U), for each magnitude bin.

disagg_by_magi(imtls, rlzs, rwdic, src_mutex, mon0, mon1, mon2, mon3)[source]#
Parameters:
  • imtls – a dictionary imt->imls

  • rlzs – an array of realization indices

  • rwdic – a dictionary rlz_id->weight; if non-empty, used compute the mean

  • src_mutex – dictionary used to set the self.src_mutex slices

Yields:

a dictionary with keys trti, magi, sid, rlzi, mean for each magi

disagg_mag_dist_eps(imldic, weights, src_mutex={})[source]#
Parameters:
  • imldic – a dictionary imt->iml

  • weights – an array of G weights, one per gsim of the cmaker

  • src_mutex – a dictionary with keys src_id, weight or empty

Returns:

a 4D matrix of rates of shape (Ma, D, E, M)

The rates depend on the realization only through the GSIM, hence the loop is over the G gsims and not over the logic tree realizations; the weights are the sums of the realization weights associated to each GSIM, see FullLogicTree.g_weights.

init(magi, src_mutex, mon0=<Monitor disagg mean_stds[runner]>, mon1=<Monitor disagg by eps[runner]>, mon2=<Monitor composing pnes[runner]>, mon3=<Monitor disagg matrix[runner]>)[source]#
std_by_dist(weights)[source]#

Combine the sigmas of the ruptures falling in the same (mag, dist) bin, weighting the GSIMs with the given weights. Since the sigmas are dispersions, the combination is done in the variance domain, i.e. in quadrature.

Parameters:

weights – an array of G weights, one per gsim of the cmaker

Returns:

an array of shape (Ma, D, M), zero in the bins not covered by any rupture

openquake.hazardlib.calc.disagg.assert_same_shape(arrays)[source]#

Raises an AssertionError if the shapes are not consistent

openquake.hazardlib.calc.disagg.disagg_source(dis, src_mutex, monitor)[source]#

Compute the rates and the sigmas for a group of sources, weighted by the logic tree realizations of the group (i.e. by the GSIM weights returned by FullLogicTree.g_weights).

Returns:

a dictionary with keys source_id, sid, rates (Ma, D, E, M), std (Ma, D, M), weight

openquake.hazardlib.calc.disagg.disaggregation(sources, site, imt, iml, gsim_by_trt, truncation_level, n_epsilons=None, mag_bin_width=None, dist_bin_width=None, coord_bin_width=None, source_filter=<openquake.hazardlib.calc.filters.SourceFilter object>, epsstar=False, bin_edges={}, **kwargs)[source]#

Compute “Disaggregation” matrix representing conditional probability of an intensity measure type imt exceeding, at least once, an intensity measure level iml at a geographical location site, given rupture scenarios classified in terms of:

  • rupture magnitude

  • Joyner-Boore distance from rupture surface to site

  • longitude and latitude of the surface projection of a rupture’s point closest to site

  • epsilon: number of standard deviations by which an intensity measure level deviates from the median value predicted by a GSIM, given the rupture parameters

  • rupture tectonic region type

In other words, the disaggregation matrix allows to compute the probability of each scenario with the specified properties (e.g., magnitude, or the magnitude and distance) to cause one or more exceedences of a given hazard level.

For more detailed information about the disaggregation, see for instance “Disaggregation of Seismic Hazard”, Paolo Bazzurro, C. Allin Cornell, Bulletin of the Seismological Society of America, Vol. 89, pp. 501-520, April 1999.

Parameters:
  • sources – Seismic source model, as for PSHA calculator it should be an iterator of seismic sources.

  • site – Site of interest to calculate disaggregation matrix for.

  • imt – Instance of intensity measure type class.

  • iml – Intensity measure level. A float value in units of imt.

  • gsim_by_trt – Tectonic region type to GSIM objects mapping.

  • truncation_level – Float, number of standard deviations for truncation of the intensity distribution.

  • n_epsilons – Integer number of epsilon histogram bins in the result matrix.

  • mag_bin_width – Magnitude discretization step, width of one magnitude histogram bin.

  • dist_bin_width – Distance histogram discretization step, in km.

  • coord_bin_width – Longitude and latitude histograms discretization step, in decimal degrees.

  • source_filter – Optional source-site filter function. See openquake.hazardlib.calc.filters.

  • epsstar – A boolean. When true disaggregations results including epsilon are in terms of epsilon star rather then epsilon.

  • bin_edges – Bin edges provided by the users. These override the ones automatically computed by the OQ Engine.

Returns:

A tuple of two items. First is itself a tuple of bin edges information for (in specified order) magnitude, distance, longitude, latitude, epsilon and tectonic region types.

Second item is 6d-array representing the full disaggregation matrix. Dimensions are in the same order as bin edges in the first item of the result tuple. The matrix can be used directly by pmf-extractor functions.

openquake.hazardlib.calc.disagg.fill_gaps(sig, M)[source]#

Fill the (mag, dist) bins not covered by any rupture with the value of the first covered bin, since the sigmas are artificially zero there.

Parameters:

sig – an array of shape (Ma, D, M)

Returns:

the filled array

openquake.hazardlib.calc.disagg.gen_disagg_source(groups, site, edges_shapedic, oq, full_lt)[source]#

Compute disaggregation for the given sources. Assume oq.imtls has a single level for each IMT.

NB: there is no need to reduce the logic tree, since the sources already store the trt_smrs of the logic tree realizations they belong to, i.e. src.sampling[‘trt_smr’].

Parameters:
  • groups – groups containing sources with a single base ID

  • site – a Site object

  • edges_shapedic – pair (bin_edges, shapedic)

  • oq – OqParam instance

  • full_lt – a FullLogicTree instance

Returns:

generators of (Disaggregator, src_mutex) pairs, one per group

openquake.hazardlib.calc.disagg.get_edges_shapedic(oq, sitecol, num_tot_rlzs=None)[source]#
Returns:

(mag dist lon lat eps trt) edges and shape dictionary

openquake.hazardlib.calc.disagg.get_eps4(eps_edges, truncation_level)[source]#
Returns:

eps_min, eps_max, eps_bands, eps_cum

openquake.hazardlib.calc.disagg.get_ints(src_ids)[source]#
Returns:

array of integers from source IDs following the colon convention

openquake.hazardlib.calc.disagg.lon_lat_bins(lon, lat, size_km, coord_bin_width)[source]#

Define lon, lat bin edges for disaggregation histograms.

Parameters:
  • lon – longitude of the site

  • lat – latitude of the site

  • size_km – total size of the bins in km

  • coord_bin_width – bin width in degrees

Returns:

two arrays lon bins, lat bins

openquake.hazardlib.calc.disagg.split_by_magbin(ctxt, mag_edges)[source]#
Parameters:
  • ctxt – a context array

  • mag_edges – magnitude bin edges

Returns:

a dictionary magbin -> ctxt

openquake.hazardlib.calc.disagg.uniform_bins(min_value, max_value, bin_width)[source]#

Returns an array of bins including all values:

>>> uniform_bins(1, 10, 1.)
array([ 1.,  2.,  3.,  4.,  5.,  6.,  7.,  8.,  9., 10.])
>>> uniform_bins(1, 10, 1.1)
array([ 0. ,  1.1,  2.2,  3.3,  4.4,  5.5,  6.6,  7.7,  8.8,  9.9, 11. ])

Fault Displacement (displacement)#

Probabilistic Fault Displacement (PFD) rate kernel (PR-6 of the oq-engine integration plan, Workstream D).

The kernel is the engine-idiomatic port of oq-pfdha’s calc/hazard.py::_compute_rupture_contribution plus its calc/location_weight.py. It computes, per surface-rupturing rupture and per site, the annual exceedance rates of fault displacement:

lambda_principal = rate * P_sr * P_fd_primary * W_p(r) lambda_distributed = rate * P_sr * P_dist_combined(r) * G(r)

W_p(r) is the rupture-location weight (see location_weight()); the distributed weight G depends on the W_p path:

  • r_sigma_km == 0 – boxcar W_p = 1{|r| <= r_threshold_km} and the COMPLEMENTARY split G = 1 - W_p (Youngs 2003 / Takao 2013 either/or);

  • r_sigma_km > 0 – Petersen et al. (2011) pinned, +/-2-sigma Gaussian W_p and the ADDITIVE split G = 1 (eq. 1 + eq. 2, “total hazard”).

An aggregate-definition primary FD model (Sarmiento et al. 2025 Table 1, the class choice IS the definition) already includes the distributed contribution: lambda_total = rate * P_sr * P_fd_aggregate * W_p flows through the principal bucket and the distributed bucket stays zero.

The kernel deliberately does NOT call get_mean_stds/get_poes (decision D12): the PFD models yield exceedance probabilities directly. The calculator wraps the returned rate arrays into the engine’s MapArray and reuses all downstream stats/export machinery.

The pure functions here take objects exposing the adapter protocol (openquake.pfd.adapter.PFDModelAdapter: compute_primary_sr, compute_primary_fd, compute_secondary_sr, compute_secondary_fd, each (ctx, ...) -> array), keyed by the slot names primary_sr / primary_fd / secondary_sr / secondary_fd. The Visini rank-2 combined pipeline (Workstream H) is not part of this kernel yet; a Visini chain is routed through the generic SR x FD path until then.

openquake.hazardlib.calc.displacement.DEFAULT_RED_CFG = {'method': 'mean'}#

default Monte-Carlo / epistemic reduction; the mean is oq-pfdha’s default and is exact inside the rate sum (expectation is linear), so the engine reproduces oq-pfdha’s mean hazard curve. The median is a legacy central-estimate heuristic that deviates at high displacement levels.

openquake.hazardlib.calc.displacement.calc_rates(contexts: Sequence[Any], n_sites: int, adapters: Mapping[str, Any], imls: ndarray, r_threshold_km: float, r_sigma_km: float, red_cfg: Dict[str, Any] | None = None) → Tuple[ndarray, ndarray, ndarray][source]#

Accumulate the PFD annual exceedance rates over a sequence of contexts.

Returns:

(rates, principal, distributed), each (n_sites, D); rates = principal + distributed

openquake.hazardlib.calc.displacement.calc_rupture_contribution(ctx, adapters: Mapping[str, Any], imls: ndarray, r_threshold_km: float, r_sigma_km: float, red_cfg: Dict[str, Any] | None = None) → Tuple[ndarray, ndarray][source]#

Principal and distributed annual-rate contributions of one rupture.

Parameters:
  • ctx – a rupture context with occurrence_rate, rtor and (for the adapters) the usual rupture/site fields

  • adapters – slot name -> adapter; missing slots contribute zero (primary SR defaults to 1, the “always surface-ruptures” assumption)

  • imls – displacement levels (m), shape (D,)

  • r_threshold_km – boxcar half-width for the W_p sigma == 0 path

  • r_sigma_km – mapping-error sigma; 0 selects the complementary split

  • red_cfg – Monte-Carlo reduction config

Returns:

(principal, distributed), each (N, D) annual rates

openquake.hazardlib.calc.displacement.location_weight(r, r_threshold_km: float, r_sigma_km: float, r_sigma_truncation: float = 2.0) → ndarray[source]#

Principal-contribution rupture-location weight W_p(r).

Two mutually exclusive paths (Petersen et al. 2011, Tables 2-3 and p. 819; see oq-pfdha docs/design/rupture_location_uncertainty.md):

  • r_sigma_km == 0: the legacy boxcar 1{|r| <= r_threshold_km};

  • r_sigma_km > 0: Petersen’s Gaussian mapping-error weight, pinned to 1 on the trace and truncated beyond +/- r_sigma_truncation * sigma, with r_threshold_km playing no role.

Parameters:
  • r – across-strike distance(s) to the mapped trace, km (ctx.rtor)

  • r_threshold_km – boxcar half-width h (sigma == 0 path only)

  • r_sigma_km – two-sided mapping-error sigma (km); 0 selects the boxcar

  • r_sigma_truncation – truncation n in +/-n*sigma for the Gaussian path (Petersen p. 819: n = 2)

Returns:

float64 array with the shape of r; W_p(0) == 1

Filters (filters)#

exception openquake.hazardlib.calc.filters.FilteredAway[source]#

Bases: Exception

class openquake.hazardlib.calc.filters.IntegrationDistance[source]#

Bases: dict

A dictionary trt -> [(mag, dist), …]

cut(min_mag_by_trt)[source]#

Cut the lower magnitudes. For instance

>>> maxdist = IntegrationDistance.new('[(4., 50), (8., 200.)]')
>>> maxdist.cut({'default': 5.})
>>> maxdist
{'default': [(5.0, 87.5), (8.0, 200.0)]}
>>> maxdist = IntegrationDistance.new('200')
>>> maxdist.cut({"Active Shallow Crust": 5.2, "default": 4.})
>>> maxdist
{'default': [(4.0, 200.0), (10.2, 200)], 'Active Shallow Crust': [(5.2, 200.0), (10.2, 200)]}
get_bounding_box(lon, lat, trt=None)[source]#

Build a bounding box around the given lon, lat by computing the maximum_distance at the given tectonic region type and magnitude.

Parameters:
  • lon – longitude

  • lat – latitude

  • trt – tectonic region type, possibly None

Returns:

min_lon, min_lat, max_lon, max_lat

get_dist_bins(trt, nbins=51)[source]#
Returns:

an array of distance bins, from 10m to maxdist

classmethod new(value)[source]#
Parameters:

value – string to be converted

Returns:

IntegrationDistance dictionary

>>> md = IntegrationDistance.new('50')
>>> md
{'default': [(2.5, 50), (10.2, 50)]}
class openquake.hazardlib.calc.filters.RuptureFilter(rup, dist)[source]#

Bases: object

Filter arrays/dataframes with lon, lat around a rupture

filter(lons, lats)[source]#
Returns:

(mask, rup-sites distances)

class openquake.hazardlib.calc.filters.SourceFilter(sitecol, integration_distance={'default': [(2.5, 1000), (10.2, 1000)]})[source]#

Bases: object

Filter objects have a .filter method yielding filtered sources and the IDs of the sites within the given maximum distance. Filter the sources by using self.sitecol.within_bbox which is based on numpy.

close_sids(src_or_rec, trt=None, maxdist=None)[source]#
Parameters:
  • src_or_rec – a source or a rupture record

  • trt – passed only if src_or_rec is a rupture record

Returns:

the site indices within the maximum_distance of the hypocenter, plus the maximum size of the bounding box

filter(sources)[source]#
Parameters:

sources – a sequence of sources

Yields:

pairs (sources, sites)

get_close(secparams)[source]#
Parameters:

secparams – a structured array with fields tl0, tl1, tr0, tr1

Returns:

an array with the number of close sites per secparams

get_close_sites(source, trt=None)[source]#

Returns the sites within the integration distance from the source, or None.

get_enlarged_box(src, maxdist)[source]#

Get the enlarged bounding box of a source.

Parameters:
  • src – a source object

  • maxdist – a scalar maximum distance

Returns:

a bounding box (min_lon, min_lat, max_lon, max_lat)

multiplier = 1#
reduce(multiplier=5)[source]#

Reduce the SourceFilter to a subset of sites

split(sources)[source]#
Yields:

pairs (split, sites)

openquake.hazardlib.calc.filters.close_ruptures(ruptures, sitecol, h5=None, magdist=<scipy.interpolate._interpolate.interp1d object>)[source]#
Parameters:
  • ruptures – an array of rupture records

  • sitecol – a SiteCollection instance

  • assetcol – an AssetCollection or None

  • h5 – hdf5 where to save the performance info

Returns:

the ruptures close to the sites

openquake.hazardlib.calc.filters.context(src)[source]#

Used to add the source_id to the error message. To be used as

with context(src):

operation_with(src)

Typically the operation is filtering a source, that can fail for tricky geometries.

openquake.hazardlib.calc.filters.filter_rups(ruptures, sitetree, orig_sids, dist, mon)[source]#
Parameters:
  • ruptures – array of ruptures with the same magnitude

  • sitetree – kdtree for the reduced sites

  • dist – integration distance at that magnitude

Returns:

ruptures close to the global site collection

openquake.hazardlib.calc.filters.filter_site_array_around(array, rup, dist)[source]#
Parameters:
  • array – array with fields ‘lon’, ‘lat’

  • rup – a rupture object

  • dist – integration distance in km

Returns:

slice to the rupture

openquake.hazardlib.calc.filters.floatdict(value)[source]#
Parameters:

value – input string corresponding to a literal Python number or dictionary

Returns:

a Python dictionary key -> number

>>> floatdict("200")
{'default': 200}
>>> floatdict("{'active shallow crust': 250., 'default': 200}")
{'active shallow crust': 250.0, 'default': 200}
openquake.hazardlib.calc.filters.get_distances(rupture, sites, param)[source]#
Parameters:
  • rupture – a rupture

  • sites – a mesh of points or a site collection

  • param – the kind of distance to compute (default rjb)

  • dcache – distance cache dictionary or None if disabled

Returns:

an array of distances from the given sites

openquake.hazardlib.calc.filters.get_dparam(surface, sites, param)[source]#
openquake.hazardlib.calc.filters.getdefault(dic_with_default, key)[source]#
Parameters:
  • dic_with_default – a dictionary with a ‘default’ key

  • key – a key that may be present in the dictionary or not

Returns:

the value associated to the key, or to ‘default’

openquake.hazardlib.calc.filters.magdepdist(pairs=((2.5, 1000), (10.2, 1000)))[source]#
Parameters:

pairs – a list of pairs [(mag, dist), …]

Returns:

a scipy.interpolate.interp1d function

openquake.hazardlib.calc.filters.magstr(mag)[source]#
Returns:

a string representation of the magnitude

openquake.hazardlib.calc.filters.rup_radius(rup)[source]#

Maximum distance from the rupture mesh to the hypocenter

openquake.hazardlib.calc.filters.split_source(src)[source]#
Parameters:

src – a splittable (or not splittable) source

Returns:

the underlying sources (or the source itself)

openquake.hazardlib.calc.filters.unique_sorted(items)[source]#

Check that the items are unique and sorted

openquake.hazardlib.calc.filters.upper_maxdist(idist)[source]#
Returns:

the maximum distance in a dictionary trt->dists

Ground Motion Fields (gmf)#

Module gmf exports ground_motion_fields().

exception openquake.hazardlib.calc.gmf.CorrelationButNoInterIntraStdDevs(corr, gsim)[source]#

Bases: Exception

class openquake.hazardlib.calc.gmf.GmfComputer(rupture, sitecol, cmaker, within_event_model=None, between_event_model=None, amplifier=None, sec_perils=(), **legacy)[source]#

Bases: object

Given an earthquake rupture, the GmfComputer computes ground shaking over a set of sites, by randomly sampling a ground shaking intensity model.

Parameters:

rupture – EBRupture to calculate ground motion fields radiated from.

:param openquake.hazardlib.site.SiteCollection sitecol:

a complete SiteCollection

Parameters:
  • cmaker – a openquake.hazardlib.gsim.base.ContextMaker instance

  • within_event_model – Instance of a within-event correlation model object. See openquake.hazardlib.correlation_models. Can be None, in which case non-correlated ground motion fields are calculated. Correlation model is not used if truncation_level is zero.

  • between_event_model – Instance of a between-event correlation model object. See openquake.hazardlib.correlation_models. Can be None, in which case non-cross-correlated ground motion fields are calculated.

  • amplifier – None or an instance of Amplifier

  • sec_perils – Tuple of secondary perils. See openquake.hazardlib.sep. Can be None, in which case no secondary perils need to be evaluated.

build_sig_eps(se_dt, event_indices=None)[source]#
Returns:

a structured array of size E with fields (eid, rlz_id, sig_inter_IMT, eps_inter_IMT)

compute_all(MNE=None, cmon=<Monitor [runner]>, umon=<Monitor [runner]>)[source]#
Returns:

DataFrame with fields eid, rlz, sid, gmv_X, …

compute_all_batches(cmon=<Monitor [runner]>, umon=<Monitor [runner]>)[source]#

Yield bounded GMF tables and their global event indices.

property correlation_model#

Compatibility alias for within_event_model.

property cross_correl#

Compatibility alias for between_event_model.

static get_symmetric_bounds(cov_matrix, level)[source]#

Calculates the lower and upper bound vectors for symmetric truncation based on the marginal standard deviations of the covariance matrix.

init_eid_rlz_sig_eps()[source]#

Initialize the attributes eid, rlz, sig, eps with shapes E, E, EM, EM

mtp_dt = dtype([('rup_id', '<i8'), ('site_id', '<u4'), ('gsim_id', '<u2'), ('imt_id', 'u1'), ('mea', '<f4'), ('tau', '<f4'), ('phi', '<f4')])#
strip_zeros(data, event_indices=None)[source]#
Returns:

a DataFrame with the nonzero GMVs

tabulate_conditioned(fields, mean, g, indices, rng=None)[source]#

Convert one batch of conditioned log fields to a GMF table.

property tlb#
property tlw#
update(data, array, rlzs, mean, max_iml=None, event_indices=None)[source]#

Updates the data dictionary with the values coming from the array of GMVs. Also indirectly updates the arrays .sig and .eps.

openquake.hazardlib.calc.gmf.build_eid_sid_rlz(allrlzs, sids, eids, rlzs)[source]#
openquake.hazardlib.calc.gmf.calc_gmf_simplified(ebrupture, sitecol, cmaker)[source]#

A simplified version of the GmfComputer for event based calculations. Used only for pedagogical purposes. Here is an example of usage:

from unittest.mock import Mock import numpy from openquake.hazardlib import valid, contexts, site, geo from openquake.hazardlib.source.rupture import EBRupture, build_planar from openquake.hazardlib.calc.gmf import calc_gmf_simplified, GmfComputer

imts = [‘PGA’] rlzs = np.arange(3, dtype=np.uint32) rlzs_by_gsim = {valid.gsim(‘BooreAtkinson2008’): rlzs} lons = [0., 0.] lats = [0., 1.] siteparams = Mock(reference_vs30_value=760.) sitecol = site.SiteCollection.from_points(lons, lats, sitemodel=siteparams) hypo = geo.point.Point(0, .5, 20) rup = build_planar(hypo, mag=7., rake=0.) cmaker = contexts.simple_cmaker(rlzs_by_gsim, imts, truncation_level=3.) ebr = EBRupture(rup, 0, 0, n_occ=2, id=1) ebr.seed = 42 print(cmaker) print(sitecol.array) print(ebr)

gmfa = calc_gmf_simplified(ebr, sitecol, cmaker) print(gmfa) # numbers considering the full site collection sites = site.SiteCollection.from_points([0], [1], sitemodel=siteparams) gmfa = calc_gmf_simplified(ebr, sites, cmaker) print(gmfa) # different numbers considering half of the site collection

openquake.hazardlib.calc.gmf.exp(vals, notMMI)[source]#

Exponentiate the values unless the IMT is MMI

openquake.hazardlib.calc.gmf.ground_motion_fields(rupture, sites, imts, gsim, truncation_level, realizations, correlation_model=None, seed=0)[source]#

Given an earthquake rupture, the ground motion field calculator computes ground shaking over a set of sites, by randomly sampling a ground shaking intensity model. A ground motion field represents a possible ‘realization’ of the ground shaking due to an earthquake rupture.

Note

This calculator is using random numbers. In order to reproduce the same results numpy random numbers generator needs to be seeded.

Parameters:
  • rupture (openquake.hazardlib.source.rupture.Rupture) – Rupture to calculate ground motion fields radiated from.

  • sites (openquake.hazardlib.site.SiteCollection) – Sites of interest to calculate GMFs.

  • imts – List of intensity measure type objects (see openquake.hazardlib.imt).

  • gsim – Ground-shaking intensity model, instance of subclass of either GMPE or IPE.

  • truncation_level – Float, number of standard deviations for truncation of the intensity distribution

  • realizations – Integer number of GMF simulations to compute.

  • correlation_model – Instance of correlation model object. See openquake.hazardlib.correlation. Can be None, in which case non-correlated ground motion fields are calculated. Correlation model is not used if truncation_level is zero.

  • seed (int) – The seed used in the numpy random number generator

Returns:

Dictionary mapping intensity measure type objects (same as in parameter imts) to 2d numpy arrays of floats, representing different simulations of ground shaking intensity for all sites in the collection. First dimension represents sites and second one is for simulations.

openquake.hazardlib.calc.gmf.set_max_min(array, mean, max_iml, min_iml, mmi_index)[source]#

Hazard Curves (hazard_curve)#

openquake.hazardlib.calc.hazard_curve implements calc_hazard_curves(). Here is an example of a classical PSHA parallel calculator computing the hazard curves per each realization in less than 20 lines of code:

import sys
from openquake.commonlib import logs
from openquake.calculators.base import calculators

def main(job_ini):
    with logs.init(job_ini) as log:
        calc = calculators(log.get_oqparam(), log.calc_id)
        calc.run(individual_rlzs='true', shutdown=True)
        print('The hazard curves are in %s::/hcurves-rlzs'
             % calc.datastore.filename)

if __name__ == '__main__':
    main(sys.argv[1])  # path to a job.ini file

NB: the implementation in the engine is smarter and more efficient. Here we start a parallel computation per each realization, the engine manages all the realizations at once.

openquake.hazardlib.calc.hazard_curve.calc_hazard_curves(groups, srcfilter, imtls, gsim_by_trt, truncation_level=99.0, apply=<function sequential_apply>, reqv=None, **kwargs)[source]#

Compute hazard curves on a list of sites, given a set of seismic source groups and a dictionary of ground shaking intensity models (one per tectonic region type).

Probability of ground motion exceedance is computed in different ways depending if the sources are independent or mutually exclusive.

Parameters:
  • groups – A sequence of groups of seismic sources objects (instances of of BaseSeismicSource).

  • srcfilter – A source filter over the site collection or the site collection itself

  • imtls – Dictionary mapping intensity measure type strings to lists of intensity measure levels.

  • gsim_by_trt – Dictionary mapping tectonic region types (members of openquake.hazardlib.const.TRT) to GMPE or IPE objects.

  • truncation_level – Float, number of standard deviations for truncation of the intensity distribution.

  • apply – apply function to use (default sequential_apply)

  • reqv – If not None, an instance of RjbEquivalent

Returns:

An array of size N, where N is the number of sites, which elements are records with fields given by the intensity measure types; the size of each field is given by the number of levels in imtls.

openquake.hazardlib.calc.hazard_curve.classical(group, sitecol, cmaker)[source]#

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 for gsims, which is a list of GSIM instances.

Parameters:
  • group – a list of sources or of atomic groups

  • sitecol – a filtered SiteCollection instance

Returns:

a dictionary with keys pmap, source_data, rup_data, extra

Stochastic Event Set (stochastic)#

openquake.hazardlib.calc.stochastic contains stochastic_event_set().

openquake.hazardlib.calc.stochastic.get_rup_array(ebruptures, magdist)[source]#

Convert a list of EBRuptures into a numpy composite array, by filtering out the ruptures below the minimum msgnitude.

openquake.hazardlib.calc.stochastic.num_rup_ids(group)[source]#
Parameters:

group – a sequence of sources with the uncertainties applied

Returns:

the number of rupture IDs generated by the group, i.e. the number of ruptures of each source times the number of realizations of the source

openquake.hazardlib.calc.stochastic.sample_cluster(group, num_ses, ses_seed, offset=0)[source]#

Yields ruptures generated by a cluster of sources

Parameters:
  • group – A sequence of sources of the same group

  • num_ses – Number of stochastic event sets

  • ses_seed – Global seed for rupture sampling

  • offset – Offset of the rupture IDs, i.e. the number of rupture IDs already generated by the other sets of realizations

Yields:

dictionaries with keys rup_array, source_data, eff_ruptures

openquake.hazardlib.calc.stochastic.sample_ruptures(sources, param, monitor=<Monitor [runner]>)[source]#
Parameters:
  • sources – a sequence of sources of the same group

  • param – a dictionary with ses_per_logic_tree_path, ses_seed, magdist and bset_values, i.e. the uncertainties to apply (optional, if there are no uncertainties)

  • monitor – monitor instance

Yields:

dictionaries with keys rup_array, source_data

openquake.hazardlib.calc.stochastic.unique_sampling(sources)[source]#

Sanity check: all sources in the atomic group must share the same sampling