Skip to content
Open
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
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ dynamic = ["version"]
description = "Open Source Solar Forecasting for a Site"
authors = [{ name = "Peter Dudfield", email = "info@openclimatefix.org" }]
readme = "README.md"
requires-python = ">=3.11"
requires-python = ">=3.11,<3.13"
license = { text = "MIT" }

dependencies = [
Expand All @@ -27,7 +27,7 @@ dependencies = [
"pydantic_settings",
"httpx",
"sentry_sdk",
"huggingface_hub==0.17.3"
"huggingface_hub==0.21.4"
]

[project.urls]
Expand Down
24 changes: 8 additions & 16 deletions quartz_solar_forecast/forecasts/v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import pandas as pd
from huggingface_hub import hf_hub_download
from xgboost.sklearn import XGBRegressor
import xgboost as xgb

import quartz_solar_forecast
from quartz_solar_forecast.weather import WeatherService
Expand Down Expand Up @@ -91,7 +92,7 @@ def _decompress_zipfile(self, filename: str) -> None:

def load_model(
self,
model_file: str = constants.MODEL_FILE,
model_file: str = "model_10_202405.ubj",
repo_id: str = "openclimatefix/open-source-quartz-solar-forecast",
file_path: str = "models/v2/model_10_202405.ubj.zip",
) -> XGBRegressor:
Expand All @@ -115,21 +116,13 @@ def load_model(
XGBRegressor
The loaded XGBoost model ready for making predictions.
"""
# Use the project directory
zipfile_model = os.path.join(self.download_dir, model_file + ".zip")

if not os.path.isfile(zipfile_model):
logger.info("Downloading model...")
zipfile_model = self._download_model(model_file + ".zip", repo_id, file_path)

model_path = os.path.join(self.download_dir, model_file)
if not os.path.isfile(model_path):
logger.info("Preparing model...")
self._decompress_zipfile(zipfile_model)

logger.info("Loading model...")
loaded_model = XGBRegressor()
logger.info(f"Loading Raw Booster from {model_path}...")
loaded_model = xgb.Booster()
loaded_model.load_model(model_path)
loaded_model._estimator_type = "regressor"
self.model = loaded_model
return loaded_model

Expand Down Expand Up @@ -260,14 +253,13 @@ def predict_power_output(
"""

data = self.get_data(latitude, longitude, start_date, kwp, orientation, tilt)
# if data is not None:
cleaned_data = self.clean(data)
predictions = self.model.predict(cleaned_data.drop(columns=[self.DATE_COLUMN]))
X = cleaned_data.drop(columns=[self.DATE_COLUMN])
dmatrix = xgb.DMatrix(X)
predictions = self.model.predict(dmatrix)
predictions_df = pd.DataFrame(predictions, columns=["prediction"])
final_data = cleaned_data.join(predictions_df)
# set night predictions to 0
final_data.loc[final_data["is_day"] == 0, "prediction"] = 0
# set negative output to 0
final_data.loc[final_data["prediction"] < 0, "prediction"] = 0
df = final_data[[self.DATE_COLUMN, "prediction"]]
df = df.rename(columns={"prediction": "power_kw"})
Expand Down
6 changes: 3 additions & 3 deletions quartz_solar_forecast/utils/sentry_logging.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""Log usage of this package to Sentry"""

import importlib.metadata
import os

import sentry_sdk

from sentry_sdk.integrations.huggingface_hub import HuggingfaceHubIntegration

from quartz_solar_forecast.pydantic_models import PVSite

version = importlib.metadata.version("quartz_solar_forecast")
Expand Down Expand Up @@ -47,4 +47,4 @@ def write_sentry(params):
sentry_sdk.set_tag("version", version)

except Exception as _: # noqa
pass
pass
4 changes: 2 additions & 2 deletions quartz_solar_forecast/weather/open_meteo.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,8 @@
except ValueError as e:
raise ValueError(
f"Invalid date format. Please use YYYY-MM-DD format. Error: {str(e)}"
) from e


if not (end_datetime > start_datetime):

Check failure on line 102 in quartz_solar_forecast/weather/open_meteo.py

View workflow job for this annotation

GitHub Actions / branch_ci / lint-typecheck

Ruff (W293)

quartz_solar_forecast/weather/open_meteo.py:102:1: W293 Blank line contains whitespace
raise ValueError(
f"Invalid date range. End date ({end_date}) must be greater than "
f"start date ({start_date})."
Expand Down Expand Up @@ -166,6 +165,7 @@
except requests.exceptions.Timeout as e:
raise TimeoutError(f"Request to OpenMeteo API timed out. URl - {url}") from e

# Process the hourly data
hourly = response[0].Hourly()
hourly_data = {
"time": pd.date_range(
Expand Down
Loading