Skip to content

Commit

Permalink
Update/forecast run (#178)
Browse files Browse the repository at this point in the history
* move script to scripts, rm datasets

* add token

* add script description
  • Loading branch information
peterdudfield authored Aug 12, 2024
1 parent bee2850 commit e08afd0
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 35 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ jobs:
HF_TOKEN: ${{ secrets.HF_TOKEN_PUSH }}
HF_REPO: ${{ secrets.HF_REPO }}
run: |
python quartz_solar_forecast/utils/hf_upload.py
python scripts/hf_upload.py
9 changes: 9 additions & 0 deletions quartz_solar_forecast/utils/file_path.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from datetime import datetime


def get_file_path(latitude: float,
longitude: float,
capacity_kwp: float,
model: str = "gb",
time: datetime = None) -> str:
return time.strftime(f"data/%Y/%-m/%-d/{model}_{latitude}_{longitude}_{capacity_kwp}_%Y%m%d_%H.csv")
33 changes: 0 additions & 33 deletions quartz_solar_forecast/utils/hf_upload.py

This file was deleted.

35 changes: 35 additions & 0 deletions scripts/hf_upload.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
""" This script is used to run the forecast every day at 9am
Github actions runs this script every day at 9am to generate the forecast for the next 48 hours.
The results are saved to HF -
https://huggingface.co/openclimatefix/open-source-quartz-solar-forecast/tree/main/data
This means we can start to compare the difference between the forecasts and the actual generation.
"""

import os
from datetime import datetime
from huggingface_hub import login, HfFileSystem, HfApi
from quartz_solar_forecast.utils.forecast_csv import forecast_for_site
from quartz_solar_forecast.utils.file_path import get_file_path


if __name__ == "__main__":

hf_token = os.getenv("HF_TOKEN")
hf_repo = os.getenv("HF_REPO")
print(hf_repo)

login(hf_token)
fs = HfFileSystem(token=hf_token)
now = datetime.utcnow()
latitude = 51.59
longitude = -1.89
capacity_kwp = 4

for model in ["gb", "xgb"]:
forecast = forecast_for_site(latitude, longitude, capacity_kwp, model, now)

path = get_file_path(latitude, longitude, capacity_kwp, model, now)
with fs.open(f"{hf_repo}/{path}", "w") as f:
forecast.to_csv(path_or_buf=f)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from quartz_solar_forecast.utils.hf_upload import get_file_path
from quartz_solar_forecast.utils.file_path import get_file_path
from datetime import datetime


Expand Down

0 comments on commit e08afd0

Please sign in to comment.