From f294da02cd4ac12123c980f1b6391523ac0262ce Mon Sep 17 00:00:00 2001 From: Peter Dudfield <34686298+peterdudfield@users.noreply.github.com> Date: Tue, 17 Dec 2024 11:26:58 +0000 Subject: [PATCH] add windnet model (#155) * add windnet model * update test * and wind site * update ml id * windnet new version 8f1fd4322f6618b74dd718d50ff2d64ffec8e8fb * fix for generation test * get 25 hours of historic data * add 24 hours of wind readings * make 25 hours of wind readings * create more wind data * fix for windnet ad * reduce generation data --- india_forecast_app/app.py | 2 +- india_forecast_app/models/all_models.yaml | 7 +++++++ india_forecast_app/models/pvnet/model.py | 6 +++++- tests/conftest.py | 18 ++++++++++++++++-- tests/models/test_pydantic_models.py | 2 +- tests/test_adjuster.py | 2 +- tests/test_app.py | 10 ++++++---- 7 files changed, 37 insertions(+), 10 deletions(-) diff --git a/india_forecast_app/app.py b/india_forecast_app/app.py index 9889e4f..670474f 100644 --- a/india_forecast_app/app.py +++ b/india_forecast_app/app.py @@ -77,7 +77,7 @@ def get_generation_data( if client == "ruvnl": start = timestamp - dt.timedelta(hours=1) elif client == "ad": - start = timestamp - dt.timedelta(hours=3) + start = timestamp - dt.timedelta(hours=25) # pad by 1 second to ensure get_pv_generation_by_sites returns correct data end = timestamp + dt.timedelta(seconds=1) diff --git a/india_forecast_app/models/all_models.yaml b/india_forecast_app/models/all_models.yaml index a41f232..29d8f36 100644 --- a/india_forecast_app/models/all_models.yaml +++ b/india_forecast_app/models/all_models.yaml @@ -47,6 +47,13 @@ models: client: ad asset_type: pv adjuster_average_minutes: 15 + - name: windnet_ad_sites + type: pvnet + id: openclimatefix/windnet_ad_sites + version: 8f1fd4322f6618b74dd718d50ff2d64ffec8e8fb + client: ad + asset_type: wind + adjuster_average_minutes: 15 # this is just a dummy one - name: dummy type: dummy diff --git a/india_forecast_app/models/pvnet/model.py b/india_forecast_app/models/pvnet/model.py index 829eb55..2701a11 100644 --- a/india_forecast_app/models/pvnet/model.py +++ b/india_forecast_app/models/pvnet/model.py @@ -263,9 +263,13 @@ def _prepare_data_sources(self): # Save generation data as netcdf file generation_da = self.generation_data["data"].to_xarray() + + # get the minimum timestamp in generation data + min_timestamp = generation_da.index.min().values # Add the forecast timesteps to the generation, with 0 values + # 192 is 48 hours of 15 min intervals forecast_timesteps = pd.date_range( - start=self.t0 - pd.Timedelta("1H"), periods=197, freq="15min" + start=min_timestamp, periods=len(generation_da.index) + 192, freq="15min" ) generation_da = generation_da.reindex(index=forecast_timesteps, fill_value=0.00001) diff --git a/tests/conftest.py b/tests/conftest.py index e3f6470..8291877 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -111,6 +111,20 @@ def sites(db_session): db_session.add(site) sites.append(site) + # Ad wind site + site = SiteSQL( + client_site_id=3, + client_site_name="test_site_ad_wind", + latitude=26.4199, + longitude=72.6699, + capacity_kw=25000, + ml_id=3, + asset_type="wind", + country="india", + ) + db_session.add(site) + sites.append(site) + db_session.commit() return sites @@ -120,7 +134,7 @@ def sites(db_session): def generation_db_values(db_session, sites, init_timestamp): """Create some fake generations""" - n = 100 # 5 hours of readings + n = 450 # 22.5 hours of readings start_times = [init_timestamp - dt.timedelta(minutes=x * 3) for x in range(n)] # remove some of the most recent readings (to simulate missing timestamps) @@ -152,7 +166,7 @@ def generation_db_values(db_session, sites, init_timestamp): def generation_db_values_only_wind(db_session, sites, init_timestamp): """Create some fake generations""" - n = 100 # 5 hours of readings + n = 20*25 # 25 hours of readings start_times = [init_timestamp - dt.timedelta(minutes=x * 3) for x in range(n)] # remove some of the most recent readings (to simulate missing timestamps) diff --git a/tests/models/test_pydantic_models.py b/tests/models/test_pydantic_models.py index 670ee9c..73b61be 100644 --- a/tests/models/test_pydantic_models.py +++ b/tests/models/test_pydantic_models.py @@ -5,7 +5,7 @@ def test_get_all_models(): """Test for getting all models""" models = get_all_models() - assert len(models.models) == 8 + assert len(models.models) == 9 def test_get_all_models_client(): diff --git a/tests/test_adjuster.py b/tests/test_adjuster.py index e463592..50a6859 100644 --- a/tests/test_adjuster.py +++ b/tests/test_adjuster.py @@ -94,7 +94,7 @@ def test_adjust_forecast_with_adjuster(db_session, sites, generation_db_values, assert len(forecast_values_df) == 5 assert forecast_values_df["forecast_power_kw"][0:4].sum() == 10 assert forecast_values_df["forecast_power_kw"][4] != 5 - # note the way the tests are setup, only the horizon_minutes=1200 has some ME values + # note the way the tests are setup, only the horizon_minutes=90 has some ME values def test_adjust_forecast_with_adjuster_no_values(db_session, sites): diff --git a/tests/test_app.py b/tests/test_app.py index 08c4653..eb23218 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -45,7 +45,7 @@ def test_get_generation_data(db_session, sites, generation_db_values, init_times """Test for correct generation data""" # Test only checks for wind data as solar data not ready yet - gen_sites = [s for s in sites if s.asset_type == SiteAssetType.wind] # 1 site + gen_sites = [s for s in sites if s.asset_type == SiteAssetType.wind][0:1] # 1 site gen_data = get_generation_data(db_session, gen_sites, timestamp=init_timestamp) gen_df, gen_meta = gen_data["data"], gen_data["metadata"] @@ -210,11 +210,13 @@ def test_app_client_ad( app_run(timestamp=None, write_to_db=True) - n_forecasts = 2 * 2 - # one model is 8 hours, one model is 4 hours + # 2 pv models, 1 wind model + # x2 for adjuster + n_forecasts = 3 * 2 + # one models is 8 hours, two model is 4 hours # x 4 for each 15 minutes # x 2 for adjuster - n_forecast_values = (8 + 4) * 4 * 2 + n_forecast_values = (8 + 4 + 4) * 4 * 2 assert db_session.query(ForecastSQL).count() == init_n_forecasts + n_forecasts assert db_session.query(ForecastValueSQL).count() == init_n_forecast_values + n_forecast_values