-
Notifications
You must be signed in to change notification settings - Fork 0
/
mdispCompare.py
executable file
·57 lines (49 loc) · 1.92 KB
/
mdispCompare.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
import numpy as np
import argparse
from multiprocessing import Pool
parser = argparse.ArgumentParser(description='Compare 2 spectra files.')
parser.add_argument('bins', help='Bins on which the comparison should be made, should be the same file as the used in reducing the binned spectra.', type=str)
parser.add_argument('spectra1', help='First spectra, the one that will be devided.', type=str)
parser.add_argument('spectra2', help='Second spectra, the one we will divide BY.', type=str)
args = parser.parse_args()
cpuNumber = 2
print('Loading files.')
binData = np.loadtxt(args.bins, ndmin=2)
print('bins loaded')
data = np.loadtxt(args.spectra1)
print('first spectra loaded')
data2 = np.loadtxt(args.spectra2)
print('All files loaded, starting comparison!')
def compare(data):
average = []
global binData
summ, count, i, j = 0, 0, 0, 0
spectraLength = len(data)
while i < spectraLength:
if j == len(binData):
break
if (data[i][0] >= binData[j][0]) and ((data[i][0]) < binData[j][1]):
count += 1
summ += data[i][1]
i += 1
if i == spectraLength - 1:
average.append(summ / count)
for k in range(j + 1, len(binData)):
average.append(0)
break
elif data[i][0] < binData[j][0]:
i += 1
elif data[i][0] >= binData[j][0]:
j += 1
if summ > 0:
average.append(summ / count)
else:
average.append(0)
summ, count = 0, 0
return average
p = Pool(cpuNumber)
average = p.map(compare, [data, data2])
output = np.c_[binData, np.divide(average[0], average[1])]
np.savetxt(args.spectra1 + 'Comparison', output, fmt='%.7e')
np.savetxt(args.spectra1 + '.averaged', np.c_[binData, average[0]], fmt='%.7e')
np.savetxt(args.spectra2 + '.averaged', np.c_[binData, average[1]], fmt='%.7e')