Skip to content

Commit

Permalink
add combine method
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdudfield committed Dec 12, 2023
1 parent 2579f43 commit b8e3b79
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
5 changes: 5 additions & 0 deletions quartz_solar_forecast/eval/forecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def run_forecast(pv_df: pd.DataFrame, nwp_df: pd.DataFrame, nwp_source="ICON") -
ts = datetime.fromisoformat(ts)

# make pv and nwp data from GFS
# TODO move this to model
nwp_xr = xr.DataArray(
data=nwp_site_df.values,
dims=["step", "variable"],
Expand Down Expand Up @@ -97,6 +98,10 @@ def run_forecast(pv_df: pd.DataFrame, nwp_df: pd.DataFrame, nwp_source="ICON") -
times = pd.date_range(start=x.ts, periods=len(pred.powers), freq="15min")
pred_df = pd.DataFrame({"power_wh": pred.powers}, index=times)

# only select hourly predictions
pred_df = pred_df.resample("1H").mean()
pred_df["horizon_hours"] = range(0, len(pred_df))

all_predictions.append(pred_df)

return pd.concat(all_predictions)
36 changes: 36 additions & 0 deletions quartz_solar_forecast/eval/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import pandas as pd





def combine_forecast_ground_truth(forecast_df, ground_truth_df):
"""
Combine the forecast results with the ground truth (ts, id, horizon (in hours), pred, truth, diff)
forecast_df should have the following columns
- timestamp
- pv_id
- horizon_hours
- power
ground_truth_df should have the following columns
- timestamp
- pv_id
- horizon_hours
- power
"""

# rename power to forecast_power
forecast_df = forecast_df.rename(columns={"power": "forecast_power"})

# rename power to ground_truth_power
ground_truth_df = ground_truth_df.rename(columns={"power": "ground_truth_power"})

# merge the two dataframes
combined_df = pd.merge(forecast_df, ground_truth_df, on=["timestamp", "pv_id", "horizon_hours"])

return combined_df

4 changes: 4 additions & 0 deletions quartz_solar_forecast/evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"""
from quartz_solar_forecast.eval.nwp import get_nwp
from quartz_solar_forecast.eval.forecast import run_forecast
from quartz_solar_forecast.eval.utils import combine_forecast_ground_truth

import pandas as pd

Expand All @@ -18,6 +19,7 @@ def run_eval(testset_path):
# Extract generation data and metadata for specific sites and timestamps for the testset from Hugging Face. (Zak)

# Split data into PV inputs and ground truth. (Zak)
ground_truth_df = None # TODO

# Collect NWP data from Hugging Face, ICON. (Peter)
nwp_df = get_nwp(testset)
Expand All @@ -27,8 +29,10 @@ def run_eval(testset_path):
predictions_df = run_forecast(pv_df=None, nwp_df=nwp_df)

# Combine the forecast results with the ground truth (ts, id, horizon (in hours), pred, truth, diff)
results_df = combine_forecast_ground_truth(predictions_df, ground_truth_df)

# Save file
results_df.to_csv("results.csv")

# Calculate and print metrics: MAE

Expand Down

0 comments on commit b8e3b79

Please sign in to comment.