File size: 3,152 Bytes
bcad657
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import pandas as pd
import matplotlib.pyplot as plt
import os
import matplotlib as mpl
import numpy as np

# Die Milltap hatte einen globalen Fehler von 20 µm. Dieser muss von den Messwerten abgezogen werden.
offset = 0

def preprocess_data(csv, x_set):
    
    df = pd.read_csv(csv, sep=",", encoding="utf-16", header=None)
    df.columns = ['x', 'y', 'z']
    
    # slicing
    df = df.iloc[:16000]
    df = df[(df['y'] > -31) & (df['y'] < -2)] 
    df = df[(df['x'] > -5.5) & (df['x'] < 5.5)]
    
    # transform x, y, z
    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.
    df["y"] = df["y"] * (-1)    # flip the y-axis
    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
    

    # These are the constant X values for the slicing, where the measuring probe actually moves along the y-axis:
    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]
    tol = 0.1
    i = 0

    x_value = x_values[x_set]

    data = df[(df['x'] > x_value-tol) & (df['x'] < x_value+tol)]

    fivetothirty = data[data['y'] > 5]
    fivetothirty = fivetothirty[0:500]
    
    return data, x_value, fivetothirty


def plot_timeseries(csv, x_set):

    data, x_value, fivetothirty = preprocess_data(csv, x_set)

    x = data["y"]
    y = data["z"]

    fig, ax = plt.subplots(figsize=(8, 4))
    
    ax.set_ylim(3.23, 3.275)
    ax.set_xlim(2, 31)
    
    mpl.rcParams['font.family'] = 'Arial'
    mpl.rcParams['font.size'] = 30

    ax.set_xlabel("Bauteillänge [mm]", fontname="Arial", fontsize=16, labelpad=7)
    ax.set_ylabel("Bauteilhöhe Z [mm]", fontname="Arial", fontsize=16, labelpad=7)
    plt.yticks(np.arange(3.23, 3.271, step=0.01), fontname="Arial", fontsize=14, color="black")
    plt.xticks(range(5, 31, 5), fontname="Arial", fontsize=14, color = "black")

    """
    xticks = ax.get_xticks()
    xticklabels = [str(int(x)) if x != xticks[-2] else "mm" for x in xticks]
    ax.set_xticklabels(xticklabels)
    """

    plt.title("Oberfläche bei X = {} mm".format(x_value),fontname="Arial", fontsize=18, color="black", weight="bold", pad=10)

    gridwidth = 1.5
    plt.grid(axis="y", linewidth=0.75, color="black")
    plt.grid(axis="x", linewidth=0.75, color="black")

    rand = ["top", "right", "bottom", "left"]
    for i in rand:
        plt.gca().spines[i].set_linewidth(gridwidth)
        ax.spines[i].set_color('black')

    plt.plot(x, y, color="#00509b", linewidth=1.5)

    tolerance = 0.012
    # Define the tolerance range
    tolerance_lower = 3.25-tolerance
    tolerance_upper = 3.25+tolerance

    ax.fill_between(x, tolerance_lower, tolerance_upper, color='gray', alpha=0.1)

    # Check if the plot is within tolerance
    within_tolerance = all(tolerance_lower <= val <= tolerance_upper for val in y)

    tolerance = None 
    if within_tolerance:
        tolerance = True
    else:
        tolerance = False

    

    return fig, tolerance, y, fivetothirty