MECH3410-P1-Graphs/main.py

197 lines
8.4 KiB
Python
Raw Normal View History

2024-08-25 13:20:40 +00:00
# Mech3410-P1-Graphs
2024-08-26 02:15:12 +00:00
# Cal Wing - Aug 2024
2024-08-25 13:20:40 +00:00
#
import os, time
import numpy as np
2024-08-26 02:15:12 +00:00
import pandas as pd
2024-08-25 13:20:40 +00:00
from tqdm import tqdm
2024-08-26 03:39:38 +00:00
from numpy import sqrt
2024-08-25 13:20:40 +00:00
2024-08-26 04:38:52 +00:00
from makeGraph import makeGraph, pltKeyClose, UQ_COLOURS as UQC, uq_colour_cycler_factory as uqccf # Custom Graphing Lib
2024-08-25 13:20:40 +00:00
# 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", "./data"]
2024-08-26 03:39:38 +00:00
folders = ["./images", './images/pressure', './images/cp']
2024-08-25 13:20:40 +00:00
for folder in folders:
if not os.path.isdir(folder): os.mkdir(folder)
2024-08-26 02:15:12 +00:00
INCH_TO_M = 0.0254
GRAVITY = 9.81 #m/s^2
2024-08-26 03:39:38 +00:00
CHORD_LEN = 90 #mm
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
PITOT_PLACEMENT_CHORD_NORM = PITOT_PLACEMENT / CHORD_LEN
print("="*15, "Loading Data", "="*15)
data_508rpm = {
"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)
}
data_1000rpm = {
"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)
}
print("="*15, "Loaded Data", "="*15)
def make_pressure_graph(sheet1, aoa, rpm, air_speed, doGraph=True):
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]
pitot_height_m = (pitot_height_inch - atm_presure_inch)*INCH_TO_M
pressure = water_density * GRAVITY * pitot_height_m
#print(pressure)
#print(pressure.min(), pressure.max())
graph = {
2024-08-26 04:38:52 +00:00
"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)",
"windowTitle": f"Pressure along Clark Y 14% Airfoil - Alpha {int(aoa):d} Degrees - {rpm:d}rpm - {air_speed:.1f}m_s",
"xLabel": "Pitot Placement [mm]",
"yLabel": "Pressure [Pa]",
"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"},
{"type":"text", "x": 0.98, "y": 0.02, "text": f"Min: {pressure.min():.3f} Pa\nMax: {pressure.max():.3f} Pa", "align": ('bottom', 'right')}
]
}
2024-08-26 03:39:38 +00:00
if doGraph:
makeGraph(graph, False, figSavePath=f'./images/pressure/{{0}}.png')
return pressure, graph, (water_density, air_density, atm_presure_inch, pitot_height_inch)
2024-08-26 02:15:12 +00:00
2024-08-26 05:16:41 +00:00
def make_rpm_grpah():
air_density = data_508rpm["data"]["0 AoA"].iloc[1, 2] # kg/m^3
rpm = np.concat((np.array([0]), np.array(data_508rpm["data"]["0 AoA"].iloc[4:14, 2])))
pressure = np.concat((np.array([0]), np.array(data_508rpm["data"]["0 AoA"].iloc[4:14, 4], dtype=np.float64)))
airSpeed = sqrt(-pressure * 2 / air_density)
x = np.linspace(rpm[0], rpm[-1], 1000)
y = 0.0212*x - 0.7751
graph = {
"title": f"RPM vs Velocity for Wind Tunnel 3",
"xLabel": "Fan RPM",
"yLabel": "Airspeed [m/s]",
"grid": True,
"plots": [
{"x": x, "y":y, "label":"Linear Estimate", "args":{"linestyle":"--"}, "colour": UQC["neutral"]},
{"type": "scatter", "x":rpm, "y": airSpeed, "label": "Measured Velocity", "colour":UQC["purple"], "args":{"zorder":2}},
{"type": "point", "x":508, "y": 10, "label": "Selected RPM (508)", "colour":UQC["red"], "zorder":3},
{"type":"text", "x": 0.98, "y": 0.02, "text": f"Velocity at 508 RPM: {10:.3f} m/s\nVelocity at 1000 RPM: {airSpeed[-1]:.3f} m/s", "align": ('bottom', 'right')},
{"type":"text", "x": 0.80, "y": 0.85, "text": f"$y = 0.0212 \\cdot x - 0.7751$", "align": ('bottom', 'right'), "facecolour": UQC["neutral"]}
]
}
makeGraph(graph, False, figSavePath='./images/{0}.png')
2024-08-26 02:15:12 +00:00
if __name__ == '__main__':
2024-08-26 05:16:41 +00:00
print("Generating RPM Graph")
make_rpm_grpah()
2024-08-26 03:39:38 +00:00
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"]
2024-08-26 05:16:41 +00:00
aoa_data[aoa] = make_pressure_graph(sheet, aoa, raw_data["rpm"], raw_data["airSpeed"], False)
2024-08-26 04:38:52 +00:00
2024-08-26 03:39:38 +00:00
data[raw_data["rpm"]] = aoa_data
2024-08-26 04:38:52 +00:00
2024-08-26 05:16:41 +00:00
if False:
2024-08-26 04:38:52 +00:00
# All
graph = {
"title": f"Pressure vs Pitot Placement along Chord\nfor a Clark Y 14% Aerofoil at:\n{raw_data["rpm"]:d} RPM ({raw_data["airSpeed"]:.1f}m/s)",
"windowTitle": f"All Pressure along Clark Y 14% Airfoil - {raw_data["rpm"]:d}rpm - {raw_data["airSpeed"]:.1f}m_s",
"xLabel": "Pitot Placement [mm]",
"yLabel": "Pressure [Pa]",
"grid": True,
"ledgLoc": 1,
"plots": []
}
colour_cycle = uqccf()
for aoa, c in zip(aoa_data, colour_cycle):
this_data = aoa_data[aoa]
pressure = this_data[0]
plts = (
{"x": PITOT_PLACEMENT[:10], "y":pressure[:10], "colour": c["color"]},
{"x": PITOT_PLACEMENT[10:], "y":pressure[10:], "colour": c["color"]},
{"x": [PITOT_PLACEMENT[0], PITOT_PLACEMENT[10]], "y": [pressure.iloc[0], pressure.iloc[10]], "colour": c["color"]},
{"x": [PITOT_PLACEMENT[9], PITOT_PLACEMENT[18]], "y": [pressure.iloc[9], pressure.iloc[18]], "colour": c["color"]},
{"x":PITOT_PLACEMENT, "y":pressure, "label":f"α = {int(aoa):d}°", "type":"scatter", "colour": c["color"]},
)
for plt in plts:
graph["plots"].append(plt)
if raw_data["rpm"] == 508:
graph['xLim'] = (
min(PITOT_PLACEMENT) - 5,
max(PITOT_PLACEMENT) + 20
)
graph["figSize"] = (8, 6)
makeGraph(graph, False, figSavePath="./images/pressure/__{0}.png")
graph["plots"] = []
graph["windowTitle"] = f"Pressure along Clark Y 14% Airfoil - {raw_data["rpm"]:d}rpm - {raw_data["airSpeed"]:.1f}m_s"
colour_cycle = uqccf()
for aoa, c in list(zip(aoa_data, colour_cycle))[1::2]:
this_data = aoa_data[aoa]
pressure = this_data[0]
plts = (
{"x": PITOT_PLACEMENT[:10], "y":pressure[:10], "colour": c["color"]},
{"x": PITOT_PLACEMENT[10:], "y":pressure[10:], "colour": c["color"]},
{"x": [PITOT_PLACEMENT[0], PITOT_PLACEMENT[10]], "y": [pressure.iloc[0], pressure.iloc[10]], "colour": c["color"]},
{"x": [PITOT_PLACEMENT[9], PITOT_PLACEMENT[18]], "y": [pressure.iloc[9], pressure.iloc[18]], "colour": c["color"]},
{"x":PITOT_PLACEMENT, "y":pressure, "label":f"α = {int(aoa):d}°", "type":"scatter", "colour": c["color"]},
)
for plt in plts:
graph["plots"].append(plt)
makeGraph(graph, False, figSavePath="./images/pressure/__{0}.png")
2024-08-26 03:39:38 +00:00
print("Data Loaded")
2024-08-26 04:38:52 +00:00
2024-08-26 03:39:38 +00:00
2024-08-26 05:16:41 +00:00
2024-08-26 03:39:38 +00:00