-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathheight_transfer.py
More file actions
122 lines (97 loc) · 3.71 KB
/
height_transfer.py
File metadata and controls
122 lines (97 loc) · 3.71 KB
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
"""
This program is used for transferring the data to direct distance from floor.
This processing is very rough and cannot be used for practical use. More like my personal temporary stuff.
"""
try:
from Tkinter import *
except ImportError:
from tkinter import * # Python 3
import numpy as np
global P2F # the height of pod to the floor
global P2F_reading # the reading value from the sensor
global ratio
global base_line
global base_distance_0
global base_distance_1
# right now based on the absolute value, the performance is accepted but not good enoght
# it should use difference instead
# right now use the first line as standard, should change to the average num
# transfer the reading data to the actual distance. unit: m
def num_to_height(num):
x = (P2F/P2F_reading)*num
return round(x, 2)
# cos(30)=0.866
def transfer_30_degree(heat_map):
temp = []
difference = [(base_line[i]-heat_map[i]) for i in range(9)]
for i in range(9):
temp.append(round(num_to_height(int(difference[i]*ratio[i]))+base_distance_0[i], 2))
temp.append(heat_map[9])
return temp
# cos(15)=0.966
def transfer_15_degree(heat_map):
temp = []
difference = [(base_line[i]-heat_map[i]) for i in range(9)]
for i in range(9):
temp.append(round(num_to_height(int(difference[i]*ratio[i]))+base_distance_1[i], 2))
temp.append(heat_map[9])
return temp
if __name__ == '__main__':
base_distance_0 = [0, 0, 0, 0.77, 0.77, 0.77, 0, 0, 0]
base_distance_1 = [0, 0, 0, 0.77, 0.77, 0.77, 0.77, 0.77, 0.77]
P2F = 2.4
filename = input("filename:")
background_filename = input("background filename:")
f_blank = open(background_filename + '.txt', 'r')
data_blank = f_blank.read()
data_blank = data_blank.strip().split('\n')
for i in range(len(data_blank)):
data_blank[i] = data_blank[i].strip().split(' ')
for j in range(9):
data_blank[i][j] = int(data_blank[i][j])
data_blank[i][9] = float(data_blank[i][9])
f = open(filename+".txt", 'r')
data = f.read()
data = data.strip().split('\n')
for i in range(len(data)):
data[i] = data[i].strip().split(' ')
for j in range(9):
data[i][j] = int(data[i][j])
data[i][9] = float(data[i][9])
# data[i] = sort_transfer(data[i])
# sample line for define the P2F value
# print(data_blank[0])
sum_background = [0 for i in range(9)]
for i in range(len(data_blank)):
for j in range(9):
sum_background[j] += data_blank[i][j]
base_line = [int(sum_background[i]/len(data_blank)) for i in range(9)]
P2F_reading = base_line[4]+775
flag_30 = False
flag_15 = True
# get the ratio from the original data
# since the noise is very small, we can ignore it when calculate the ratio here
ratio = [0 for i in range(9)]
for i in range(9):
if flag_15:
if i < 3:
ratio[i] = round(P2F_reading / base_line[i], 2)
else:
ratio[i] = round(base_line[4] / base_line[i], 2)
elif flag_30:
if 3 <= i <= 5:
ratio[i] = round(base_line[4] / base_line[i], 2)
else:
ratio[i] = round(P2F_reading / base_line[i], 2)
print(ratio)
for i in range(len(data)):
if flag_30:
data[i] = transfer_30_degree(data[i])
elif flag_15:
data[i] = transfer_15_degree(data[i])
f = open(filename+"_height.txt", 'w')
for i in range(len(data)):
for j in range(len(data[i])):
f.write(str(data[i][j])+' ')
f.write('\n')
f.close()