-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprocessVBIoutput.py
46 lines (38 loc) · 1.12 KB
/
processVBIoutput.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
"""
1. Reads in VBI output and file_list
2. Selects non-zero models and outputs short_lists intenstites and
"""
import os
import sys
import numpy as np
def read_file_safe(filename, dtype="float64"):
"""
Simple check if file exists
:param filename:
:return:
"""
try:
results = np.genfromtxt(filename, dtype=dtype)
except IOError as err:
print(os.strerror(err.errno))
return results
def savetext(filename, string_array):
"""
:param string_array:
:return:
"""
output_file = open(filename,'w')
for name in string_array:
output_file.write(name+" ")
output_file.close()
if __name__=="__main__":
intensities = read_file_safe(sys.argv[2])
vbi_output = read_file_safe(sys.argv[1])
last_output = vbi_output[-1][:-4]
file_list = read_file_safe(sys.argv[3], 'unicode')
nonzero_indexes = np.nonzero(last_output>0.0)
print(nonzero_indexes)
output_intensities = intensities[:,nonzero_indexes[0]]
output_filelist = file_list[last_output>0.0]
savetext('file_sub.txt', output_filelist)
np.savetxt('TrmIntensites.txt', output_intensities)