Skip to content

Commit

Permalink
interpolate adjuster values before merging (#133)
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdudfield authored Nov 20, 2024
1 parent aea3f94 commit 16db043
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
15 changes: 12 additions & 3 deletions india_forecast_app/adjuster.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,18 @@ def get_me_values(
# drop the hour column
me_df.drop(columns=["horizon_hour"], inplace=True)

if len(me_df) == 0:
return me_df

# interpolate horizon_minutes up to 15 minutes blocks, its currently in 60 minute blocks
# currently in 0, 60, 120,...
# change to 0, 15, 30, 45, 60, 75, 90, 105, 120, ...
me_df = me_df.set_index("horizon_minutes")
me_df = me_df.reindex(range(0, max(me_df.index), 15)).interpolate(limit=3)

# reset indiex
me_df = me_df.reset_index()

return me_df


Expand Down Expand Up @@ -154,9 +166,6 @@ def adjust_forecast_with_adjuster(
me_values, on="horizon_minutes", how="left"
)

# interpolate nans with window limit of 3
forecast_values_df_adjust["me_kw"].interpolate(limit=3, inplace=True)

# if me_kw is null, set to 0
forecast_values_df_adjust["me_kw"].fillna(0, inplace=True)

Expand Down
4 changes: 4 additions & 0 deletions tests/test_adjuster.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ def test_get_me_values(db_session, sites, generation_db_values, forecasts):
me_df = get_me_values(db_session, hour, site_uuid=sites[0].site_uuid, ml_model_name="test")

assert len(me_df) != 0
assert len(me_df) == 96
assert me_df["me_kw"].sum() != 0
assert me_df["horizon_minutes"][0] == 0
assert me_df["horizon_minutes"][1] == 15


def test_get_me_values_no_generation(db_session, sites, forecasts):
Expand Down

0 comments on commit 16db043

Please sign in to comment.