SM-Bello's picture
Upload 3 files
10722fd verified
Raw
History Blame Contribute Delete
1.8 kB
import pandas as pd
import matplotlib.pyplot as plt
# 1. Load the data
df = pd.read_csv('flightgear_phm_log.csv')
# 2. Define the plot
fig, ax1 = plt.subplots(figsize=(10, 5))
# Plot RUL (Left Axis)
color1 = '#38BDF8' # Consistent with your dashboard
ax1.set_xlabel('Frame (10 Hz)')
ax1.set_ylabel('Predicted RUL (cycles)', color=color1, fontweight='bold')
ax1.plot(df['frame'], df['rul_mean'], color=color1, label='RUL (mean)', lw=2)
ax1.fill_between(df['frame'],
df['rul_mean'] - 1.645 * df['rul_std'],
df['rul_mean'] + 1.645 * df['rul_std'],
alpha=0.2, color=color1, label='90% Confidence Interval')
ax1.tick_params(axis='y', labelcolor=color1)
# Plot Health % (Right Axis)
ax2 = ax1.twinx()
color2 = '#EF4444' # Critical red
ax2.set_ylabel('Relative Health (%)', color=color2, fontweight='bold')
ax2.plot(df['frame'], df['health_pct'], color=color2, linestyle='--', lw=2, label='Health %')
ax2.tick_params(axis='y', labelcolor=color2)
ax2.set_ylim(0, 110)
# Add Fault Injection marker
# Based on your script, the fault injector logic starts near frame 1800
fault_frame = 1800
plt.axvline(x=fault_frame, color='gray', linestyle=':', label='Fault Injection (HPT)')
# Aesthetics
plt.title('Figure 9: Real-time PHM Response to Simulated HPT Blade Degradation', fontweight='bold')
fig.tight_layout()
plt.grid(True, alpha=0.3)
# Combine legends from both axes
lines1, labels1 = ax1.get_legend_handles_labels()
lines2, labels2 = ax2.get_legend_handles_labels()
ax1.legend(lines1 + lines2, labels1 + labels2, loc='lower left', frameon=True)
# Save as PDF for the journal
plt.savefig('fig9_health_timeseries.pdf', format='pdf')
print("Successfully generated fig9_health_timeseries.pdf")
plt.show()