# 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]]>})]
```
`compute`(sids, pmaps)[source]
Params sids: array of N site IDs pmaps – array of R simple ProbabilityMaps a list of pairs [(‘mean’, ...), (‘quantile-XXX’, ...), ...]
`compute_pmap`(sids, pmaps)[source]
Params sids: array of N site IDs pmaps – array of R simple ProbabilityMaps a ProbabilityMap with arrays of size (num_levels, num_stats)
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  ]>
```
`convert`(imtls, idx=0)[source]

Convert a probability curve into a record of dtype imtls.imt_dt.

Parameters: imtls – DictArray instance idx – extract the data corresponding to the given inner index
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) 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.

`filter`(sids)[source]

Extracs a submap of self for the given sids.

`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

`openquake.hazardlib.probability_map.``get_shape`(pmaps)[source]
Parameters: pmaps – a set of homogenous ProbabilityMaps the common shape (N, L, I)