7 with open(in_file)
as data_file:
8 data = [line.strip().split(
";")
for line
in data_file.readlines()]
9 data = [[int(line[0]), int(line[1]), float(line[2])]
for line
in data]
10 data.sort(key=
lambda x: x[-1], reverse=
True)
11 with open(out_file,
"w")
as output_file:
12 for index
in range(len(data)):
13 if index >= 1
and ((data[index][0] > data[index - 1][0])
or (data[index][1] > data[index - 1][1])):
15 output_file.write(
"\t".join(str(x)
for x
in data[index]) +
"\n")
16 apps1_values = [line[0]
for line
in data]
17 apps2_values = [line[1]
for line
in data]
18 compression_values = [line[2]
for line
in data]
20 compression_values = [val - min(compression_values)
for val
in compression_values]
21 return apps1_values, apps2_values, compression_values
37 apps1_interp = interpolate.interp1d(compr_vals, apps1_vals, kind=
"linear", fill_value=
"extrapolate")
38 apps2_interp = interpolate.interp1d(compr_vals, apps2_vals, kind=
"linear", fill_value=
"extrapolate")
40 interpolation_step = 0.01
41 new_compr_vals = np.arange(0, max(compr_vals), interpolation_step)
43 new_apps1_vals = apps1_interp(new_compr_vals)
44 new_apps2_vals = apps2_interp(new_compr_vals)
46 for index
in range(len(new_apps1_vals)):
47 if new_apps1_vals[index] < 0:
48 new_apps1_vals[index] = 0
49 if new_apps1_vals[index] > 1023:
50 new_apps1_vals[index] = 1023
52 for index
in range(len(new_apps2_vals)):
53 if new_apps2_vals[index] < 0:
54 new_apps2_vals[index] = 0
55 if new_apps2_vals[index] > 1023:
56 new_apps2_vals[index] = 1023
58 return new_apps1_vals, new_apps2_vals, new_compr_vals
62 with open(
"data_files/interpolation_data.txt",
"r")
as input_file:
66 for line
in input_file:
67 line = line.strip().split(
"\t")
68 apps1_vals.append(float(line[0]))
69 apps2_vals.append(float(line[1]))
70 compr_vals.append(float(line[2]))
71 return apps1_vals, apps2_vals, compr_vals
76 sensor_data = [[round(apps1_vals[index]), round(apps2_vals[index])]
for index
in range(len(apps1_vals))]
77 sensor_data = sorted(list(set(tuple(x)
for x
in sensor_data)))
78 apps_1_deadzone_vals = [vals
for vals
in sensor_data
if vals[0] >= 1022]
79 apps_2_deadzone_vals = [vals
for vals
in sensor_data
if vals[1] <= 1]
80 apps_1_deadozone_interval = (
81 min([vals[1]
for vals
in apps_1_deadzone_vals]),
82 max([vals[1]
for vals
in apps_1_deadzone_vals]),
84 apps_2_deadozone_interval = (
85 min([vals[0]
for vals
in apps_2_deadzone_vals]),
86 max([vals[0]
for vals
in apps_2_deadzone_vals]),
89 apps_linear_zone = [vals
for vals
in sensor_data
if vals
not in apps_1_deadzone_vals + apps_2_deadzone_vals]
90 apps_linear_offset = round(sum([vals[0] - vals[1]
for vals
in apps_linear_zone]) / len(apps_linear_zone))
91 max_error = round(max([vals[0] - (vals[1] + apps_linear_offset)
for vals
in apps_linear_zone]), ndigits=4)
92 max_error_percent = round(max_error / 1023 * 100, ndigits=4)
93 return apps_1_deadozone_interval, apps_2_deadozone_interval, apps_linear_offset, max_error, max_error_percent
100 new_apps1_vals, new_apps2_vals, new_compr_vals =
interpolate_data(apps1_vals, apps2_vals, compr_vals)
102 new_compr_vals, new_apps1_vals,
"Sensor Compression (mm)",
"APPS 1",
"APPS 1 vs. Compression (Interpolated)"
105 new_compr_vals, new_apps2_vals,
"Sensor Compression (mm)",
"APPS 2",
"APPS 2 vs. Compression (Interpolated)"
107 with open(
"data_files/interpolation_data.txt",
"w")
as output_file:
108 for index
in range(len(new_compr_vals)):
110 "\t".join(str(x)
for x
in [new_apps1_vals[index], new_apps2_vals[index], new_compr_vals[index]]) +
"\n"
117 apps1_vals, apps2_vals, compr_vals =
read_data_from_file(
"data_files/interpolation_data.txt")
119 apps_1_deadozone_interval,
120 apps_2_deadozone_interval,
126 print(
"APPS 1 Deadzone Interval: " + str(apps_1_deadozone_interval))
127 print(
"APPS 2 Deadzone Interval: " + str(apps_2_deadozone_interval))
128 print(
"APPS Linear Offset: " + str(apps_linear_offset))
129 print(
"Max Error: " + str(max_error))
130 print(
"Max Error Percent: " + str(max_error_percent))