Very shitty Plots
This commit is contained in:
parent
a15e95f8f1
commit
17cfa82b4b
84
main.py
84
main.py
@ -2,26 +2,24 @@
|
||||
# Cal Wing, Sem 2 2023
|
||||
|
||||
# Import System / Common Libs
|
||||
import os, time, pickle
|
||||
import os, pickle, time
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
from tqdm import tqdm
|
||||
|
||||
from numpy import pi, sin, cos, tan
|
||||
|
||||
#Import MakeGraph, a custom graphing wrapper I developed, refer to it for documentation
|
||||
#Import makeGraph, a custom graphing wrapper I developed, refer to it for documentation
|
||||
from makeGraph import makeGraph, pltKeyClose, UQ_COLOURS as UQC # Custom Graphing Lib
|
||||
|
||||
# Override Sin & Cos to use & return degrees
|
||||
#def sin(angle): return np.sin(np.deg2rad(angle))
|
||||
#def cos(angle): return np.cos(np.deg2rad(angle))
|
||||
|
||||
# Make sure the relevant folders folder exists
|
||||
folders = ["./images", "./tmp"]
|
||||
for folder in folders:
|
||||
if not os.path.isdir(folder): os.mkdir(folder)
|
||||
|
||||
# This is a cacheing function, it checks if a cache file exists and loads it or it calcs & saves it.
|
||||
# This is a cacheing function, it checks if a cache file exists and loads it or it calcs & saves it.
|
||||
# TL;DR This takes a file path & either a single variable (defArg) or some sort of callable and either
|
||||
# loads it or dumps it to disk. Note: It does not validate the data inside!
|
||||
def cacheData(dataFilePath: str, calcFunction: callable = lambda x: x, args: tuple = (), kargs: dict = {}, defArg=None):
|
||||
if len(args) == 0 and defArg is not None:
|
||||
args = (defArg, )
|
||||
@ -64,6 +62,8 @@ def cacheData(dataFilePath: str, calcFunction: callable = lambda x: x, args: tup
|
||||
if data is None: raise ValueError("Could not import or generate data requested")
|
||||
return data
|
||||
|
||||
|
||||
|
||||
# IMU Data Loading
|
||||
# I map in to a heading to add units / make things make more sense
|
||||
## The gyroscopic body angular rates from the IMU are given:
|
||||
@ -123,19 +123,25 @@ def getNEDForces(NEDPos):
|
||||
return forceMat
|
||||
|
||||
# Calculate Mission Translation & Force Data
|
||||
TRANS_DATA_HEADER = IMU_TIME_HEADER + IMU_WBE_HEADERS + ["Forces", "ForceSum", "ForceCumSum"]
|
||||
def calculateTranslatedData(missionWBEData) -> pd.DataFrame:
|
||||
print("Translating Motion & Calculating Resulting Forces")
|
||||
translatedData = pd.DataFrame(columns=IMU_TIME_HEADER + IMU_WBE_HEADERS + ["Forces"])
|
||||
translatedData = pd.DataFrame(columns=TRANS_DATA_HEADER)
|
||||
for i in tqdm(range(len(missionWBEData))):
|
||||
dataPoint = missionWBEData[IMU_WBE_HEADERS].iloc[i]
|
||||
trans = translate2NED(dataPoint.values, INIT_EULER_ANGLES).flatten()
|
||||
forces = getNEDForces(trans)
|
||||
forceSum = np.array([np.sum(forces[:,0].flatten()), np.sum(forces[:,1].flatten()), np.sum(forces[:,2].flatten())])
|
||||
privForce = translatedData[TRANS_DATA_HEADER[5]].iloc[i-1] if i > 0 else [0, 0, 0]
|
||||
forceCumSum = np.array([ forceSum[ii] + value for ii, value in enumerate(privForce) ])
|
||||
dataRow = {
|
||||
IMU_TIME_HEADER[0]: missionWBEData[IMU_TIME_HEADER].iloc[i],
|
||||
IMU_WBE_HEADERS[0]: trans[0],
|
||||
IMU_WBE_HEADERS[1]: trans[1],
|
||||
IMU_WBE_HEADERS[2]: trans[2],
|
||||
"Forces": forces
|
||||
TRANS_DATA_HEADER[0]: missionWBEData[IMU_TIME_HEADER].iloc[i],
|
||||
TRANS_DATA_HEADER[1]: trans[0],
|
||||
TRANS_DATA_HEADER[2]: trans[1],
|
||||
TRANS_DATA_HEADER[3]: trans[2],
|
||||
TRANS_DATA_HEADER[4]: forces,
|
||||
TRANS_DATA_HEADER[5]: forceSum,
|
||||
TRANS_DATA_HEADER[6]: forceCumSum,
|
||||
}
|
||||
translatedData.loc[i] = dataRow
|
||||
|
||||
@ -143,46 +149,18 @@ def calculateTranslatedData(missionWBEData) -> pd.DataFrame:
|
||||
|
||||
if __name__ == '__main__':
|
||||
missionWBEData = m1_IMUData[0][IMU_TIME_HEADER + IMU_WBE_HEADERS]
|
||||
translatedData = cacheData("./tmp/m1_transData.dfz", calculateTranslatedData, (missionWBEData,))
|
||||
|
||||
boo = "" #calculateTranslatedData(missionWBEData)
|
||||
translatedData = cacheData("./tmp/m1_transData.dfz", defArg=boo)
|
||||
import matplotlib.pyplot as plt
|
||||
fig = plt.figure()
|
||||
ax = plt.axes(projection='3d')
|
||||
plots = translatedData[TRANS_DATA_HEADER[6]].values
|
||||
x = [p[0] for p in plots]
|
||||
y = [p[1] for p in plots]
|
||||
z = [p[2] for p in plots]
|
||||
ax.plot3D(x, y, z)
|
||||
|
||||
plt.show()
|
||||
|
||||
#print("Raw Data")
|
||||
#print(dataPoint)
|
||||
|
||||
#print("\nTranslated Point")
|
||||
#print(trans)
|
||||
|
||||
#print("\nForces")
|
||||
#print(forces)
|
||||
|
||||
input("Damn")
|
||||
|
||||
if __name__ == '__main__1':
|
||||
#This is an example of drawing 4 plots by generating them
|
||||
graphData = {
|
||||
"figTitle": "Simple Plot",
|
||||
"figTitleFontSize": 16,
|
||||
"figSize": (8,8), #Yay America, this is in inches :/ # Note: cm = 1/2.54
|
||||
"xLabel": "x label",
|
||||
"yLabel": "y label",
|
||||
"plotDim": (2,2),
|
||||
"subPlots":[]
|
||||
}
|
||||
|
||||
#Create 4 identical plots with different names
|
||||
for i in range(4):
|
||||
newPlot = {
|
||||
"title": f"Graph {i+1}",
|
||||
"plots": [
|
||||
{"x":[0,1,2,3,4], "y":[0,1,2,3,4], "label":"Linear"},
|
||||
{"x":[0,1,2,3,4], "y":[5,5,5,5,5]},
|
||||
{"x":[4,3,2,1,0], "y":[4,3,2,1,0], "label":"Linear2"},
|
||||
{"x":0, "type":"axvLine", "label":"Red Vertical Line", "color":"red"},
|
||||
{"y":6, "type":"axhLine", "label":"Dashed Horizontal Line", "args":{"linestyle":"--"}},
|
||||
{"type":"scatter", "x":4, "y":4, "label":"A Random Point", "colour":"purple", "args":{"zorder":2}}
|
||||
]
|
||||
}
|
||||
graphData["subPlots"].append(newPlot)
|
||||
|
||||
makeGraph(graphData, figSavePath="./images/example.png")
|
||||
print("Complete")
|
Loading…
x
Reference in New Issue
Block a user