Skip to content

Commit

Permalink
use new function to laod gsp capacities
Browse files Browse the repository at this point in the history
  • Loading branch information
dfulu committed Nov 6, 2023
1 parent 4865e79 commit 3258ab0
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions pvnet_app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
get_model,
)
from nowcasting_datamodel.save.save import save as save_sql_forecasts
from nowcasting_datamodel.read.read_gsp get_latest_gsp_capacities
from nowcasting_datamodel.connection import DatabaseConnection
from nowcasting_datamodel.models.base import Base_Forecast
from ocf_datapipes.load import OpenGSPFromDatabase
from ocf_datapipes.training.pvnet import construct_sliced_data_pipeline
from ocf_datapipes.transform.numpy.batch.sun_position import ELEVATION_MEAN, ELEVATION_STD
Expand Down Expand Up @@ -319,23 +322,16 @@ def app(
logger.info("Loading GSP metadata")

ds_gsp = next(iter(OpenGSPFromDatabase()))

# DataArray of most recent GSP capacities
gsp_capacities = (
ds_gsp.sel(
time_utc=t0,
method="ffill",
)
.sel(gsp_id=gsp_ids)
.reset_coords()
.effective_capacity_mwp
)

# National capacity is needed if using summation model
ds_gsp_national = next(iter(OpenGSPFromDatabase(national_only=True)))
national_capacity = ds_gsp_national.sel(
time_utc=t0, method="ffill"
).effective_capacity_mwp.item()

# Get capacities from the database
url = os.getenv("DB_URL")
db_connection = DatabaseConnection(url=url, base=Base_Forecast)
with db_connection.get_session() as session:
# Pandas series of most recent GSP capacities
gsp_capacities = get_latest_gsp_capacities(session, gsp_ids)

# National capacity is needed if using summation model
national_capacity = sum(gsp_capacities)

# Set up ID location query object
gsp_id_to_loc = GSPLocationLookup(ds_gsp.x_osgb, ds_gsp.y_osgb)
Expand Down

0 comments on commit 3258ab0

Please sign in to comment.