Skip to content

Commit

Permalink
add old pvnet main model back in.
Browse files Browse the repository at this point in the history
Add test to check it runs
  • Loading branch information
peterdudfield committed Oct 15, 2024
1 parent 855db76 commit 0e673ea
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 4 deletions.
14 changes: 13 additions & 1 deletion pvnet_app/model_configs/all_models.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,19 @@ models:
version: 4fe6b1441b6dd549292c201ed85eee156ecc220c
ecmwf_only: True
uses_satellite_data: False
# This is the old model for pvnet_ecmwf
# This is the old model for pvnet and pvnet_ecmwf
- name: pvnet_v2
pvnet:
repo: openclimatefix/pvnet_uk_region
version: 62e5e20ab793cee7cf94eadac870d2199501a730
summation:
repo: openclimatefix/pvnet_v2_summation
version: ffac655f9650b81865d96023baa15839f3ce26ec
use_adjuster: True
save_gsp_sum: False
verbose: True
save_gsp_to_recent: True
uses_ocf_data_sampler: False
- name: pvnet_ecmwf # this name is important as it used for blending
pvnet:
repo: openclimatefix/pvnet_uk_region
Expand Down
2 changes: 1 addition & 1 deletion tests/model_configs/test_pydantic_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_get_all_models_ocf_data_sampler():
assert len(models) == 5

models = get_all_models(use_ocf_data_sampler=False, run_extra_models=True)
assert len(models) == 1
assert len(models) == 2

models = get_all_models(use_ocf_data_sampler=False, run_extra_models=True, get_day_ahead_only=True)
assert len(models) == 1
Expand Down
73 changes: 71 additions & 2 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,15 @@ def test_app_day_ahead_model(

os.environ["DAY_AHEAD_MODEL"] = "True"
os.environ["RUN_EXTRA_MODELS"] = "False"
os.environ["USE_OCF_DATA_SAMPLER"] = "False"

# Run prediction
# Thes import needs to come after the environ vars have been set
from pvnet_app.app import app

app(gsp_ids=list(range(1, 318)), num_workers=2)

all_models = get_all_models(get_day_ahead_only=True)
all_models = get_all_models(get_day_ahead_only=True, use_ocf_data_sampler=False)

# Check correct number of forecasts have been made
# (317 GSPs + 1 National + maybe GSP-sum) = 318 or 319 forecasts
Expand Down Expand Up @@ -213,4 +214,72 @@ def test_app_no_sat(
expected_forecast_results += 317 * model_config.save_gsp_to_recent
expected_forecast_results += model_config.save_gsp_sum # optional Sum of GSPs

assert len(db_session.query(ForecastValueSevenDaysSQL).all()) == expected_forecast_results * 16
assert len(db_session.query(ForecastValueSevenDaysSQL).all()) == expected_forecast_results * 16


# test legacy models
# Its nice to have this here, so we can run the latest version in production, but still use the old models
# Once we have re trained PVnet summation models we can remove this
def test_app_ocf_datapipes(
db_session, nwp_ukv_data, nwp_ecmwf_data, sat_5_data, gsp_yields_and_systems, me_latest
):
"""Test the app running the day ahead model"""

with tempfile.TemporaryDirectory() as tmpdirname:
os.chdir(tmpdirname)

temp_nwp_path = "temp_nwp_ukv.zarr"
os.environ["NWP_UKV_ZARR_PATH"] = temp_nwp_path
nwp_ukv_data.to_zarr(temp_nwp_path)

temp_nwp_path = "temp_nwp_ecmwf.zarr"
os.environ["NWP_ECMWF_ZARR_PATH"] = temp_nwp_path
nwp_ecmwf_data.to_zarr(temp_nwp_path)

temp_sat_path = "temp_sat.zarr.zip"
os.environ["SATELLITE_ZARR_PATH"] = temp_sat_path
with zarr.storage.ZipStore(temp_sat_path, mode="x") as store:
sat_5_data.to_zarr(store)

os.environ["DAY_AHEAD_MODEL"] = "False"
os.environ["RUN_EXTRA_MODELS"] = "False"
os.environ["USE_OCF_DATA_SAMPLER"] = "False"

# Run prediction
# Thes import needs to come after the environ vars have been set
from pvnet_app.app import app

app(gsp_ids=list(range(1, 318)), num_workers=2)

all_models = get_all_models(use_ocf_data_sampler=False)

# Check correct number of forecasts have been made
# (317 GSPs + 1 National + maybe GSP-sum) = 318 or 319 forecasts
# Forecast made with multiple models
expected_forecast_results = 0
for model_config in all_models:
expected_forecast_results += 318 + model_config.save_gsp_sum

forecasts = db_session.query(ForecastSQL).all()
# Doubled for historic and forecast
assert len(forecasts) == expected_forecast_results * 2

# Check probabilistic added
assert "90" in forecasts[0].forecast_values[0].properties
assert "10" in forecasts[0].forecast_values[0].properties

# 72 time steps in forecast
expected_forecast_timesteps = 72

assert (
len(db_session.query(ForecastValueSQL).all())
== expected_forecast_results * expected_forecast_timesteps
)
assert (
len(db_session.query(ForecastValueLatestSQL).all())
== expected_forecast_results * expected_forecast_timesteps
)
assert (
len(db_session.query(ForecastValueSevenDaysSQL).all())
== expected_forecast_results * expected_forecast_timesteps
)

0 comments on commit 0e673ea

Please sign in to comment.