generated from openclimatefix/ocf-template
-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'openclimatefix:main' into main
- Loading branch information
Showing
4 changed files
with
54 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from datetime import timedelta | ||
from typing import Tuple | ||
|
||
import pandas as pd | ||
from nowcasting_datamodel.connection import DatabaseConnection | ||
from nowcasting_datamodel.read.read_gsp import get_latest_gsp_capacities | ||
from nowcasting_datamodel.models.base import Base_Forecast | ||
|
||
def get_gsp_and_national_capacities( | ||
db_connection: DatabaseConnection, | ||
gsp_ids: list[int], | ||
t0: pd.Timestamp, | ||
) -> Tuple[pd.Series, float]: | ||
"""Get GSP and national capacities from the database. | ||
Args: | ||
db_connection: Database connection object | ||
gsp_ids: List of GSP IDs to get capacities for | ||
t0: Reference timestamp for getting capacities | ||
Returns: | ||
Tuple containing: | ||
- Pandas series of most recent GSP capacities | ||
- National capacity value | ||
""" | ||
with db_connection.get_session() as session: | ||
# Get GSP capacities | ||
gsp_capacities = get_latest_gsp_capacities( | ||
session=session, | ||
gsp_ids=gsp_ids, | ||
datetime_utc=t0 - timedelta(days=2), | ||
) | ||
|
||
# Get national capacity (needed if using summation model) | ||
national_capacity = get_latest_gsp_capacities(session, [0])[0] | ||
|
||
return gsp_capacities, national_capacity |