Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue/ml #108

Merged
merged 16 commits into from
Oct 23, 2024
9 changes: 5 additions & 4 deletions india_forecast_app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ def get_generation_data(
generation_data = get_pv_generation_by_sites(
session=db_session, site_uuids=site_uuids, start_utc=start, end_utc=end
)
# hard code as for the moment
system_id = int(0.0)
# get the ml id, this only works for one site right now
system_id = sites[0].ml_id

if len(generation_data) == 0:
log.warning("No generation found for the specified sites/period")
generation_df = pd.DataFrame()
generation_df = pd.DataFrame(columns=[str(system_id)])

else:
# Convert to dataframe
Expand Down Expand Up @@ -272,7 +272,8 @@ def app_click(timestamp: dt.datetime | None, write_to_db: bool, log_level: str):
Main click function for running forecasts for sites in India
"""

app(timestamp, write_to_db, log_level)
app(timestamp=timestamp, write_to_db=write_to_db, log_level=log_level)


def app(timestamp: dt.datetime | None, write_to_db: bool=False, log_level: str="info"):
"""
Expand Down
14 changes: 10 additions & 4 deletions india_forecast_app/models/pvnet/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def __init__(
generation_data: dict[str, pd.DataFrame],
hf_repo: str,
hf_version: str,
name: str
name: str,
):
"""Initializer for the model"""

Expand Down Expand Up @@ -131,6 +131,7 @@ def predict(self, site_id: str, timestamp: dt.datetime):
log.info("Feathering the forecast to the lastest value of generation")

# Feather in the last generation, if it exists
system_id = str(self.generation_data["data"].columns[0])
generation_da = self.generation_data["data"].to_xarray()

# Check if the generation exists, if so, take the value at t0 and
Expand All @@ -139,7 +140,8 @@ def predict(self, site_id: str, timestamp: dt.datetime):
final_gen_points = 0
final_gen_index = 0
for gen_idx in range(len(generation_da.index.values) - 1, -1, -1):
current_gen = generation_da.isel(index=gen_idx)["0"].values
current_gen = generation_da.isel(index=gen_idx)
current_gen = current_gen[system_id].values
if not np.isnan(current_gen) and current_gen > 0:
final_gen_points = current_gen * 1000.0
# Convert to KW back from MW
Expand Down Expand Up @@ -241,7 +243,10 @@ def _prepare_data_sources(self):

# if generation_da is still empty make nans
if len(generation_da) == 0:
generation_df = pd.DataFrame(index=forecast_timesteps, columns=["0"], data=0.0001)
cols = [str(col) for col in self.generation_data["data"].columns]
generation_df = pd.DataFrame(
index=forecast_timesteps, columns=cols, data=0.0001
)
generation_da = generation_df.to_xarray()
generation_da.to_netcdf(wind_netcdf_path, engine="h5netcdf")

Expand Down Expand Up @@ -271,7 +276,8 @@ def _prepare_data_sources(self):

# if generation_da is still empty make nans
if len(generation_da) == 0:
generation_df = pd.DataFrame(index=forecast_timesteps, columns=["0"], data=0.0001)
cols = [str(col) for col in self.generation_data["data"].columns]
generation_df = pd.DataFrame(index=forecast_timesteps, columns=cols, data=0.0001)
generation_da = generation_df.to_xarray()
generation_da.to_netcdf(pv_netcdf_path, engine="h5netcdf")

Expand Down
Loading