|
| 1 | +import pandas as pd |
| 2 | +import matplotlib.pyplot as plt |
| 3 | +import argparse |
| 4 | + |
| 5 | +def plot_wind_data(csv_file): |
| 6 | + # Load the CSV file |
| 7 | + df = pd.read_csv(csv_file) |
| 8 | + |
| 9 | + # Convert obsTimeLocal to datetime |
| 10 | + df["obsTimeLocal"] = pd.to_datetime(df["obsTimeLocal"]) |
| 11 | + |
| 12 | + # Create a figure with two subplots |
| 13 | + fig, axes = plt.subplots(nrows=2, ncols=1, figsize=(12, 10)) |
| 14 | + |
| 15 | + # Plot wind direction trends |
| 16 | + axes[0].plot(df["obsTimeLocal"], df["winddirHigh"], label="Wind Dir High", alpha=0.7) |
| 17 | + axes[0].plot(df["obsTimeLocal"], df["winddirAvg"], label="Wind Dir Avg", alpha=0.7) |
| 18 | + axes[0].plot(df["obsTimeLocal"], df["winddirLow"], label="Wind Dir Low", alpha=0.7) |
| 19 | + axes[0].set_xlabel("Time") |
| 20 | + axes[0].set_ylabel("Wind Direction (Degrees)") |
| 21 | + axes[0].set_title("Wind Direction Trends Over Time") |
| 22 | + axes[0].legend() |
| 23 | + axes[0].tick_params(axis='x', rotation=45) |
| 24 | + axes[0].grid() |
| 25 | + |
| 26 | + # Plot wind speed trends |
| 27 | + axes[1].plot(df["obsTimeLocal"], df["windspeedHigh"], label="Wind Speed High", alpha=0.7) |
| 28 | + axes[1].plot(df["obsTimeLocal"], df["windspeedAvg"], label="Wind Speed Avg", alpha=0.7) |
| 29 | + axes[1].plot(df["obsTimeLocal"], df["windspeedLow"], label="Wind Speed Low", alpha=0.7) |
| 30 | + axes[1].set_xlabel("Time") |
| 31 | + axes[1].set_ylabel("Wind Speed (km/h)") |
| 32 | + axes[1].set_title("Wind Speed Trends Over Time") |
| 33 | + axes[1].legend() |
| 34 | + axes[1].tick_params(axis='x', rotation=45) |
| 35 | + axes[1].grid() |
| 36 | + |
| 37 | + plt.tight_layout() |
| 38 | + plt.show() |
| 39 | + |
| 40 | +if __name__ == "__main__": |
| 41 | + parser = argparse.ArgumentParser(description="Analyze and plot wind data from a CSV file.") |
| 42 | + parser.add_argument("csv_file", type=str, help="Path to the wind-history CSV file") |
| 43 | + args = parser.parse_args() |
| 44 | + |
| 45 | + plot_wind_data(args.csv_file) |
0 commit comments