diff --git a/pvnet_app/model_configs/all_models.yaml b/pvnet_app/model_configs/all_models.yaml index 988b4e5..7d87a2f 100644 --- a/pvnet_app/model_configs/all_models.yaml +++ b/pvnet_app/model_configs/all_models.yaml @@ -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 diff --git a/tests/model_configs/test_pydantic_models.py b/tests/model_configs/test_pydantic_models.py index e21f23a..327a3e3 100644 --- a/tests/model_configs/test_pydantic_models.py +++ b/tests/model_configs/test_pydantic_models.py @@ -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 diff --git a/tests/test_app.py b/tests/test_app.py index 797a3cd..3746c47 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -111,6 +111,7 @@ 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 @@ -118,7 +119,7 @@ def test_app_day_ahead_model( 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 @@ -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 \ No newline at end of file + 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 + ) \ No newline at end of file