ifw-arz commited on
Commit
8b2e775
1 Parent(s): edd8879
Files changed (1) hide show
  1. Messungen/preprocessing.py +0 -100
Messungen/preprocessing.py DELETED
@@ -1,100 +0,0 @@
1
- import pandas as pd
2
- import matplotlib.pyplot as plt
3
- import os
4
- import matplotlib as mpl
5
- import numpy as np
6
-
7
- # Die Milltap hatte einen globalen Fehler von 20 µm. Dieser muss von den Messwerten abgezogen werden.
8
- offset = 0
9
-
10
- def preprocess_data(csv, x_set):
11
-
12
- df = pd.read_csv(csv, sep=",", encoding="utf-16", header=None)
13
- df.columns = ['x', 'y', 'z']
14
-
15
- # slicing
16
- df = df.iloc[:16000]
17
- df = df[(df['y'] > -31) & (df['y'] < -2)]
18
- df = df[(df['x'] > -5.5) & (df['x'] < 5.5)]
19
-
20
- # transform x, y, z
21
- df["x"] = df["x"] +7.5 # in the raw data, X = 0 is in the middle of the workpiece-width. Shift X to the left by 7.5 mm to have X = 0 at the left edge of the workpiece.
22
- df["y"] = df["y"] * (-1) # flip the y-axis
23
- df['z'] = df['z'] - (1.5 + offset) # the radius of the tip of the measuring device is 1.5 mm and needs to be substracted from z
24
-
25
-
26
- # These are the constant X values for the slicing, where the measuring probe actually moves along the y-axis:
27
- x_values = [2.4, 3, 3.6, 4.2, 4.8, 5.4, 6, 6.6, 7.2, 7.8, 8.4, 9, 9.6, 10.2, 10.8, 11.4, 12, 12.6]
28
- tol = 0.1
29
- i = 0
30
-
31
- x_value = x_values[x_set]
32
-
33
- data = df[(df['x'] > x_value-tol) & (df['x'] < x_value+tol)]
34
-
35
- fivetothirty = data[data['y'] > 5]
36
- fivetothirty = fivetothirty[0:500]
37
-
38
- return data, x_value, fivetothirty
39
-
40
-
41
- def plot_timeseries(csv, x_set):
42
-
43
- data, x_value, fivetothirty = preprocess_data(csv, x_set)
44
-
45
- x = data["y"]
46
- y = data["z"]
47
-
48
- fig, ax = plt.subplots(figsize=(8, 4))
49
-
50
- ax.set_ylim(3.23, 3.275)
51
- ax.set_xlim(2, 31)
52
-
53
- mpl.rcParams['font.family'] = 'Arial'
54
- mpl.rcParams['font.size'] = 30
55
-
56
- ax.set_xlabel("Bauteillänge [mm]", fontname="Arial", fontsize=16, labelpad=7)
57
- ax.set_ylabel("Bauteilhöhe Z [mm]", fontname="Arial", fontsize=16, labelpad=7)
58
- plt.yticks(np.arange(3.23, 3.271, step=0.01), fontname="Arial", fontsize=14, color="black")
59
- plt.xticks(range(5, 31, 5), fontname="Arial", fontsize=14, color = "black")
60
-
61
- """
62
- xticks = ax.get_xticks()
63
- xticklabels = [str(int(x)) if x != xticks[-2] else "mm" for x in xticks]
64
- ax.set_xticklabels(xticklabels)
65
- """
66
-
67
- plt.title("Oberfläche bei X = {} mm".format(x_value),fontname="Arial", fontsize=18, color="black", weight="bold", pad=10)
68
-
69
- gridwidth = 1.5
70
- plt.grid(axis="y", linewidth=0.75, color="black")
71
- plt.grid(axis="x", linewidth=0.75, color="black")
72
-
73
- rand = ["top", "right", "bottom", "left"]
74
- for i in rand:
75
- plt.gca().spines[i].set_linewidth(gridwidth)
76
- ax.spines[i].set_color('black')
77
-
78
- plt.plot(x, y, color="#00509b", linewidth=1.5)
79
-
80
- tolerance = 0.012
81
- # Define the tolerance range
82
- tolerance_lower = 3.25-tolerance
83
- tolerance_upper = 3.25+tolerance
84
-
85
- ax.fill_between(x, tolerance_lower, tolerance_upper, color='gray', alpha=0.1)
86
-
87
- # Check if the plot is within tolerance
88
- within_tolerance = all(tolerance_lower <= val <= tolerance_upper for val in y)
89
-
90
- tolerance = None
91
- if within_tolerance:
92
- tolerance = True
93
- else:
94
- tolerance = False
95
-
96
-
97
-
98
- return fig, tolerance, y, fivetothirty
99
-
100
-