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
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ 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 = [
# Keep core dependencies that are needed for the app to run
"xarray==2022.12.0",
"pv-site-prediction==0.1.19",
"pydantic==2.6.2",
"python-dotenv==1.0.1",
"openmeteo-requests==1.2.0",
Expand All @@ -27,7 +26,7 @@ dependencies = [
"pydantic_settings",
"httpx",
"sentry_sdk",
"huggingface_hub==0.17.3"
"huggingface_hub>=0.20.0"
]

[project.urls]
Expand All @@ -53,6 +52,7 @@ dev = [
"pytest",
]
inverters = ["ocf_vrmapi"] # victron
legacy = ["pv-site-prediction>=0.1.19"] # v1 models, requires Python <3.12
all = [
"ocf_vrmapi",
"streamlit",
Expand Down
15 changes: 13 additions & 2 deletions quartz_solar_forecast/eval/forecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@
from datetime import datetime

import pandas as pd
from psp.serialization import load_model

from quartz_solar_forecast.data import format_nwp_data, make_pv_data
from quartz_solar_forecast.forecasts.v1 import forecast_v1
from quartz_solar_forecast.pydantic_models import PVSite

try:
from psp.serialization import load_model
from quartz_solar_forecast.forecasts.v1 import forecast_v1
except ImportError:
load_model = None
forecast_v1 = None

dir_path = os.path.dirname(os.path.realpath(__file__))


Expand All @@ -29,6 +34,12 @@ def run_forecast(pv_df: pd.DataFrame, nwp_df: pd.DataFrame, nwp_source="ICON") -
maybe more
"""

if load_model is None or forecast_v1 is None:
raise ImportError(
"Evaluation requires pv-site-prediction. "
"Install with: pip install 'quartz-solar-forecast[legacy]' (requires Python <3.12)"
)

# load model only once
model = load_model(f"{dir_path}/../models/model-0.3.0.pkl")

Expand Down
6 changes: 6 additions & 0 deletions quartz_solar_forecast/forecast.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ def predict_ocf(
pv_xr = make_pv_data(site=site, ts=ts, live_generation=live_generation)

# load and run models
if forecast_v1_tilt_orientation is None:
raise ImportError(
"The 'gb' model requires pv-site-prediction which is not installed. "
"Install it with: pip install 'quartz-solar-forecast[legacy]' "
"(requires Python <3.12). Alternatively, use model='xgb'."
)
pred_df = forecast_v1_tilt_orientation(nwp_source, nwp_xr, pv_xr, ts, model=model)

# scale the results if the capacity is different
Expand Down
13 changes: 10 additions & 3 deletions quartz_solar_forecast/forecasts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@

This module contains different forecasting models for solar power prediction.
Different models are put in different files like:
- v1.py contains the v1 model
- v1.py contains the v1 model (requires pv-site-prediction, Python <3.12)
- v2.py contains the v2 model which was developed by Tryolabs
"""

from .v1 import forecast_v1
from .v1_tilt_orientation import forecast_v1_tilt_orientation
from .v2 import TryolabsSolarPowerPredictor

# v1 models depend on pv-site-prediction which requires Python <3.12
# and fsspec<2023.0.0. Import them lazily to avoid breaking on Python 3.12.
try:
from .v1 import forecast_v1
from .v1_tilt_orientation import forecast_v1_tilt_orientation
except ImportError:
forecast_v1 = None
forecast_v1_tilt_orientation = None

__all__ = ["forecast_v1", "forecast_v1_tilt_orientation", "TryolabsSolarPowerPredictor"]
7 changes: 3 additions & 4 deletions quartz_solar_forecast/utils/sentry_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

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 All @@ -14,13 +16,10 @@
)

SENTRY_DSN = "https://b2b6f3c97299f81464bc16ad0d516d0b@o400768.ingest.us.sentry.io/4508439933157376"

# Disable default integrations to prevent incompatible huggingface_hub integration
# from causing AttributeError with older huggingface_hub versions
sentry_sdk.init(
dsn=SENTRY_DSN,
traces_sample_rate=1.0,
default_integrations=False,
disabled_integrations=[HuggingfaceHubIntegration],
)


Expand Down
Loading