Skip to content

Commit

Permalink
Merge pull request #50 from armenbod/feature/issue-43/default-time-to…
Browse files Browse the repository at this point in the history
…-now-if-none

run_forecast sets to current timestamp rounded 15min if optional ts = None
  • Loading branch information
peterdudfield authored Feb 19, 2024
2 parents b735059 + 5765b6b commit 3308770
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
6 changes: 5 additions & 1 deletion quartz_solar_forecast/forecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@



def run_forecast(site: PVSite, ts: datetime | str, nwp_source: str = "icon") -> pd.DataFrame:
def run_forecast(site: PVSite, ts: datetime | str = None, nwp_source: str = "icon") -> pd.DataFrame:
"""
Run the forecast from NWP data
Expand All @@ -20,6 +20,10 @@ def run_forecast(site: PVSite, ts: datetime | str, nwp_source: str = "icon") ->
:return: The PV forecast of the site for time (ts) for 48 hours
"""

# set timestamp to now if not provided
if ts is None:
ts = pd.Timestamp.now().round("15min")

if isinstance(ts, str):
ts = datetime.fromisoformat(ts)

Expand Down
21 changes: 21 additions & 0 deletions tests/test_forecast_no_ts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import pandas as pd
from quartz_solar_forecast.forecast import run_forecast
from quartz_solar_forecast.pydantic_models import PVSite


def test_run_forecast_no_ts():
# make input data
site = PVSite(latitude=51.75, longitude=-1.25, capacity_kwp=1.25)

current_ts = pd.Timestamp.now().round("15min")

# run model with no ts
predications_df = run_forecast(site=site)

# check current ts agrees with dataset
assert predications_df.index.min() == current_ts

print(predications_df)
print(f"Current time: {current_ts}")
print(f"Max: {predications_df['power_wh'].max()}")

0 comments on commit 3308770

Please sign in to comment.