-
Notifications
You must be signed in to change notification settings - Fork 0
/
rebin.py
118 lines (102 loc) · 3.08 KB
/
rebin.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
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
#!/disks/jets/cosmic/o.jamil/software/python/bin/ env python
from scipy import *
from pylab import *
print "Logarithmic/Geometric re-binning program:", '\n'
# var = int(raw_input("Enter 1 for logarithmic and 2 for geometric: "))
# #if var == 2:
# # geo = float(raw_input("Enter the geometric ratio: "))
# infile = raw_input("Enter the input file name: ")
# oufile = raw_input("Enter the output file name: ")
# binNums = float(raw_input("Enter the number of bins: "))
# xLoBound = float(raw_input("Enter the x-lower bound: "))
# xUpBound = float(raw_input("Enter the x-upper bound: "))
parArray=[]
inpar = open ("rebPar.par","r")
for line in inpar:
columns = line.split("=")
parArray.append( columns[1] )
var = int(parArray[0])
infile = parArray[1]
infile = infile.replace("\n","")
oufile = parArray[2]
oufile = oufile.replace("\n","")
binNums = float(parArray[3])
xLoBound = float(parArray[4])
xUpBound = float(parArray[5])
Y=[]
X=[]
inp = open (infile,"r")
for line in inp:
columns = line.split("\t")
X.append( float(columns[0]) )
Y.append( float(columns[1]) )
#temp for adding up the values that fall in the bin selected
temp=[]
#For logarithmic spacing
if var == 1:
X1=logspace(log10(xLoBound), log10(xUpBound), binNums)
#For geometric series
if var == 2:
geo=(xUpBound/xLoBound)**(1./(binNums-1.))
X1=[]
for g in range(1, int(binNums)+1, 1):
X1.append(xLoBound*(geo**(g-1.)))
Y1=[]
count = 1.0
sum = 0.0
prevSum = 0.0
#For logarithmic progression
if var == 1:
outfile=open(oufile,'wr')
for i in range(size(X1)):
for k in range(size(Y)):
if i==size(X1)-1:
temp.append( Y[k] )
sum += Y[k]
count += 1.0
elif i < size(X1)-1:
if X[k] >= X1[i] and X[k] < X1[i+1]:
temp.append( Y[k] )
sum += Y[k]
count += 1.0
else:
temp.append( 0.0 )
Y1.append( (sum/count) )
#prevSum = sum
sum = 0.0
count = 1.0
del temp[:]
for m in range(size(X1)):
if Y1[m] != 0.0:
s1=str(X1[m])
s2=str(Y1[m])
outfile.write(s1+"\t"+s2+"\n")
#For geometric progression
if var == 2:
outfile=open(oufile,'wr')
for i in range(size(X1)):
for k in range(size(Y)):
if i==size(X1)-1:
temp.append( Y[k] )
sum += Y[k]
count += 1.0
elif i < size(X1)-1:
if X[k] >= X1[i] and X[k] < X1[i+1]:
temp.append( Y[k] )
sum += Y[k]
count += 1.0
else:
temp.append( 0.0 )
Y1.append( (sum/count) )
#prevSum = sum
sum = 0.0
count = 1.0
del temp[:]
#output the x and y values
for m in range(size(X1)):
if Y1[m] != 0.0: #this does not output the zero values
s1=str(X1[m])
s2=str(Y1[m])
outfile.write(s1+"\t"+s2+"\n")
inp.close()
outfile.close()