-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboxplot.py
More file actions
executable file
·149 lines (120 loc) · 3.8 KB
/
Copy pathboxplot.py
File metadata and controls
executable file
·149 lines (120 loc) · 3.8 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import numpy as np
import matplotlib.pyplot as plt
import scipy.signal
from scipy import stats
import math
import os
import pylab
def minmax(a, ind_mean, ind_var):
N,Y=a.shape
out=np.zeros((N,2))
for i in range(N):
out[i,0]=max(0, a[i,ind_mean]-a[i,ind_var])
out[i,1]=min(1, a[i,ind_mean]+a[i,ind_var])
return out
def buildbox(a,index):
dist=np.unique(a[:,0])
dist_nb=len(dist)
#print('Number of distances: ', dist_nb)
data = []
box_name = []
q1 = []
q2 = []
q3 = []
for i in range(dist_nb):
ext=np.where((a[:,0] == dist[i]))
data_boxi = a[ext[0][0]:ext[0][-1],index]
data.append(data_boxi)
if (i%5 == 0):
box_name.append(str(dist[i]))
else:
box_name.append('')
q1.append(np.percentile(data_boxi, 25))
q2.append(np.percentile(data_boxi, 50))
q3.append(np.percentile(data_boxi, 75))
return data,box_name,q1,q2,q3
# 0 dist
# 1 covpbb
# 2 medbandwidth
# 3 absolute residual (mean)
# 4 MSE (mean)
# 5 precision (mean)
detectors = ["aLIGO", "ADV", "KAGRA", "CE1", "CE2", "ET_B", "ET_C", "ET_D"]
signals = ["s20.0--SFHo", "s11.2--LS220", "s15.0--GShen", "s15.0--SFHo", "s15.0--LS220", "s20.0--LS220", "s25.0--LS220", "s40.0--LS220"]
detectors=["aLIGO"]
name="s20.0--SFHo"
#name="s11.2--LS220"
#name="s15.0--GShen"
#name="s15.0--LS220"
#name="s15.0--SFHo"
#name="s20.0--LS220"
#name="s25.0--LS220"
#name="s40.0--LS220"
try:
os.stat(name)
except:
os.mkdir(name)
for det in detectors:
title= 's20S ' + det
filename='results_intercept_false/results_AA_prewhiten_f2_' + name + '_' + det + '.txt'
a= np.loadtxt(filename, dtype='f', delimiter=' ')
dist=np.unique(a[:,0])
dist_nb=len(dist)
#print('Number of distances: ', dist_nb)
# coverage
data,box_name,q1,q2,q3=buildbox(a,1)
#plt.figure(figsize=(4, 3))
plt.figure()
blue_cross = dict(markerfacecolor='b', marker='+')
bx=plt.boxplot(data,flierprops=blue_cross)
pylab.xticks(range(1,dist_nb), box_name)
plt.xlabel('Distance [kpc]')
plt.ylabel('coverage')
plt.title(title)
plt.grid(False)
plt.xlim((1,30))
plt.ylim((0,1.05))
fig_name=name + '/' + name + '_covpbb_boxplot_' + det + '.png';
plt.savefig(fig_name)
fig_name=name + '/' + name + '_covpbb_boxplot_' + det + '.eps';
plt.savefig(fig_name)
fig_name=name + '/' + name + '_covpbb_boxplot_' + det + '.pdf';
plt.savefig(fig_name)
#plt.figure(figsize=(4, 3))
#plt.figure()
#plt.plot(dist, q2, 'b', label='Median')
#plt.fill_between(dist, q1, q3, alpha=0.05, facecolor='b', label="IQR")
#plt.xlabel('Distance [kpc]')
#plt.ylabel('coverage')
#plt.title(title)
#plt.grid(True)
#plt.legend(loc='best')
# delta
data,box_name,q1,q2,q3=buildbox(a,5)
#plt.figure(figsize=(4, 3))
plt.figure()
blue_cross = dict(markerfacecolor='b', marker='+')
bx=plt.boxplot(data, flierprops=blue_cross)
pylab.xticks(range(1,dist_nb), box_name)
plt.xlabel('Distance [kpc]')
plt.ylabel('$\Delta$')
plt.title(title)
plt.grid(False)
plt.ylim((0,3.5))
plt.xlim((1,30))
fig_name=name + '/' + name + '_error_boxplot_' + det + '.png';
plt.savefig(fig_name)
fig_name=name + '/' + name + '_error_boxplot_' + det + '.eps';
plt.savefig(fig_name)
fig_name=name + '/' + name + '_error_boxplot_' + det + '.pdf';
plt.savefig(fig_name)
#plt.figure(figsize=(4, 3))
#plt.figure()
#plt.plot(dist, q2, 'b', label='Median')
#plt.fill_between(dist, q1, q3, alpha=0.05, facecolor='b', label="IQR")
#plt.xlabel('Distance [kpc]')
#plt.ylabel('$\Delta$')
#plt.title(title)
#plt.grid(True)
#plt.legend(loc='best')
plt.show()