-
Notifications
You must be signed in to change notification settings - Fork 1
/
statdat.py
89 lines (74 loc) · 2.31 KB
/
statdat.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
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
import numpy as np
from scipy import stats
def statdat( dataset , Xcol, Ycol):
out =[]
while dataset.shape[0] != 0:
#print "# of rows in array = %d" % dataset.shape[0]
Xval = dataset [0, Xcol]
Yval = []
to_delete = []
if np.isnan(Xval):
to_delete.append(0)
dataset = np.delete( dataset, to_delete , axis=0)
continue
if Xcol >= dataset.shape[1] :
print "Column index for stat dat is larger than data columns available!"
exit(1)
for i in range( dataset.shape[0] ) :
row = dataset[i,:]
if row[Xcol] == Xval:
to_delete.append(i)
Yval.append( row[Ycol])
dataset = np.delete( dataset, to_delete , axis=0)
#print "# of rows in array = %d" % dataset.shape[0]
#print set
Yarray = np.array( Yval)
mean = np.mean(Yarray)
stddev = np.std(Yarray)
serror = stats.sem(Yarray)
pkpk = np.max( Yarray) - np.min( Yarray )
#print Yval
out.append( [Xval, mean, stddev, serror, pkpk] )
return np.array( out )
def bindat( dataset , Xcol, Ycol, X0, XF, nbins):
out =[]
bins,step = np.linspace(X0,XF,nbins, endpoint=False, retstep=True)
for b in bins:
if Xcol >= dataset.shape[1]:
print "Column index for stat dat is larger than data columns available!"
exit(1)
Xval = dataset [0, Xcol]
Yval = []
to_delete = []
if np.isnan(Xval):
to_delete.append(0)
dataset = np.delete( dataset, to_delete, axis=0)
continue
for i in range( dataset.shape[0] ) :
row = dataset[i,:]
if row[Xcol] >= b and row[Xcol]<b+step:
to_delete.append(i)
Yval.append( row[Ycol])
dataset = np.delete( dataset, to_delete , axis=0)
#print "# of rows in array = %d" % dataset.shape[0]
#print set
Yarray = np.array( Yval)
if Yarray.size == 1 :
mean = np.mean(Yarray)
stddev = 0.
serror = 0.
pkpk = 0.
out.append( [b+step/2., mean, stddev, serror, pkpk] )
elif Yarray.size > 1 :
mean = np.mean(Yarray)
stddev = np.std(Yarray)
serror = stats.sem(Yarray)
pkpk = np.max( Yarray) - np.min( Yarray )
out.append( [b+step/2., mean, stddev, serror, pkpk] )
else:
mean = np.nan
stddev = np.nan
serror = np.nan
pkpk = 0.
#print Yval
return np.array( out )