nhlibi: calculation results post-processing: mean/quantile curves

Bug #1025204 reported by Muharem Hrnjadovic
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenQuake (deprecated)
Fix Released
Medium
matley

Bug Description

Right now the nhlib based psha calculator only calculates plain hazard curves. We need to add post-processing logic that calculates mean/quantile curves as well.

The calculator should read the post_process configuration (for quantile/mean curves computation) from the .ini file in the [output] section. E.g.

[output]

mean_hazard_curves = true
quantile_hazard_curves = 0.1 0.6. 0.8 10.1

see also: https://bugs.launchpad.net/openquake/+bug/994033

Please mind that with the new calculator mean/quantile curves are calculated differently when no montecarlo sampling is considered.

When no Montecarlo sampling is considered, each path (ergo each realization) has a weight, then a weighted mean/quantile need to be computed (this was pointed out from a conversation with the dr. Monelli).

The output will be serialized into the db as follows:

For mean:
L Output, L HazardCurve L * N HazardCurveData.
where L is the number of Intensity Measure Types (IMTS) and N is the number of sites

For quantile:
L*M Output, L*M HazardCurve, L*M*N HazardCurveData,
where L is the number of IMTs, M is the number of quantile levels

Weighted quantile for a level can be computed as the inverse of the cdf of a discrete distribution where the values are given by the poe at that level (for the different realization) and the probabilities are given by the weights. To this aim, it is possible to use scipy.stats.rv_discrete#ppf or the following code:

def weighted_quantile(weights, curves, quantile):
    result_curve = []

    for poes in curves:
        sorted_poe_idxs = numpy.argsort(poes)
        sorted_weights = weights[sorted_poe_idxs]
        sorted_poes = poes[sorted_poe_idxs]
        cum_weights = numpy.cumsum(sorted_weights)
        result_curve.append(numpy.interp(quantile, cum_weights, sorted_poes))
    return result_curve

Tags: hazard nhlibi
Changed in openquake:
status: New → Confirmed
importance: Undecided → Medium
milestone: none → 0.8.2
tags: added: hazard nhlibi
summary: - nhlib calculation results post-processing: mean/quantile curves
+ nhlibi: calculation results post-processing: mean/quantile curves
matley (matley)
description: updated
matley (matley)
description: updated
matley (matley)
description: updated
matley (matley)
description: updated
Changed in openquake:
assignee: nobody → matley (matley)
matley (matley)
description: updated
matley (matley)
description: updated
matley (matley)
Changed in openquake:
status: Confirmed → Fix Committed
Changed in openquake:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.