-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrorsummary.py
37 lines (29 loc) · 909 Bytes
/
errorsummary.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# Copyright (C) 2022 Giacomo Petrillo
# Released under the MIT license
import uncertainties
import collections
import numpy as np
def errorsummary(x):
"""
Returns error components of a ufloat as a ordered dictionary
where the keys are the tags of the components. Components
with the same tag are summed over. The ordering is greater
component first.
See also
--------
gvar.fmt_errorbudget
"""
comps = x.error_components()
# sum variance for each tag
var = collections.defaultdict(int)
for v, sd in comps.items():
var[v.tag] += sd ** 2
# sort by variance
tags = list(map(lambda v: v.tag, comps.keys()))
sds = np.sqrt(np.array([var[tag] for tag in tags]))
idx = np.argsort(sds)[::-1]
# fill ordered dictionary
d = collections.OrderedDict()
for i in idx:
d[tags[i]] = sds[i]
return d