-
Notifications
You must be signed in to change notification settings - Fork 0
/
preproc_prof.py
182 lines (139 loc) · 4.15 KB
/
preproc_prof.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
import sys
utility_folder = '../utility/'
sys.path.insert(0, utility_folder)
import csv
from math import *
from matplotlib.pylab import *
from sys import argv
import util as ut
def distance_2p(xy1,xy2):
return np.sqrt((xy1[0] - xy2[0])**2 + (xy1[1] - xy2[1])**2)
def find_le(xy_p,xy_te):
dist = (xy_p[0,:] - xy_te[0])**2 + (xy_p[1,:] - xy_te[1])**2
return dist.argmax()
#def shift_0
def read_xy_p (filename):
data = ut.read_data(filename)
return np.array([[row[0] for row in data], [row[1] for row in data]])
def shift_o(xy_p, xy_le):
xy_p[0,:] -= xy_le[0]
xy_p[1,:] -= xy_le[1]
return xy_p
def atang(xy):
den = xy[0]**(-1)
alpha = np.arctan(xy[1]*den)*180.0/pi
import operator
condition1 = operator.and_(xy[0] < 0.00, xy[1] < 0.0)
condition2 = operator.and_(xy[0] > 0.0, xy[1] > 0.0)
condition3 = operator.and_(xy[0] > 0.0, xy[1] < 0.0)
condition4 = operator.and_(xy[0] < 0.0, xy[1] > 0.0)
condition23 =operator.or_(condition2, condition3)
r = np.where(condition4, alpha + 180.0,
np.where(condition23, alpha,
np.where(condition1, alpha - 180.0, 0.0)))
return r
def rotate(xy_p, ang):
r = sqrt(xy_p[0,:]**2 + xy_p[1,:]**2)
#print r
alpha = atang(xy_p)
#print alpha
beta = alpha - ang
beta *=pi/180.00
#print beta
tras_cos = cos(beta)
#print tras_cos
tras_sin = sin(beta)
n = len(xy_p[0,:])
x = np.zeros(n)
x += r
x *= tras_cos
y = np.zeros(n)
y += r
y *= tras_sin
return array([x,y])
def ss(xy_p):
ss_x = []
ss_y = []
for i in xrange(len(xy_p[0,:])):
if xy_p[1,i] >= 0.0:
ss_x.append(xy_p[0,i])
ss_y.append(xy_p[1,i])
return np.array([ss_x,ss_y])
def ps(xy_p):
ps_x = []
ps_y = []
for i in xrange(len(xy_p[0,:])):
if xy_p[1,i]<= 0.0:
ps_x.append(xy_p[0,i])
ps_y.append(xy_p[1,i])
return np.array([ps_x,ps_y])
def ps_ss(xy_p):
x_le = xy_p[0,0]
y_le = xy_p[1,0]
ps_x = []
ps_y = []
ss_x = []
ss_y = []
ss_x.append(x_le)
ss_y.append(y_le)
ps_x.append(x_le)
ps_y.append(y_le)
i = 1
while (len(ps_x) < 2 or len(ss_x) < 2):
if xy_p[1,i] >= y_le:
ss_x.append(xy_p[0,i])
ss_y.append(xy_p[1,i])
else:
ps_x.append(xy_p[0,i])
ps_y.append(xy_p[1,i])
i += 1
while i < len(xy_p[0,:]) - 1:
# y1_ss = (ss_y[len(ss_y)-1] - ss_y[len(ss_y) - 2])/(ss_x[len(ss_x)-1] - ss_x[len(ss_x) - 2])
# y_ss_exp = ss_y[len(ss_y)-1] + y1_ss*(xy_p[0,i]- ss_x[len(ss_x) -1])
# y1_ps = (ps_y[len(ps_y)-1] - ps_y[len(ps_y) - 2])/(ps_x[len(ps_x)-1] - ps_x[len(ps_x) - 2])
# y_ps_exp = ps_y[len(ps_y)-1] + y1_ps*(xy_p[0,i]- ps_x[len(ps_x) -1])
if abs(ss_y[len(ss_y) -1] - xy_p[1,i]) < abs(ps_y[len(ps_y) -1] - xy_p[1,i]):
ss_x.append(xy_p[0,i])
ss_y.append(xy_p[1,i])
else:
ps_x.append(xy_p[0,i])
ps_y.append(xy_p[1,i])
i += 1
ss_x.append(xy_p[0,len(xy_p[0,:]) -1])
ss_y.append(xy_p[1,len(xy_p[0,:]) -1])
ps_x.append(xy_p[0,len(xy_p[0,:]) -1])
ps_y.append(xy_p[1,len(xy_p[0,:]) -1])
print ss_y, ps_y
return np.array([ss_x, ss_y]), np.array([ps_x, ps_y])
def normalize(xy_p, chord):
xy_p /= chord
return xy_p
def sort_ar_x (a):
a = zip(*a)
a.sort(key = lambda x : x[0])
return np.array(zip(*a))
#if __name__=='__main__':
# script, filename = argv
def import_prof(filename):
xy_p = read_xy_p(filename)
xy_te = xy_p[:,0]
xy_le = xy_p[:,find_le(xy_p, xy_te)]
xy_p = shift_o(xy_p, xy_le)
ang = atang(xy_te - xy_le)
xy_p = rotate(xy_p, ang)
#ut.plot(xy_p[0,:], xy_p[1,:])
chord = distance_2p(xy_te,xy_le)
xy_p = normalize(sort_ar_x(xy_p), chord)
print xy_p
# xy_ps = ps(xy_p)
# print xy_ps
# xy_ss = ss(xy_p)
# print xy_ss
xy_ss, xy_ps = ps_ss(xy_p)
# ut.plot(xy_ps[0,:], xy_ps[1,:])
# ut.plot(xy_ss[0,:], xy_ss[1,:])
# plt.show()
# raw_input('\>')
return xy_ss, xy_ps
#plot(x,y)
#show()