Skip to content

Commit

Permalink
add better viz for sensor placement
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdsharpe committed Mar 15, 2024
1 parent b103b38 commit 405e67d
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -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())
Expand All @@ -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:
Expand All @@ -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"
)
Original file line number Diff line number Diff line change
Expand Up @@ -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.")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 405e67d

Please sign in to comment.