Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Large capacity #205

Merged
merged 3 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions quartz_solar_forecast/forecast.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from datetime import datetime, timedelta
import logging

import pandas as pd

from quartz_solar_forecast.data import get_nwp, make_pv_data
from quartz_solar_forecast.forecasts import forecast_v1_tilt_orientation, TryolabsSolarPowerPredictor
from quartz_solar_forecast.pydantic_models import PVSite

log = logging.getLogger(__name__)

def predict_ocf(
site: PVSite, model=None, ts: datetime | str = None, nwp_source: str = "icon"
Expand All @@ -25,13 +27,27 @@ def predict_ocf(
if isinstance(ts, str):
ts = datetime.fromisoformat(ts)

if site.capacity_kwp > 4:
log.warning("Your site capacity is greater than 4kWp, "
"however the model is trained on sites with capacity <= 4kWp."
"We therefore will run the model with a capacity of 4 kWp, "
"and we'll scale the results afterwards.")
capacity_kwp_original = site.capacity_kwp
site.capacity_kwp = 4
else:
capacity_kwp_original = site.capacity_kwp

# make pv and nwp data from nwp_source
nwp_xr = get_nwp(site=site, ts=ts, nwp_source=nwp_source)
pv_xr = make_pv_data(site=site, ts=ts)

# load and run models
pred_df = forecast_v1_tilt_orientation(nwp_source, nwp_xr, pv_xr, ts, model=model)

# scale the results if the capacity is different
if capacity_kwp_original != site.capacity_kwp:
pred_df["power_kw"] = pred_df["power_kw"] * capacity_kwp_original / site.capacity_kwp

return pred_df


Expand Down
20 changes: 19 additions & 1 deletion tests/test_forecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
from quartz_solar_forecast.pydantic_models import PVSite
from datetime import datetime, timedelta

import numpy as np


def test_run_forecast():
# make input data
site = PVSite(latitude=51.75, longitude=-1.25, capacity_kwp=1.25)
Expand Down Expand Up @@ -55,7 +58,22 @@ def test_run_forecast_historical():
print("\n Prediction based on UKMO NWP\n")
print(predications_df_ukmo)
print(f" Max: {predications_df_ukmo['power_kw'].max()}")

print("\n Prediction based on XGB\n")
print(predications_df_xgb)


def test_large_capacity():

# make input data
site = PVSite(latitude=51.75, longitude=-1.25, capacity_kwp=4)
site_large = PVSite(latitude=51.75, longitude=-1.25, capacity_kwp=4000)
ts = datetime.today() - timedelta(weeks=2)

# run model with icon, gfs and ukmo nwp
predications_df = run_forecast(site=site, model="gb", ts=ts, nwp_source="gfs")
predications_df_large = run_forecast(site=site_large, model="gb", ts=ts, nwp_source="gfs")

assert np.round(predications_df["power_kw"].sum() * 1000, 8) == np.round(
predications_df_large["power_kw"].sum(), 8
)
Loading