Generated all graphs correctly

This commit is contained in:
Cal Wing 2024-08-26 16:16:15 +10:00
parent 66c4d7d23a
commit b1e53552fb
2 changed files with 69 additions and 17 deletions

65
main.py
View File

@ -59,6 +59,12 @@ def make_pressure_graph(sheet1, aoa, rpm, air_speed, doGraph=True):
#print(pressure) #print(pressure)
#print(pressure.min(), pressure.max()) #print(pressure.min(), pressure.max())
# Extrapolate Aerofoil Tip
p1 = (PITOT_PLACEMENT[9], pressure.iloc[9])
p2 = (PITOT_PLACEMENT[18], pressure.iloc[18])
pN = (0.9*CHORD_LEN, p2[1] + (p1[1]-p2[1])/2)
#print(aoa, rpm, p1[1], p2[1], (p1[1]-p2[1])/2, pN[1], pN[1] > p1[1])
graph = { graph = {
"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)", "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)",
@ -68,28 +74,37 @@ def make_pressure_graph(sheet1, aoa, rpm, air_speed, doGraph=True):
"grid": True, "grid": True,
"yLim": (pressure.min()-10, pressure.max()+10), "yLim": (pressure.min()-10, pressure.max()+10),
"plots": [ "plots": [
# Draw Lines
{"x": PITOT_PLACEMENT[:10], "y":pressure[:10], "colour": UQC["purple"]}, {"x": PITOT_PLACEMENT[:10], "y":pressure[:10], "colour": UQC["purple"]},
{"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[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[9], PITOT_PLACEMENT[18]], "y": [pressure.iloc[9], pressure.iloc[18]], "colour": UQC["purple"]},
# Draw Extrapolated Airfoil Tip
{"x": [PITOT_PLACEMENT[9], pN[0]], "y": [pressure.iloc[9], pN[1]], "colour": UQC["aqua"], "label": "Extrapolated Airfoil Tip"},
{"x": [PITOT_PLACEMENT[9], pN[0]], "y": [pressure.iloc[18], pN[1]], "colour": UQC["aqua"]},
# Draw Colour Shading
{"x": PITOT_PLACEMENT[:10], "y":pressure[:10], "colour": UQC["purple"], "alpha":0.2, "type":"fill"}, {"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[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[0], PITOT_PLACEMENT[10]], "y":[pressure.iloc[0], pressure.iloc[10]], "colour": "w", "type":"fill"},
{"x": [PITOT_PLACEMENT[9], pN[0]], "y": [pressure.iloc[9], pN[1]], "colour": UQC["aqua"], "type":"fill", "alpha":0.2},
{"x":PITOT_PLACEMENT, "y":pressure, "label":"Pressure Data", "type":"scatter"}, {"x":[PITOT_PLACEMENT[9], pN[0]], "y": [pressure.iloc[18], pN[1]], "colour": "w", "type":"fill"},
# Draw Points & text
{"x":PITOT_PLACEMENT, "y":pressure, "label":"Pressure Data", "type":"scatter", "args":{"zorder":2}},
{"label":[str(i) for i in range(1, len(PITOT_PLACEMENT)+1)], "x":PITOT_PLACEMENT, "y":pressure, "type":"annotate"}, {"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')} {"type":"text", "x": 0.98, "y": 0.02, "text": f"Min: {pressure.min():.3f} Pa\nMax: {pressure.max():.3f} Pa", "align": ('bottom', 'right')}
] ]
} }
if doGraph: if doGraph:
makeGraph(graph, False, figSavePath=f'./images/pressure/{{0}}.png') makeGraph(graph, False, figSavePath=f'./images/pressure/{{0}}.png', closeFig=True)
return pressure, graph, (water_density, air_density, atm_presure_inch, pitot_height_inch) return pressure, graph, (water_density, air_density, atm_presure_inch, pitot_height_inch), (p1, p2, pN)
def make_rpm_grpah(): def make_rpm_graph():
air_density = data_508rpm["data"]["0 AoA"].iloc[1, 2] # kg/m^3 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]))) 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))) pressure = np.concat((np.array([0]), np.array(data_508rpm["data"]["0 AoA"].iloc[4:14, 4], dtype=np.float64)))
@ -119,7 +134,8 @@ def make_rpm_grpah():
if __name__ == '__main__': if __name__ == '__main__':
print("Generating RPM Graph") print("Generating RPM Graph")
make_rpm_grpah() #make_rpm_graph()
print("Generated")
print("Loading Data & Generating Pressure Graphs") print("Loading Data & Generating Pressure Graphs")
data = {} data = {}
@ -128,11 +144,11 @@ if __name__ == '__main__':
for aoa in tqdm(raw_data["AoA"], position=1): for aoa in tqdm(raw_data["AoA"], position=1):
sheet = raw_data["data"][f"{aoa} AoA"] sheet = raw_data["data"][f"{aoa} AoA"]
aoa_data[aoa] = make_pressure_graph(sheet, aoa, raw_data["rpm"], raw_data["airSpeed"], False) aoa_data[aoa] = make_pressure_graph(sheet, aoa, raw_data["rpm"], raw_data["airSpeed"], True)
data[raw_data["rpm"]] = aoa_data data[raw_data["rpm"]] = aoa_data
if False: if True:
# All # All
graph = { 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)", "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)",
@ -148,12 +164,24 @@ if __name__ == '__main__':
for aoa, c in zip(aoa_data, colour_cycle): for aoa, c in zip(aoa_data, colour_cycle):
this_data = aoa_data[aoa] this_data = aoa_data[aoa]
pressure = this_data[0] pressure = this_data[0]
# Extrapolate Aerofoil Tip
p1 = (PITOT_PLACEMENT[9], pressure.iloc[9])
p2 = (PITOT_PLACEMENT[18], pressure.iloc[18])
pN = (0.9*CHORD_LEN, p2[1] + (p1[1]-p2[1])/2)
plts = ( plts = (
{"x": PITOT_PLACEMENT[:10], "y":pressure[:10], "colour": c["color"]}, {"x": PITOT_PLACEMENT[:10], "y":pressure[:10], "colour": c["color"]},
{"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[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"]}, #{"x": [PITOT_PLACEMENT[9], PITOT_PLACEMENT[18]], "y": [pressure.iloc[9], pressure.iloc[18]], "colour": c["color"]},
{"x": [PITOT_PLACEMENT[9], pN[0]], "y": [pressure.iloc[9], pN[1]], "colour": c["color"].lighten(0.4)},
{"x": [PITOT_PLACEMENT[9], pN[0]], "y": [pressure.iloc[18], pN[1]], "colour": c["color"].lighten(0.4)},
{"x":PITOT_PLACEMENT, "y":pressure, "label":f"α = {int(aoa):d}°", "type":"scatter", "colour": c["color"], "args":{"zorder":2}},
) )
for plt in plts: for plt in plts:
graph["plots"].append(plt) graph["plots"].append(plt)
@ -175,11 +203,22 @@ if __name__ == '__main__':
for aoa, c in list(zip(aoa_data, colour_cycle))[1::2]: for aoa, c in list(zip(aoa_data, colour_cycle))[1::2]:
this_data = aoa_data[aoa] this_data = aoa_data[aoa]
pressure = this_data[0] pressure = this_data[0]
# Extrapolate Aerofoil Tip
p1 = (PITOT_PLACEMENT[9], pressure.iloc[9])
p2 = (PITOT_PLACEMENT[18], pressure.iloc[18])
pN = (0.9*CHORD_LEN, p2[1] + (p1[1]-p2[1])/2)
plts = ( plts = (
{"x": PITOT_PLACEMENT[:10], "y":pressure[:10], "colour": c["color"]}, {"x": PITOT_PLACEMENT[:10], "y":pressure[:10], "colour": c["color"]},
{"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[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[9], PITOT_PLACEMENT[18]], "y": [pressure.iloc[9], pressure.iloc[18]], "colour": c["color"]},
{"x": [PITOT_PLACEMENT[9], pN[0]], "y": [pressure.iloc[9], pN[1]], "colour": c["color"].lighten(0.4)},
{"x": [PITOT_PLACEMENT[9], pN[0]], "y": [pressure.iloc[18], pN[1]], "colour": c["color"].lighten(0.4)},
{"x":PITOT_PLACEMENT, "y":pressure, "label":f"α = {int(aoa):d}°", "type":"scatter", "colour": c["color"]}, {"x":PITOT_PLACEMENT, "y":pressure, "label":f"α = {int(aoa):d}°", "type":"scatter", "colour": c["color"]},
) )
for plt in plts: for plt in plts:

View File

@ -16,6 +16,7 @@ import matplotlib.pyplot as plt
import matplotlib.colors as colors import matplotlib.colors as colors
from mpl_toolkits.axes_grid1 import make_axes_locatable from mpl_toolkits.axes_grid1 import make_axes_locatable
from cycler import cycler from cycler import cycler
import colorsys
# Define the UQ Colours # Define the UQ Colours
UQ_COLOURS_DICT = { UQ_COLOURS_DICT = {
@ -52,17 +53,27 @@ class ColourValue(str):
def __repr__(self) -> str: def __repr__(self) -> str:
return self.name + " " + self.value + " " + str(self.rgba()) return self.name + " " + self.value + " " + str(self.rgba())
def rgba(self) -> tuple[float, float, float, float]: def rgba(self, alpha = None) -> tuple[float, float, float, float]:
return colors.to_rgba(self.value) return colors.to_rgba(self.value, alpha)
def rgb(self) -> tuple[float, float, float]: def rgb(self) -> tuple[float, float, float]:
return colors.to_rgb() return colors.to_rgb(self.value)
def hex(self) -> str: def hex(self) -> str:
return self.value return self.value
def hsv(self) -> np.ndarray: def hsv(self) -> np.ndarray:
return colors.rgb_to_hsv(self.rgb()) return colors.rgb_to_hsv(self.rgb())
def hls(self) -> tuple[float, float, float]:
return colorsys.rgb_to_hls(*self.rgb())
def lighten(self, amount=0.5) -> tuple[float, float, float]:
hls = self.hls()
return colorsys.hls_to_rgb(hls[0], max(0, min(1, amount * hls[1])), hls[2])
# Define the UQ Colours in a nicer object # Define the UQ Colours in a nicer object
class ColourList(object): class ColourList(object):
@ -191,7 +202,7 @@ def colorbar(mappable, size="5%", pad=0.05, lsize=None, lpad=None, lax=True, **k
## Make Graph Function ## Make Graph Function
def makeGraph(graphData, showPlot=True, doProgramBlock=True, figSavePath=None, hideEmptyAxis=False) -> tuple[matplotlib.figure.Figure, tuple[matplotlib.axes.Axes, ...]]: def makeGraph(graphData, showPlot=True, doProgramBlock=True, figSavePath=None, hideEmptyAxis=False, closeFig=False) -> tuple[matplotlib.figure.Figure, tuple[matplotlib.axes.Axes, ...]]:
""" Generate a matplotlib graph based on a simple dictionary object """ Generate a matplotlib graph based on a simple dictionary object
Input: Input:
dict(graphData): The dictionary containing all the graph data - see example for more info dict(graphData): The dictionary containing all the graph data - see example for more info
@ -483,6 +494,8 @@ def makeGraph(graphData, showPlot=True, doProgramBlock=True, figSavePath=None, h
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
if closeFig:
matplotlib.pyplot.close(fig)
return fig, axes return fig, axes