From 8669b3b19e3173a1a1068e400a27a923bcc0d531 Mon Sep 17 00:00:00 2001 From: Michele Simionato Date: Sat, 5 Aug 2023 08:15:42 +0200 Subject: [PATCH] Added view_MPL --- openquake/calculators/views.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/openquake/calculators/views.py b/openquake/calculators/views.py index d911031adf51..7c8bd51df26c 100644 --- a/openquake/calculators/views.py +++ b/openquake/calculators/views.py @@ -1500,3 +1500,20 @@ def view_sources_branches(token, dstore): out = [(t, ' '.join(shorten(s)), b) for ((b, t), s) in sorted(acc.items())] return numpy.array(sorted(out), dt('trt sources branches')) + + +@view.add('MPL') +def view_MPL(token, dstore): + """ + Maximum Probable Loss at a given return period + """ + rp = int(token.split(':')[1]) + K = dstore['risk_by_event'].attrs['K'] + ltypes = list(dstore['agg_curves-stats']) + out = numpy.zeros(1, [(lt, float) for lt in ltypes]) + for ltype in ltypes: + # shape (K+1, S, P) + arr = dstore.sel(f'agg_curves-stats/{ltype}', + stat='mean', agg_id=K, return_period=rp) + out[ltype] = arr + return out