Package openquake.hazardlib.calc contains hazard calculator modules and utilities for them, such as filters.
openquake.hazardlib.calc.stochastic contains stochastic_event_set().
Generates a ‘Stochastic Event Set’ (that is a collection of earthquake ruptures) representing a possible realization of the seismicity as described by a source model.
The calculator loops over sources. For each source, it loops over ruptures. For each rupture, the number of occurrence is randomly sampled by calling openquake.hazardlib.source.rupture.BaseProbabilisticRupture.sample_number_of_occurrences()
Note
This calculator is using random numbers. In order to reproduce the same results numpy random numbers generator needs to be seeded, see http://docs.scipy.org/doc/numpy/reference/generated/numpy.random.seed.html
Parameters: 


Returns:  Generator of Rupture objects that are contained in an event set. Some ruptures can be missing from it, others can appear one or more times in a row. 
openquake.hazardlib.calc.hazard_curve implements hazard_curves().
Aggregate hazard curves by composing the probabilities.
Parameters: 


Returns:  a new accumulator 
Compute hazard curves on a list of sites, given a set of seismic sources and a set of ground shaking intensity models (one per tectonic region type considered in the seismic sources).
Probability of ground motion exceedance is computed using the following formula
P(X≥xT) = 1  ∏ ∏ Prup_ij(X<xT)
where P(X≥xT) is the probability that the ground motion parameter X is exceeding level x one or more times in a time span T, and Prup_ij(X<xT) is the probability that the jth rupture of the ith source is not producing any ground motion exceedance in time span T. The first product ∏ is done over sources, while the second one is done over ruptures in a source.
The above formula computes the probability of having at least one ground motion exceedance in a time span as 1 minus the probability that none of the ruptures in none of the sources is causing a ground motion exceedance in the same time span. The basic assumption is that seismic sources are independent, and ruptures in a seismic source are also independent.
Parameters: 


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. 
Deprecated. It does the same job of openquake.hazardlib.calc.hazard_curve.calc_hazard_curves(), with the only difference that the intensity measure types in input and output are hazardlib objects instead of simple strings.
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.
Returns:  A list of G arrays of size N, where N is the number of sites and G the number of gsims. Each array contains records with fields given by the intensity measure types; the size of each field is given by the number of levels in imtls. 

Module gmf exports ground_motion_fields().
Given an earthquake rupture, the ground motion field computer computes ground shaking over a set of sites, by randomly sampling a ground shaking intensity model. The usage is:
gmfcomputer = GmfComputer(rupture, r_sites, imts, gsims,
truncation_level, correlation_model)
gmf1 = gmfcomputer.compute(seed1)
gmf2 = gmfcomputer.compute(seed2)
Parameters: 


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. If a nontrivial filtering function is passed, the final result is expanded and filled with zeros in the places corresponding to the filtered out sites.
Note
This calculator is using random numbers. In order to reproduce the same results numpy random numbers generator needs to be seeded, see http://docs.scipy.org/doc/numpy/reference/generated/numpy.random.seed.html
Parameters: 


Returns:  Dictionary mapping intensity measure type objects (same as in parameter imts) to 2d numpy arrays of floats, representing different realizations of ground shaking intensity for all sites in the collection. First dimension represents sites and second one is for realizations. 
Module openquake.hazardlib.correlation defines correlation models for spatiallydistributed groundshaking intensities.
Base class for correlation models for spatiallydistributed groundshaking intensities.
Apply correlation to randomly sampled residuals.
Parameters: 


Returns:  Array of the same structure and semantics as residuals but with correlations applied. 
Get lowertriangle matrix as a result of Choleskydecomposition of correlation matrix.
The resulting matrix should have zeros on values above the main diagonal.
The actual implementations of BaseCorrelationModel interface might calculate the matrix considering site collection and IMT (like JB2009CorrelationModel does) or might have it preconstructed for a specific site collection and IMT, in which case they will need to make sure that parameters to this function match parameters that were used to precalculate decomposed correlation matrix.
Parameters: 


“Correlation model for spatially distributed groundmotion intensities” by Nirmal Jayaram and Jack W. Baker. Published in Earthquake Engineering and Structural Dynamics 2009; 38, pages 16871708.
Parameters:  vs30_clustering – Boolean value to indicate whether “Case 1” or “Case 2” from page 1700 should be applied. True value means that Vs 30 values show or are expected to show clustering (“Case 2”), False means otherwise. 

See BaseCorrelationModel.get_lower_triangle_correlation_matrix().
openquake.hazardlib.calc.disagg contains disaggregation() as well as several aggregation functions for extracting a specific PMF from the result of disaggregation().
Compute “Disaggregation” matrix representing conditional probability of an intensity mesaure type imt exceeding, at least once, an intensity measure level iml at a geographical location site, given rupture scenarios classified in terms of:
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. 501520, April 1999.
Parameters: 


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 6darray 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 pmfextractor functions. 
Fold full disaggregation matrix to magnitude PMF.
Returns:  1d array, a histogram representing magnitude PMF. 

Fold full disaggregation matrix to distance PMF.
Returns:  1d array, a histogram representing distance PMF. 

Fold full disaggregation matrix to tectonic region type PMF.
Returns:  1d array, a histogram representing tectonic region type PMF. 

Fold full disaggregation matrix to magnitude / distance PMF.
Returns:  2d array. First dimension represents magnitude histogram bins, second one – distance histogram bins. 

Fold full disaggregation matrix to magnitude / distance / epsilon PMF.
Returns:  3d array. First dimension represents magnitude histogram bins, second one – distance histogram bins, third one – epsilon histogram bins. 

Fold full disaggregation matrix to longitude / latitude PMF.
Returns:  2d array. First dimension represents longitude histogram bins, second one – latitude histogram bins. 

Module filters contain filter functions for calculators.
Filters are functions (or other callable objects) that should take generators and return generators. There are two different kinds of filter functions:
The purpose of both kinds of filters is to limit the amount of calculation to be done based on some criteria, like the distance between the source and the site. So common design feature of all the filters is the loop over pairs of the provided generator, filtering the sites collection, and if there are no items left in it, skipping the pair and continuing to the next one. If some sites need to be considered together with that source / rupture, the pair gets generated out, with a (possibly) limited site collection.
Consistency of filters’ input and output stream format allows several filters (obviously, of the same kind) to be chained together.
Filter functions should not make assumptions about the ordering of items in the original generator or draw more than one pair at once. Ideally, they should also perform reasonably fast (filtering stage that takes longer than the actual calculation on unfiltered collection only decreases performance).
Module openquake.hazardlib.calc.filters exports one distancebased filter function of each kind (see source_site_distance_filter() and rupture_site_distance_filter()) as well as “no operation” filters (source_site_noop_filter() and rupture_site_noop_filter()).
Filter out sites from the collection that are further from the rupture than some arbitrary threshold.
Parameters: 


Returns:  Filtered SiteCollection. 
This function is similar to openquake.hazardlib.source.base.BaseSeismicSource.filter_sites_by_distance_to_source(). The same notes about filtering criteria apply. Site should not be filtered out if it is not further than the integration distance from the rupture’s surface projection along the great circle arc (this is known as JoynerBoore distance, :meth:` openquake.hazardlib.geo.surface.base.BaseQuadrilateralSurface.get_joyner_boore_distance`).
Rupturesite filter based on distance.
Parameters:  integration_distance – Threshold distance in km, this value gets passed straight to openquake.hazardlib.calc.filters.filter_sites_by_distance_to_rupture() which is what is actually used for filtering. 

Rupturesite “noop” filter, same as source_site_noop_filter().
Sourcesite filter based on distance.
Parameters:  integration_distance – Threshold distance in km, this value gets passed straight to openquake.hazardlib.source.base.BaseSeismicSource.filter_sites_by_distance_to_source() which is what is actually used for filtering. 

Transparent sourcesite “noop” filter – behaves like a real filter but never filters anything out and doesn’t have any overhead.