ProbabilityCurve and ProbabilityMap¶
-
class
openquake.hazardlib.probability_map.
PmapStats
(quantiles, weights=None)[source]¶ A class to perform statistics on ProbabilityMaps.
Parameters: - weights – a list of weights
- quantiles – a list of floats in the range 0..1
Here is an example:
>>> pm1 = ProbabilityMap.build(3, 1, sids=[0, 1], ... initvalue=1.0) >>> pm2 = ProbabilityMap.build(3, 1, sids=[0], ... initvalue=0.8) >>> PmapStats(quantiles=[]).compute(sids=[0, 1], pmaps=[pm1, pm2]) [('mean', {0: <ProbabilityCurve [[ 0.9] [ 0.9] [ 0.9]]>, 1: <ProbabilityCurve [[ 0.5] [ 0.5] [ 0.5]]>})]
-
class
openquake.hazardlib.probability_map.
ProbabilityCurve
(array)[source]¶ This class is a small wrapper over an array of PoEs associated to a set of intensity measure types and levels. It provides a few operators, including the complement operator ~
~p = 1 - p
and the inclusive or operator |
p = p1 | p2 = ~(~p1 * ~p2)
Such operators are implemented efficiently at the numpy level, by dispatching on the underlying array.
Here is an example of use:
>>> poe = ProbabilityCurve(numpy.array([0.1, 0.2, 0.3, 0, 0])) >>> ~(poe | poe) * .5 <ProbabilityCurve [ 0.405 0.32 0.245 0.5 0.5 ]>
-
class
openquake.hazardlib.probability_map.
ProbabilityMap
(shape_y, shape_z)[source]¶ A dictionary site_id -> ProbabilityCurve. It defines the complement operator ~, performing the complement on each curve
~p = 1 - p
and the “inclusive or” operator |:
m = m1 | m2 = {sid: m1[sid] | m2[sid] for sid in all_sids}
Such operators are implemented efficiently at the numpy level, by dispatching on the underlying array. Moreover there is a classmethod .build(L, I, sids, initvalue) to build initialized instances of
ProbabilityMap
. The map can be represented as 3D array of shape (shape_x, shape_y, shape_z) = (N, L, I), where N is the number of site IDs, L the total number of hazard levels and I the number of GSIMs.-
array
¶ The underlying array of shape (N, L, I)
-
classmethod
build
(shape_y, shape_z, sids, initvalue=0.0)[source]¶ Parameters: - shape_y – the total number of intensity measure levels
- shape_z – the number of inner levels
- sids – a set of site indices
- initvalue – the initial value of the probability (default 0)
Returns: a ProbabilityMap dictionary
-
convert
(imtls, nsites=None, idx=0)[source]¶ Convert a probability map into a composite array of length nsites and dtype imtls.imt_dt.
Parameters: - imtls – DictArray instance
- nsites – the total number of sites (or None)
- idx – extract the data corresponding to the given inner index
-
extract
(inner_idx)[source]¶ Extracts a component of the underlying ProbabilityCurves, specified by the index inner_idx.
-
nbytes
¶ The size of the underlying array
-
setdefault
(sid, value)[source]¶ Works like dict.setdefault: if the sid key is missing, it fills it with an array and returns it.
Parameters: - sid – site ID
- value – value used to fill the returned array
-
sids
¶ The ordered keys of the map as a numpy.uint32 array
-