From 01384941daed7875a921851f6552e159580d00c6 Mon Sep 17 00:00:00 2001 From: Peter Dudfield <34686298+peterdudfield@users.noreply.github.com> Date: Fri, 20 Dec 2024 13:28:18 +0000 Subject: [PATCH 1/4] add new wind model (#160) * add new wind model * update tests * mask wind t0 idx, for windnet_ad_sites_generation_delay model * lint * fix --- india_forecast_app/models/all_models.yaml | 7 +++++++ india_forecast_app/models/pvnet/model.py | 13 +++++++++++-- tests/models/test_pydantic_models.py | 2 +- tests/test_app.py | 8 ++++---- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/india_forecast_app/models/all_models.yaml b/india_forecast_app/models/all_models.yaml index 29d8f36..96cf09d 100644 --- a/india_forecast_app/models/all_models.yaml +++ b/india_forecast_app/models/all_models.yaml @@ -54,6 +54,13 @@ models: client: ad asset_type: wind adjuster_average_minutes: 15 + - name: windnet_ad_sites_generation_delay + type: pvnet + id: openclimatefix/windnet_ad_sites + version: bced479c5c3ab198bfce7d5cb4e02f8679be3297 + 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 6a1e38a..a529cb2 100644 --- a/india_forecast_app/models/pvnet/model.py +++ b/india_forecast_app/models/pvnet/model.py @@ -11,7 +11,12 @@ import numpy as np import pandas as pd import torch -from ocf_datapipes.batch import batch_to_tensor, copy_batch_to_device, stack_np_examples_into_batch +from ocf_datapipes.batch import ( + BatchKey, + batch_to_tensor, + copy_batch_to_device, + stack_np_examples_into_batch, +) from ocf_datapipes.training.pvnet_site import construct_sliced_data_pipeline as pv_base_pipeline from ocf_datapipes.training.windnet import DictDatasetIterDataPipe, split_dataset_dict_dp from ocf_datapipes.training.windnet import construct_sliced_data_pipeline as wind_base_pipeline @@ -95,6 +100,10 @@ def predict(self, site_id: str, timestamp: dt.datetime): for i, batch in enumerate(self.dataloader): log.info(f"Predicting for batch: {i}") + if self.name == "windnet_ad_sites_generation_delay": + # this is a bit of hack, but it's important to do what was done in training + batch[BatchKey.wind][:, int(batch[BatchKey.wind_t0_idx])] = -1 + # save batch save_batch(batch=batch, i=i, model_name=self.name, site_uuid=self.site_uuid) @@ -242,7 +251,7 @@ def _prepare_data_sources(self): source_nwp_path=os.environ["NWP_MO_GLOBAL_ZARR_PATH"], dest_nwp_path=nwp_mo_global_path, source="mo_global", - config=self.config["input_data"]["nwp"]["mo_global"] + config=self.config["input_data"]["nwp"]["mo_global"], ) ) diff --git a/tests/models/test_pydantic_models.py b/tests/models/test_pydantic_models.py index 73b61be..3f23330 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) == 9 + assert len(models.models) == 10 def test_get_all_models_client(): diff --git a/tests/test_app.py b/tests/test_app.py index eb23218..9623732 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -210,13 +210,13 @@ def test_app_client_ad( app_run(timestamp=None, write_to_db=True) - # 2 pv models, 1 wind model + # 2 pv models, 2 wind model # x2 for adjuster - n_forecasts = 3 * 2 - # one models is 8 hours, two model is 4 hours + n_forecasts = 4 * 2 + # one models is 8 hours, three model is 4 hours # x 4 for each 15 minutes # x 2 for adjuster - n_forecast_values = (8 + 4 + 4) * 4 * 2 + n_forecast_values = (8 + 4 + 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 From 008df41c6952af2c8c550cdf843657051363aa4f Mon Sep 17 00:00:00 2001 From: BumpVersion Action Date: Fri, 20 Dec 2024 13:33:53 +0000 Subject: [PATCH 2/4] =?UTF-8?q?Bump=20version:=201.1.25=20=E2=86=92=201.1.?= =?UTF-8?q?26=20[ci=20skip]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .bumpversion.cfg | 2 +- india_forecast_app/__init__.py | 2 +- pyproject.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 54fccb3..7455935 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 1.1.25 +current_version = 1.1.26 commit = True tag = True message = Bump version: {current_version} → {new_version} [ci skip] diff --git a/india_forecast_app/__init__.py b/india_forecast_app/__init__.py index 77f5c58..c0f8577 100644 --- a/india_forecast_app/__init__.py +++ b/india_forecast_app/__init__.py @@ -1,2 +1,2 @@ """India Forecast App""" -__version__ = "1.1.25" +__version__ = "1.1.26" diff --git a/pyproject.toml b/pyproject.toml index beba6be..fd5b87e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "india_forecast_app" -version = "1.1.25" +version = "1.1.26" description = "Runs wind and PV forecasts for India and saves to database" authors = ["Chris Briggs "] readme = "README.md" From 661eb3e99e77b33112b5ecf86dc820e5773e1806 Mon Sep 17 00:00:00 2001 From: Peter Dudfield <34686298+peterdudfield@users.noreply.github.com> Date: Sat, 28 Dec 2024 10:45:27 +0000 Subject: [PATCH 3/4] Fix no generation (#161) * fix if no generation data * fix --- india_forecast_app/models/pvnet/model.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/india_forecast_app/models/pvnet/model.py b/india_forecast_app/models/pvnet/model.py index a529cb2..63dcc0c 100644 --- a/india_forecast_app/models/pvnet/model.py +++ b/india_forecast_app/models/pvnet/model.py @@ -273,7 +273,10 @@ def _prepare_data_sources(self): generation_da = self.generation_data["data"].to_xarray() # get the minimum timestamp in generation data - min_timestamp = generation_da.index.min().values + if len(generation_da.index) > 0: + min_timestamp = generation_da.index.min().values + else: + min_timestamp = self.t0 - pd.Timedelta(hours=24) # Add the forecast timesteps to the generation, with 0 values # 192 is 48 hours of 15 min intervals forecast_timesteps = pd.date_range( From 98056118202d8139005af098ec62a12743bd04dd Mon Sep 17 00:00:00 2001 From: BumpVersion Action Date: Sat, 28 Dec 2024 10:50:42 +0000 Subject: [PATCH 4/4] =?UTF-8?q?Bump=20version:=201.1.26=20=E2=86=92=201.1.?= =?UTF-8?q?27=20[ci=20skip]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .bumpversion.cfg | 2 +- india_forecast_app/__init__.py | 2 +- pyproject.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 7455935..fa01156 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 1.1.26 +current_version = 1.1.27 commit = True tag = True message = Bump version: {current_version} → {new_version} [ci skip] diff --git a/india_forecast_app/__init__.py b/india_forecast_app/__init__.py index c0f8577..d3ad067 100644 --- a/india_forecast_app/__init__.py +++ b/india_forecast_app/__init__.py @@ -1,2 +1,2 @@ """India Forecast App""" -__version__ = "1.1.26" +__version__ = "1.1.27" diff --git a/pyproject.toml b/pyproject.toml index fd5b87e..91dc56d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "india_forecast_app" -version = "1.1.26" +version = "1.1.27" description = "Runs wind and PV forecasts for India and saves to database" authors = ["Chris Briggs "] readme = "README.md"