From ea2150a471151282d855a87e10d967c68c30f7a0 Mon Sep 17 00:00:00 2001
From: wmalisch <malisch.will@gmail.com>
Date: Fri, 26 Apr 2024 20:03:42 -0400
Subject: [PATCH] Plotting scripts

---
 requirements.txt                              | 12 ++++++
 src/{ => data-processing}/PlotAllPlanes.py    |  0
 .../PlotPeaks.py}                             | 19 +++++----
 src/data-processing/PlotVectorizedPlanes.py   | 42 +++++++++++++++++++
 src/data-processing/Vectorize.py              | 27 ++++++++++++
 5 files changed, 91 insertions(+), 9 deletions(-)
 create mode 100644 requirements.txt
 rename src/{ => data-processing}/PlotAllPlanes.py (100%)
 rename src/{PlotVectorizedPlanes.py => data-processing/PlotPeaks.py} (62%)
 create mode 100644 src/data-processing/PlotVectorizedPlanes.py
 create mode 100644 src/data-processing/Vectorize.py

diff --git a/requirements.txt b/requirements.txt
new file mode 100644
index 0000000..1f53dad
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1,12 @@
+contourpy==1.2.1
+cycler==0.12.1
+fonttools==4.51.0
+kiwisolver==1.4.5
+matplotlib==3.8.4
+numpy==1.26.4
+packaging==24.0
+pillow==10.3.0
+pyparsing==3.1.2
+python-dateutil==2.9.0.post0
+scipy==1.13.0
+six==1.16.0
diff --git a/src/PlotAllPlanes.py b/src/data-processing/PlotAllPlanes.py
similarity index 100%
rename from src/PlotAllPlanes.py
rename to src/data-processing/PlotAllPlanes.py
diff --git a/src/PlotVectorizedPlanes.py b/src/data-processing/PlotPeaks.py
similarity index 62%
rename from src/PlotVectorizedPlanes.py
rename to src/data-processing/PlotPeaks.py
index fe85a48..d164eeb 100644
--- a/src/PlotVectorizedPlanes.py
+++ b/src/data-processing/PlotPeaks.py
@@ -1,8 +1,8 @@
 import numpy as np
 import matplotlib.pyplot as plt
+from scipy.signal import find_peaks
 import csv
 
-# Initialize list to store magnitudes
 magnitudes = []
 
 with open('outputs/vectorized_data.csv', 'r') as file:
@@ -17,12 +17,13 @@ with open('outputs/vectorized_data.csv', 'r') as file:
 # Convert magnitudes list to numpy array
 magnitudes = np.array(magnitudes)
 
-# Plot magnitudes
-plt.figure(figsize=(10, 6))  # Adjust the figure size as needed
-plt.plot(magnitudes, label='Magnitude')
+peaks, _ = find_peaks(magnitudes)
+
+plt.plot(magnitudes)
+plt.plot(peaks, magnitudes[peaks], "x", color='red')
 plt.xlabel('Index')
-plt.ylabel('Magnitude')
-plt.title('Magnitude from vectorized_data.csv')
-plt.legend()
-plt.grid(True)
-plt.show()
\ No newline at end of file
+plt.ylabel('Acceleration Magnitude')
+plt.title('Acceleration Magnitude with Peaks')
+plt.show()
+
+print("Indices of the peaks:", peaks)
\ No newline at end of file
diff --git a/src/data-processing/PlotVectorizedPlanes.py b/src/data-processing/PlotVectorizedPlanes.py
new file mode 100644
index 0000000..7a0cce2
--- /dev/null
+++ b/src/data-processing/PlotVectorizedPlanes.py
@@ -0,0 +1,42 @@
+import numpy as np
+import matplotlib.pyplot as plt
+import csv
+
+# Initialize list to store magnitudes
+magnitudes = []
+
+with open('outputs/vectorized_data.csv', 'r') as file:
+    reader = csv.reader(file)
+    next(reader)  # Skip the header row
+    for row in reader:
+        # Extract magnitude value from each row
+        mag = float(row[0])
+        # Append magnitude to the list
+        magnitudes.append(mag)
+
+# Convert magnitudes list to numpy array
+magnitudes = np.array(magnitudes)
+
+mean_value = np.mean(magnitudes)
+std_dev = np.std(magnitudes)
+
+# Plot magnitudes
+plt.figure(figsize=(10, 6))  # Adjust the figure size as needed
+plt.plot(magnitudes, label='Magnitude')
+plt.xlabel('Index')
+plt.ylabel('Magnitude')
+plt.title('Magnitude from vectorized_data.csv')
+
+# Plot mean and standard deviation lines
+plt.axhline(mean_value, color='r', linestyle='--', label='Mean')
+plt.axhline(mean_value + std_dev*1.5, color='g', linestyle='--', label='Mean + StdDev')
+plt.axhline(mean_value - std_dev*1.5, color='g', linestyle='--', label='Mean - StdDev')
+
+# Annotate mean and standard deviation values
+plt.text(0.5, mean_value, f'Mean: {mean_value:.2f}', color='r', fontsize=10, va='center', ha='left')
+plt.text(0.5, mean_value + std_dev, f'Standard Deviation: {std_dev:.2f}', color='g', fontsize=10, va='center', ha='left')
+plt.text(0.5, mean_value - std_dev, f'Standard Deviation: {std_dev:.2f}', color='g', fontsize=10, va='center', ha='left')
+
+plt.legend()
+plt.grid(True)
+plt.show()
diff --git a/src/data-processing/Vectorize.py b/src/data-processing/Vectorize.py
new file mode 100644
index 0000000..a515c02
--- /dev/null
+++ b/src/data-processing/Vectorize.py
@@ -0,0 +1,27 @@
+import numpy as np
+import matplotlib.pyplot as plt
+import csv
+
+# Initialize list to store magnitudes
+magnitudes = []
+
+# Open and read the CSV file
+with open('outputs/1714090197.csv', 'r') as file:
+    reader = csv.reader(file)
+    
+    for row in reader:    
+        # Extract x, y, and z values from each row
+        x, y, z = float(row[0]), float(row[1]), float(row[2])
+        
+        # Calculate magnitude using the provided algorithm
+        mag = np.sqrt(x**2 + y**2 + z**2)
+
+        # Append magnitude to the list
+        magnitudes.append(mag)
+
+magnitudes = np.array(magnitudes)
+
+with open('outputs/vectorized_data.csv', 'w', newline='') as file:
+    writer = csv.writer(file)
+    for mag in magnitudes:
+        writer.writerow([mag])
\ No newline at end of file
-- 
GitLab