-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_matrix.py
142 lines (99 loc) · 2.78 KB
/
build_matrix.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import numpy as np
import gc
import argparse
import utilities as util
if __name__ == "__main__":
"""
The routine works by reading in a file containig in each line the
time stamp of the sub-matrix file (WARNING: they have to be in the
correct order, 1st line -> sub-matrix 00; 2nd line -> sub-matrix 01
etc.).
The time stamp is inserted in the file name. THIS COULD BETTER BE A LIST OF FILE NAMES!!
"""
parser = argparse.ArgumentParser(
description = "SN lightcurve fitter and classifier: Bulding distance matrix from files.",
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument(
'--path', '-p', dest='path',
help='Path where to find files.')
args = parser.parse_args()
if __name__ == "__main__":
# if args.timeStamps == '':
# raise SystemExit
# inFile = file(args.timeStamps, 'r')
# timeStamps = inFile.readlines()
# inFile.close()
fileList = util.sort_distance_file(args.path)
# # path = 'results/SIMGEN_PUBLIC_FIT/RBF_test-length/distance_matrix/'
# fileName = 'dist_matrix_Sum_mothra_{:<14.3f}.txt'
print 'mat00 ...'
mat00 = np.loadtxt(fileList[0])
print 'mat01 ...'
mat01 = np.loadtxt(fileList[1])
print 'mat02 ...'
mat02 = np.loadtxt(fileList[2])
print 'mat03 ...'
mat03 = np.loadtxt(fileList[3])
#---> hstacking ....
print 'hstacking mat0 ...'
mat0 = np.hstack((mat00, mat01, mat02, mat03))
del mat00
# ----- line 1 -----
print 'mat10 ...'
mat10 = np.transpose(mat01)
del mat01
# gc.collect()
print 'mat11 ...'
mat11 = np.loadtxt(fileList[4])
print 'mat12 ...'
mat12 = np.loadtxt(fileList[5])
print 'mat13 ...'
mat13 = np.loadtxt(fileList[6])
#---> hstacking ....
print 'stacking mat1 ...'
mat1 = np.hstack((mat10, mat11, mat12, mat13))
del mat10, mat11
# gc.collect()
# ----- line 2 -----
print 'mat20 ...'
mat20 = np.transpose(mat02)
del mat02
print 'mat21 ...'
mat21 = np.transpose(mat12)
del mat12
gc.collect()
print 'mat22 ...'
mat22 = np.loadtxt(fileList[7])
print 'mat23 ...'
mat23 = np.loadtxt(fileList[8])
#---> stacking ....
print 'stacking mat2 ...'
mat2 = np.hstack((mat20, mat21, mat22, mat23))
del mat20, mat21, mat22
# gc.collect()
# ----- line 3 -----
print 'mat30 ...'
mat30 = np.transpose(mat03)
print 'mat31 ...'
mat31 = np.transpose(mat13)
print 'mat32 ...'
mat32 = np.transpose(mat23)
del mat03, mat13, mat23
print 'mat33 ...'
mat33 = np.loadtxt(fileList[9])
#---> stacking ....
print 'stacking mat3 ...'
mat3 = np.hstack((mat30, mat31, mat32, mat33))
del mat30, mat31, mat32, mat33
# gc.collect()
#---> stacking ....
print 'stacking mat ...'
mat = np.vstack((mat0, mat1, mat2, mat3))
del mat0, mat1, mat2, mat3
# gc.collect()
print 'saving mat ...'
np.savetxt(args.path+'dist_matrix_Sum.txt', mat)
del mat
# gc.collect()
print 'END'
#END