-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaero_plot.py
More file actions
59 lines (50 loc) · 1.97 KB
/
Copy pathaero_plot.py
File metadata and controls
59 lines (50 loc) · 1.97 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
import matplotlib.pyplot as plt
import numpy as np
from aero_csv import read_data
# Assuming read_data is imported from your module that parses the CSV file.
# from your_data_module import read_data
def graph_acceleration(csv_filename: str):
times = [] # Time stamps in seconds
acc_x = [] # Accelerometer X values
acc_y = [] # Accelerometer Y values
acc_z = [] # Accelerometer Z values
acc_mag = [] # Computed acceleration magnitude
# Read data from CSV using your read_data() generator
for data in read_data(csv_filename):
# Convert the microsecond timestamp into seconds
t = data.us_since_launch / 1_000_000.0
times.append(t)
# Get acceleration values from each axis;
# If the data file contains raw counts that need conversion, apply conversion functions.
x_val = data.x.accelerometer
y_val = data.y.accelerometer
z_val = data.z.accelerometer
acc_x.append(x_val)
acc_y.append(y_val)
acc_z.append(z_val)
# Compute the magnitude of acceleration (Euclidean norm)
magnitude = np.linalg.norm([x_val, y_val, z_val])
acc_mag.append(magnitude)
# Plot each accelerometer axis over time
plt.figure(figsize=(12, 6))
plt.plot(times, acc_x, label="Acc X")
plt.plot(times, acc_y, label="Acc Y")
plt.plot(times, acc_z, label="Acc Z")
plt.xlabel("Time (s)")
plt.ylabel("Acceleration (m/s²)")
plt.title("Accelerometer Data (per axis)")
plt.legend()
plt.grid(True)
plt.show()
# Plot acceleration magnitude over time
plt.figure(figsize=(12, 6))
plt.plot(times, acc_mag, label="Acc Magnitude", color='magenta')
plt.xlabel("Time (s)")
plt.ylabel("Acceleration Magnitude (m/s²)")
plt.title("Acceleration Magnitude over Time")
plt.legend()
plt.grid(True)
plt.show()
if __name__ == '__main__':
csv_filename = "data.csv" # Path to your CSV file
graph_acceleration(csv_filename)