-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_stability.py
More file actions
91 lines (89 loc) · 2.89 KB
/
Copy pathplot_stability.py
File metadata and controls
91 lines (89 loc) · 2.89 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import matplotlib.pyplot as plt
import numpy as np
import gvar as gv
import util_funcs as utf
import util_plots as utp
import defines as df
import define_prior as dfp
from lsqfit._utilities import gammaQ
import matplotlib as mpl
mpl.use('TkAgg')
def plot_stability(fit_collector,**kwargs):
"""
"""
fitCount = 0
hVal = [] ## -- horizontal axis value, ~ fit
hName = [] ## -- fit name, e.g. 1+1, 2+1...
hChi2 = [] ## -- fit chi2, for color coding
hQval = [] ## -- fit Q, for color coding
hValDatn = [] ## -- mostly same as hVal, but match size of enCentral and offset
hValDato = [] ## -- mostly same as hVal, but match size of eoCentral and offset
enCentral = []
eoCentral = []
enError = []
eoError = []
## -- tkey should be tuple: nst,ost, and 'fit' or 'prior' or other descriptor
for nst in range(1,15):
for ost in range(1,15):
tkey=(nst,ost,'fit')
### -- ignore fits with large chi2
try:
fit_collector[tkey] # check that this works
# dof = float(fit_collector[tkey]['dof'])
# npr = float(len(df.define_prior['nkey']))
# if (dof-npr*(nst+ost))*fit_collector[tkey]['chi2']/dof > df.max_chi2\
# or (dof-npr*(nst+ost))*fit_collector[tkey]['chi2']/dof < df.min_chi2:
# print (dof-npr*(nst+ost))*fit_collector[tkey]['chi2']/dof
# continue
except KeyError:
## -- lots of key errors; not a big deal
#print "KeyError"
continue
#except ZeroDivisionError:
# print "ZeroDivisionError"
# continue
## -- collect only important info
try:
Qval = gammaQ(fit_collector[tkey]['rdof']/2.,fit_collector[tkey]['chi2']/2.)
if Qval < 0.001:
continue
hQval.append(Qval)
except:
continue
#hQval.append(0)
hVal.append(fitCount+0.5)
if fit_collector[tkey]['rdof'] > 0:
hName.append(str(nst) +'+'+ str(ost)
+' (%.2g)' % gammaQ(fit_collector[tkey]['rdof']/2.,fit_collector[tkey]['chi2']/2.))
#+' ('+ str(round((dof-npr*(nst+ost))*fit_collector[tkey]['chi2']/dof,2))+')'
else:
hName.append(str(nst) +'+'+ str(ost) +' (?)')
#hChi2.append(fit_collector[tkey]['chi2'])
for key in fit_collector[tkey]:
sum=0
bkey = utf.get_basekey(key)
if bkey[1][-2:] == 'En' and (bkey[0] is None):
for x in fit_collector[tkey][key]:
hValDatn.append(fitCount+0.25)
sum += x.mean
enCentral.append(sum)
enError.append(x.sdev)
elif bkey[1][-2:] == 'Eo' and (bkey[0] is None):
for x in fit_collector[tkey][key]:
hValDato.append(fitCount+0.75)
sum += x.mean
eoCentral.append(sum)
eoError.append(x.sdev)
fitCount += 1
fig = plt.figure()
ax = fig.add_subplot(111)
plt.xticks(hVal,hName,rotation='vertical')
ax.set_xlim([0,fitCount])
ax.set_ylim([0.6,1.5])
ax.errorbar(hValDatn,enCentral,enError,
color='r',marker='o',linestyle='')
ax.errorbar(hValDato,eoCentral,eoError,
color='b',marker='o',linestyle='')
for x in range(1,fitCount):
ax.axvline(x,color='k')
plt.show()