Load Pressure Data & Graph

This commit is contained in:
Cal Wing 2024-08-26 13:39:38 +10:00
parent 8cd2fe414b
commit d838b54556
3 changed files with 105 additions and 50 deletions

2
.gitignore vendored
View File

@ -166,4 +166,4 @@ images
# Temp Folder # Temp Folder
tmp tmp
~$* data/~$*

119
main.py
View File

@ -7,6 +7,7 @@ import numpy as np
import pandas as pd import pandas as pd
from tqdm import tqdm from tqdm import tqdm
from numpy import sqrt
from makeGraph import makeGraph, pltKeyClose, UQ_COLOURS as UQC # Custom Graphing Lib from makeGraph import makeGraph, pltKeyClose, UQ_COLOURS as UQC # Custom Graphing Lib
@ -16,7 +17,7 @@ from makeGraph import makeGraph, pltKeyClose, UQ_COLOURS as UQC # Custom Graphin
# Make sure the relevant folders folder exists # Make sure the relevant folders folder exists
#folders = ["./images", "./tmp", "./data"] #folders = ["./images", "./tmp", "./data"]
folders = ["./images"] folders = ["./images", './images/pressure', './images/cp']
for folder in folders: for folder in folders:
if not os.path.isdir(folder): os.mkdir(folder) if not os.path.isdir(folder): os.mkdir(folder)
@ -24,60 +25,84 @@ for folder in folders:
INCH_TO_M = 0.0254 INCH_TO_M = 0.0254
GRAVITY = 9.81 #m/s^2 GRAVITY = 9.81 #m/s^2
PITOT_PLACEMENT = ( # mm from base CHORD_LEN = 90 #mm
0, PITOT_PLACEMENT = np.array((0,4,8,16,25,34,43,53,61,70,5,9,17,25,34,43,53,61,70)) # mm from base of chord
4, PITOT_PLACEMENT_CHORD_NORM = PITOT_PLACEMENT / CHORD_LEN
8,
16,
25,
34,
43,
53,
61,
70,
5,
9,
17,
25,
34,
43,
53,
61,
70,
)
print("Loading Data") print("="*15, "Loading Data", "="*15)
data = pd.read_excel('.\\data\\508 RPM Results.xlsx', sheet_name=None, header=None) data_508rpm = {
print("Loaded Data") "rpm": 508,
"airSpeed": 10,
"data": pd.read_excel('.\\data\\508 RPM Results.xlsx', sheet_name=None, header=None),
"AoA": (0,1,2,3,4,5,6,7,8,9)
}
sheet1 = data['0 AoA'] data_1000rpm = {
#print(sheet1) "rpm": 1000,
"airSpeed": 20.40408122,
"data": pd.read_excel('.\\data\\1000 RPM Results.xlsx', sheet_name=None, header=None),
"AoA": (1,2,4,6,8,10,12,14,16)
}
air_speed = 10 # m/s print("="*15, "Loaded Data", "="*15)
water_density = sheet1.iloc[0, 2] # kg/m^3
air_density = sheet1.iloc[1, 2] # kg/m^3
atm_presure_inch = sheet1.iloc[24, 12] # inch
pitot_height_inch = sheet1.iloc[4:23, 11] def make_pressure_graph(sheet1, aoa, rpm, air_speed, doGraph=True):
pitot_height_m = (pitot_height_inch - atm_presure_inch)*INCH_TO_M water_density = sheet1.iloc[0, 2] # kg/m^3
air_density = sheet1.iloc[1, 2] # kg/m^3
atm_presure_inch = sheet1.iloc[24, 12] # inch
pressure = water_density * GRAVITY * pitot_height_m pitot_height_inch = sheet1.iloc[4:23, 11]
pitot_height_m = (pitot_height_inch - atm_presure_inch)*INCH_TO_M
#print(pressure) pressure = water_density * GRAVITY * pitot_height_m
#print(pressure.min(), pressure.max())
#print(pressure)
#print(pressure.min(), pressure.max())
makeGraph({ graph = {
"title": "Simple Plot", "title": f"Pressure vs Pitot Placement along Chord\nfor a Clark Y 14% Aerofoil at:\nα = {int(aoa):d}° at {rpm:d} RPM ({air_speed:.1f}m/s)",
"xLabel": "x label", "windowTitle": f"Pressure along Clark Y 14% Airfoil - Alpha {int(aoa):d} Degrees - {rpm:d}rpm - {air_speed:.1f}m_s",
"yLabel": "y label", "xLabel": "Pitot Placement [mm]",
"plots": [ "yLabel": "Pressure [Pa]",
{"x":PITOT_PLACEMENT, "y":pressure, "label":"Linear", "type":"scatter"}, "grid": True,
] "yLim": (pressure.min()-10, pressure.max()+10),
}) "plots": [
{"x": PITOT_PLACEMENT[:10], "y":pressure[:10], "colour": UQC["purple"]},
{"x": PITOT_PLACEMENT[10:], "y":pressure[10:], "colour": UQC["purple"]},
{"x": [PITOT_PLACEMENT[0], PITOT_PLACEMENT[10]], "y": [pressure.iloc[0], pressure.iloc[10]], "colour": UQC["purple"]},
{"x": [PITOT_PLACEMENT[9], PITOT_PLACEMENT[18]], "y": [pressure.iloc[9], pressure.iloc[18]], "colour": UQC["purple"]},
{"x": PITOT_PLACEMENT[:10], "y":pressure[:10], "colour": UQC["purple"], "alpha":0.2, "type":"fill"},
{"x": PITOT_PLACEMENT[10:], "y":pressure[10:], "colour": "w", "type":"fill"},
{"x":[PITOT_PLACEMENT[0], PITOT_PLACEMENT[10]], "y":[pressure.iloc[0], pressure.iloc[10]], "colour": "w", "type":"fill"},
{"x":PITOT_PLACEMENT, "y":pressure, "label":"Pressure Data", "type":"scatter"},
{"label":[str(i) for i in range(1, len(PITOT_PLACEMENT)+1)], "x":PITOT_PLACEMENT, "y":pressure, "type":"annotate"}
]
}
if doGraph:
makeGraph(graph, False, figSavePath=f'./images/pressure/{{0}}.png')
return pressure, graph, (water_density, air_density, atm_presure_inch, pitot_height_inch)
def main():
pass
if __name__ == '__main__': if __name__ == '__main__':
main() print("Loading Data & Generating Pressure Graphs")
data = {}
for raw_data in tqdm((data_508rpm, data_1000rpm), position=0):
aoa_data = {}
for aoa in tqdm(raw_data["AoA"], position=1):
sheet = raw_data["data"][f"{aoa} AoA"]
aoa_data[aoa] = make_pressure_graph(sheet, aoa, raw_data["rpm"], raw_data["airSpeed"], False)
data[raw_data["rpm"]] = aoa_data
print("Data Loaded")

View File

@ -4,9 +4,10 @@
#### 2023 - Added UQ Colors #### 2023 - Added UQ Colors
#### 2023 - Added pltKeyClose function #### 2023 - Added pltKeyClose function
#### 2023 - Added UQ Default Colours to MatPlotLib #### 2023 - Added UQ Default Colours to MatPlotLib
#### 2024 - Added Annotation & Fill
__author__ = "Cal Wing" __author__ = "Cal Wing"
__version__ = "0.1.10" __version__ = "0.1.11"
from collections.abc import Iterator from collections.abc import Iterator
import numpy as np import numpy as np
@ -368,6 +369,33 @@ def makeGraph(graphData, showPlot=True, doProgramBlock=True, figSavePath=None, h
align = getSafeValue("align", align) align = getSafeValue("align", align)
ax.text(getSafeValue("x", 0.05), getSafeValue("y", 0.95), pData["text"], transform=ax.transAxes, fontsize=getSafeValue("fontsize", None), va=align[0], ha=align[1], bbox=props) ax.text(getSafeValue("x", 0.05), getSafeValue("y", 0.95), pData["text"], transform=ax.transAxes, fontsize=getSafeValue("fontsize", None), va=align[0], ha=align[1], bbox=props)
elif pData["type"] == "annotate":
if type(pData["label"]) == str:
if "pos" in pData:
pData["x"] = pData["pos"][0]
pData["y"] = pData["pos"][1]
ax.annotate(
pData["label"], # this is the text
(pData["x"],pData["y"]), # these are the coordinates to position the label
textcoords=getSafeValue("offType", "offset points"), # how to position the text
xytext=getSafeValue("offset", (0,10)), # distance from text to points (x,y)
ha=getSafeValue("align", 'center') # horizontal alignment can be left, right or center
)
else:
if "pos" not in pData:
pData["pos"] = list(zip(pData['x'], pData['y']))
for i, label in enumerate(pData["label"]):
ax.annotate(
label, # this is the text
(pData["pos"][i][0], pData["pos"][i][1]), # these are the coordinates to position the label
textcoords=getSafeValue("offType", "offset points"), # how to position the text
xytext=getSafeValue("offset", (0,10)), # distance from text to points (x,y)
ha=getSafeValue("align", 'center') # horizontal alignment can be left, right or center
)
elif pData["type"] == "fill":
ax.fill_between(list(pData["x"]), list(pData["y"]), color=getSafeColour, alpha=getSafeValue("alpha", 1), linewidth=getSafeValue("linewidth", None))
#ax.fill_between(xA, yA, color="w")
#Set extra options as needed #Set extra options as needed
@ -440,6 +468,8 @@ def makeGraph(graphData, showPlot=True, doProgramBlock=True, figSavePath=None, h
fig.suptitle(graphData["figTitle"], fontsize=getSafeValue("figTitleFontSize")) fig.suptitle(graphData["figTitle"], fontsize=getSafeValue("figTitleFontSize"))
fig.canvas.manager.set_window_title(graphData["figTitle"].replace("\n", " ")) fig.canvas.manager.set_window_title(graphData["figTitle"].replace("\n", " "))
if "windowTitle" in graphData:
fig.canvas.manager.set_window_title(graphData["windowTitle"].replace("\n", " "))
fig.tight_layout() #Fix labels being cut off sometimes fig.tight_layout() #Fix labels being cut off sometimes
@ -448,7 +478,7 @@ def makeGraph(graphData, showPlot=True, doProgramBlock=True, figSavePath=None, h
flatAxes[-1].set_axis_off() flatAxes[-1].set_axis_off()
if figSavePath: if figSavePath:
fig.savefig(figSavePath) fig.savefig(figSavePath.format(fig.canvas.manager.get_window_title()))
if showPlot: if showPlot:
plt.show(block=doProgramBlock) #Show the plot and also block the program - doing things OO style allow for more flexible programs plt.show(block=doProgramBlock) #Show the plot and also block the program - doing things OO style allow for more flexible programs