diff --git a/main.py b/main.py index 7f891b9..d9ea0ab 100644 --- a/main.py +++ b/main.py @@ -148,7 +148,7 @@ def calculateVelocityPosition(missionData, initial_values) -> pd.DataFrame: offset = initial_values.copy() - translatedData = pd.DataFrame(columns=TRANS_DATA_HEADER, dtype=np.float32) + translatedData = pd.DataFrame(columns=TRANS_DATA_HEADER, dtype=float) for i in tqdm(range(len(missionData))): mData = lambda header, j=i: missionData.loc[j, header].values dt = mData(IMU_TIME_HEADER, i)[0] - mData(IMU_TIME_HEADER, i-1)[0] if i > 0 else mData(IMU_TIME_HEADER, i+1)[0] - mData(IMU_TIME_HEADER, i)[0] @@ -262,7 +262,7 @@ def generateGraphs(missionData, mission): graphData = { "figTitle": f"Mission {mission} Flight Position", "figTitleFontSize": 16, - "figSize": (10, 12), #Yay America, this is in inches :/ # Note: cm = 1/2.54 + "figSize": (12, 15), #Yay America, this is in inches :/ # Note: cm = 1/2.54 "yLabel": "Time [s]", "plotDim": (3,2), "grid": True, @@ -323,6 +323,8 @@ def generateGraphs(missionData, mission): }, ] } + if TRUTH_N_POS_HEADER[1] in missionData[1].columns: + graphData["subPlots"][0]["plots"].insert(0, {"x": missionData[1][IMU_TIME_HEADER[0]], "y":missionData[1][TRUTH_N_POS_HEADER[1]], "label":"True Position", "colour":"uq:red"}) makeGraph(graphData, False, False, figSavePath=f"./images/m{mission}_flight_pos_3d.png") pBar.update(1) @@ -368,7 +370,7 @@ def generateGraphs(missionData, mission): "figTitleFontSize": 16, "figSize": (8, 12), #Yay America, this is in inches :/ # Note: cm = 1/2.54 "yLabel": "Time [s]", - "plotDim": (3,3), + "plotDim": (3,1), "grid": True, "subPlots":[ { @@ -403,9 +405,9 @@ def generateGraphs(missionData, mission): graphData = { "figTitle": f"Mission {mission} Flight Characteristics", "figTitleFontSize": 16, - "figSize": (8, 12), #Yay America, this is in inches :/ # Note: cm = 1/2.54 + "figSize": (20, 12), #Yay America, this is in inches :/ # Note: cm = 1/2.54 "yLabel": "Time [s]", - "plotDim": (3,1), + "plotDim": (3,3), "grid": True, "subPlots":[ { @@ -484,7 +486,7 @@ def generateGraphs(missionData, mission): } if TRUTH_N_POS_HEADER[1] in missionData[1].columns: graphData["subPlots"][0]["plots"].insert(0, {"x": missionData[1][IMU_TIME_HEADER[0]], "y":missionData[1][TRUTH_N_POS_HEADER[1]], "label":"True Position", "colour":"uq:red"}) - makeGraph(graphData, False, False, figSavePath=f"./images/m{mission}_flight_accell.png") + makeGraph(graphData, False, False, figSavePath=f"./images/m{mission}_flight_chars.png") pBar.update(1) @@ -496,7 +498,7 @@ def doTruthComparison(missionData, truthData): mData[TRUTH_NPOS_DELTA_HEADER[0]] = mData[NED_POSITION_HEADER[0]] - mData[TRUTH_N_POS_HEADER[1]] mData[TRUTH_NPOS_DELTA_HEADER[1]] = np.abs(mData[TRUTH_NPOS_DELTA_HEADER[0]]) / mData[TRUTH_N_POS_HEADER[1]] * 100 - mData[mData.columns] = mData[mData.columns].astype(np.float32) + mData[mData.columns] = mData[mData.columns].astype(float) return missionData @@ -516,8 +518,8 @@ def generateTruthErrorGraphs(missionData): } makeGraph(graphData, False, False, figSavePath="./images/m1_error_delta.png") - poly_low = np.polyfit(missionData[0][IMU_TIME_HEADER[0]], missionData[0][TRUTH_NPOS_DELTA_HEADER[1]], 4) - poly_high = np.polyfit(missionData[1][IMU_TIME_HEADER[0]], missionData[1][TRUTH_NPOS_DELTA_HEADER[1]], 4) + poly_low = np.polyfit(missionData[0][IMU_TIME_HEADER[0]], missionData[0][TRUTH_NPOS_DELTA_HEADER[1]], 3) + poly_high = np.polyfit(missionData[1][IMU_TIME_HEADER[0]], missionData[1][TRUTH_NPOS_DELTA_HEADER[1]], 3) graphData = { "grid": True, "xLabel": "Time [s]", @@ -525,13 +527,13 @@ def generateTruthErrorGraphs(missionData): "title": "Calculated vs True North Position Error", "plots": [ {"x":missionData[0][IMU_TIME_HEADER[0]], "y": np.abs(missionData[0][TRUTH_NPOS_DELTA_HEADER[1]]), "label": "Low Grade IMU Error"}, - {"x":missionData[0][IMU_TIME_HEADER[0]], "y": np.polyval(poly_low, missionData[0][IMU_TIME_HEADER[0]]), "label": "Low Grade Best Fit Curve"}, {"x":missionData[1][IMU_TIME_HEADER[0]], "y": np.abs(missionData[1][TRUTH_NPOS_DELTA_HEADER[1]]), "label": "High Grade IMU Error"}, + {"x":missionData[0][IMU_TIME_HEADER[0]], "y": np.polyval(poly_low, missionData[0][IMU_TIME_HEADER[0]]), "label": "Low Grade Best Fit Curve"}, {"x":missionData[1][IMU_TIME_HEADER[0]], "y": np.polyval(poly_high, missionData[1][IMU_TIME_HEADER[0]]), "label": "High Grade Best Fit Curve"}, ] } - makeGraph(graphData, True, False, figSavePath="./images/m1_error_percent.png") + makeGraph(graphData, False, False, figSavePath="./images/m1_error_percent.png") if __name__ == '__main__': diff --git a/makeGraph.py b/makeGraph.py index d712caa..2f59d4c 100644 --- a/makeGraph.py +++ b/makeGraph.py @@ -4,6 +4,7 @@ #### 2023 - Added UQ Colors #### 2023 - Added pltKeyClose function #### 2023 - Added UQ Default Colours to MatPlotLib +#### 2023 - Added auto-magic 3D plot generation, label addition & min/max line points __author__ = "Cal Wing" __version__ = "0.1.12" @@ -280,6 +281,11 @@ def makeGraph(graphData, showPlot=True, doProgramBlock=True, figSavePath=None, h additional_legends = [] + if bool(sum([("z" in pData) for pData in axGraphData["plots"]])): + orig_ax = ax1 + ax1 = fig.add_subplot(orig_ax.get_position(), projection='3d') + orig_ax.remove() + # Duct Tape ax = ax1 @@ -304,9 +310,14 @@ def makeGraph(graphData, showPlot=True, doProgramBlock=True, figSavePath=None, h elif "y2" in pData: yData = pData["y2"] ax = ax2 + + zData = pData["z"] if "z" in pData else None if "type" not in pData or pData["type"] == "plot": - currentLine = ax.plot(xData, yData, getSafeValue("z"), label=getSafeValue("label"), color=getSafeColour, **optArgs) + if zData is not None: + currentLine = ax.plot(xData, yData, zData, label=getSafeValue("label"), color=getSafeColour, **optArgs) + else: + currentLine = ax.plot(xData, yData, label=getSafeValue("label"), color=getSafeColour, **optArgs) currentLine = currentLine[0] currentLineColour = currentLine.get_color() @@ -442,7 +453,7 @@ def makeGraph(graphData, showPlot=True, doProgramBlock=True, figSavePath=None, h ax = ax1 if "xLabel" in axGraphData: ax.set_xlabel(axGraphData["xLabel"]) # Add an x-label to the axes. if "yLabel" in axGraphData: ax.set_ylabel(axGraphData["yLabel"]) # Add an y-label to the axes. - if "zLabel" in axGraphData: ax2.set_zlabel(axGraphData["zLabel"]) # Add a y2-label to the axes. + if "zLabel" in axGraphData: ax.set_zlabel(axGraphData["zLabel"]) # Add a y2-label to the axes. if "y2Label" in axGraphData: ax2.set_ylabel(axGraphData["y2Label"]) # Add a y2-label to the axes. if "title" in axGraphData: ax.set_title(axGraphData["title"]) # Add an title to the axes. if "axis" in axGraphData: ax.axis(axGraphData["axis"]) # Set the axis type