diff --git a/training/gen2_architecture/optimal_sensor_placement/compute_optimal_sensor_placement.py b/training/gen2_architecture/optimal_sensor_placement/compute_optimal_sensor_placement.py index 8949be2..48e2659 100644 --- a/training/gen2_architecture/optimal_sensor_placement/compute_optimal_sensor_placement.py +++ b/training/gen2_architecture/optimal_sensor_placement/compute_optimal_sensor_placement.py @@ -1,23 +1,39 @@ from load_data import df, Data import numpy as np -Cfs = np.stack([ - df[f"{side}_bl_H_{i}"] +df = df.to_pandas().dropna() + +data = np.stack([ + # (df[f"{side}_bl_theta_{i}"]) + (df[f"{side}_bl_H_{i}"]) + for side in [ + "upper", + "lower", + ] for i in range(Data.N) +], axis=1) + +data_flipped = np.stack([ + # (df[f"{side}_bl_theta_{i}"]) + (df[f"{side}_bl_H_{i}"]) for side in [ + "lower", "upper", - # "lower" ] + for i in range(Data.N) ], axis=1) -# Remove rows with any nans -Cfs = Cfs[~np.any(np.isnan(Cfs), axis=1)] +# Flip and augment +data = np.concatenate([ + data, + data_flipped +], axis=0) import pysensors as ps -model = ps.SSPOR(n_sensors=30) +model = ps.SSPOR(n_sensors=64) model.fit( - x=Cfs[:300], + x=data, ) sensor_ids = np.sort(model.get_selected_sensors()) @@ -30,6 +46,8 @@ import matplotlib.pyplot as plt import aerosandbox.tools.pretty_plots as p +fig, ax = plt.subplots(figsize=(6, 3)) + af = asb.KulfanAirfoil("naca0012") af.draw(show=False) for i in sensor_ids: @@ -39,4 +57,30 @@ else: x = np.linspace(0, 1, Data.N)[i - Data.N] plt.plot(*af.lower_coordinates(x).T, ".k", markersize=10) -p.show_plot("Optimal Sensor Locations") + +subtitle = "Question: \"If I have 64 sensors, where should I put them on a generic airfoil to reconstruct $H(s)$ with minimum error?\"" +import textwrap + +plt.text( # Top center of axes, textwrapped + 0.5, 0.95, + textwrap.fill(subtitle, width=65), + horizontalalignment='center', + verticalalignment='top', + transform=plt.gca().transAxes, + fontsize=11, alpha=0.7, +) + +answer = "Answer: \"Roughly evenly across the airfoil.\"" + +plt.text( + 0.5, 0.05, + textwrap.fill(answer, width=65), + horizontalalignment='center', + verticalalignment='bottom', + transform=plt.gca().transAxes, + fontsize=11, alpha=0.7, +) + +p.show_plot( + "Optimal Sensor Locations for Compressed\nSensing of Shape Factor" +) diff --git a/training/gen2_architecture/optimal_sensor_placement/generate_high_dim_xfoil_data.py b/training/gen2_architecture/optimal_sensor_placement/generate_high_dim_xfoil_data.py index 13aca82..4364463 100644 --- a/training/gen2_architecture/optimal_sensor_placement/generate_high_dim_xfoil_data.py +++ b/training/gen2_architecture/optimal_sensor_placement/generate_high_dim_xfoil_data.py @@ -14,7 +14,7 @@ # num_cpus=2, ) -datafile = "data_xfoil.csv" +datafile = "hd_data_xfoil.csv" n_procs = int(ray.cluster_resources()["CPU"]) print(f"Running on {n_procs} processes.") diff --git a/training/gen2_architecture/optimal_sensor_placement/load_data.py b/training/gen2_architecture/optimal_sensor_placement/load_data.py index e8fe883..41ca42e 100644 --- a/training/gen2_architecture/optimal_sensor_placement/load_data.py +++ b/training/gen2_architecture/optimal_sensor_placement/load_data.py @@ -15,7 +15,7 @@ raw_dfs = {} -for csv_file in data_directory.glob("data*.csv"): +for csv_file in data_directory.glob("hd_data*.csv"): print(f"Reading {csv_file}...") raw_dfs[csv_file.stem] = pl.read_csv( csv_file, has_header=False,