Skip to content

Commit

Permalink
add windnet model (#155)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
peterdudfield authored Dec 17, 2024
1 parent 7ebb9e6 commit f294da0
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 10 deletions.
2 changes: 1 addition & 1 deletion india_forecast_app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
7 changes: 7 additions & 0 deletions india_forecast_app/models/all_models.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion india_forecast_app/models/pvnet/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 16 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/models/test_pydantic_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
2 changes: 1 addition & 1 deletion tests/test_adjuster.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
10 changes: 6 additions & 4 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f294da0

Please sign in to comment.