diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index bd4416cf..f7febe49 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -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 diff --git a/quartz_solar_forecast/utils/file_path.py b/quartz_solar_forecast/utils/file_path.py new file mode 100644 index 00000000..3f4e1e45 --- /dev/null +++ b/quartz_solar_forecast/utils/file_path.py @@ -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") diff --git a/quartz_solar_forecast/utils/hf_upload.py b/quartz_solar_forecast/utils/hf_upload.py deleted file mode 100644 index 73b7fecc..00000000 --- a/quartz_solar_forecast/utils/hf_upload.py +++ /dev/null @@ -1,33 +0,0 @@ -import os -from datetime import datetime -from huggingface_hub import login, HfFileSystem -from quartz_solar_forecast.utils.forecast_csv import forecast_for_site - - -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") - - -if __name__ == "__main__": - - hf_token = os.getenv("HF_TOKEN") - hf_repo = os.getenv("HF_REPO") - print(hf_repo) - - login(hf_token) - fs = HfFileSystem() - 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"datasets/{hf_repo}/{path}", "w") as f: - forecast.to_csv(path_or_buf=f) diff --git a/scripts/hf_upload.py b/scripts/hf_upload.py new file mode 100644 index 00000000..f04eb634 --- /dev/null +++ b/scripts/hf_upload.py @@ -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) diff --git a/tests/utils/test_hf_upload.py b/tests/utils/test_file_path.py similarity index 83% rename from tests/utils/test_hf_upload.py rename to tests/utils/test_file_path.py index d266c17e..50d5a50b 100644 --- a/tests/utils/test_hf_upload.py +++ b/tests/utils/test_file_path.py @@ -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