-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_analysis.py
90 lines (61 loc) · 2.01 KB
/
data_analysis.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
import pandas as pd
import matplotlib.pyplot as plt
def best_fit(X, Y):
xbar = sum(X)/len(X)
ybar = sum(Y)/len(Y)
n = len(X) # or len(Y)
numer = sum([xi*yi for xi,yi in zip(X, Y)]) - n * xbar * ybar
denum = sum([xi**2 for xi in X]) - n * xbar**2
b = numer / denum
a = ybar - b * xbar
print('best fit line:\ny = {:.5f} + {:.5f}x'.format(a, b))
return a, b
file_path = 'Payload/Github Repo/2024-payload/Utility Scripts/Extractor/Logs/2024-06-14_22_52_52_593467_1.csv'
df = pd.read_csv(file_path)
print(df['Time'])
preLaunch = [0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
launch = [0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0]
time = []
pdVal = []
pdChange = []
current = []
pdCount = 0
pdSum = 0
voltCount = 0
voltSum = 0
lastState = 0
startTime = 0
lastPd = 0
for index, row in df.iterrows():
if row["State"] != lastState:
if(pdSum > 0):
if row["Launched"] == 1 or True:
pdVal.append(pdSum / pdCount)
current.append((voltSum / voltCount) / 3.4)
time.append(startTime)
pdChange.append(((pdSum / pdCount - lastPd) / lastPd * 100) if voltSum > 0 else 0)
lastPd = pdSum / pdCount
pdSum = 0
pdCount = 0
voltSum = 0
voltCount = 0
startTime = row["Time"]
if((preLaunch[int(row["State"])] if (row["Launched"] == 0) else launch[int(row["State"])]) > 0):
voltSum += row["Coil"]
pdSum += row["PD"]
voltCount += 1
pdCount += 1
lastState = row["State"]
field = []
for cur in current:
field.append(cur * 132.55)
a, b = best_fit(field, pdChange)
#plt.plot(pdChange)
plt.scatter(field, pdChange)
yfit = [a + b * xi for xi in field]
plt.plot(field, yfit, color='red')
plt.xlabel("Field [Gauss]")
plt.ylabel("Optical Change [%]")
plt.suptitle("Ground Test Run Results")
plt.title("Limited Test Levels")
plt.show()