Skip to content

Commit

Permalink
Merge branch 'openclimatefix:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
utsav-pal authored Feb 18, 2025
2 parents c697fb0 + f800f70 commit 8fcb60a
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 10 deletions.
9 changes: 9 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@
"contributions": [
"code"
]
},
{
"login": "meghana-0211",
"name": "Meghana Sancheti",
"avatar_url": "https://avatars.githubusercontent.com/u/136890863?v=4",
"profile": "https://github.com/meghana-0211",
"contributions": [
"code"
]
}
],
"contributorsPerLine": 7,
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# pvnet_app
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-11-orange.svg?style=flat-square)](#contributors-)
[![All Contributors](https://img.shields.io/badge/all_contributors-12-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->

[![ease of contribution: hard](https://img.shields.io/badge/ease%20of%20contribution:%20hard-bb2629)](https://github.com/openclimatefix#how-easy-is-it-to-get-involved)
Expand Down Expand Up @@ -69,6 +69,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
<td align="center" valign="top" width="14.28%"><a href="https://github.com/Sukh-P"><img src="https://avatars.githubusercontent.com/u/42407101?v=4?s=100" width="100px;" alt="Sukhil Patel"/><br /><sub><b>Sukhil Patel</b></sub></a><br /><a href="https://github.com/openclimatefix/uk-pvnet-app/commits?author=Sukh-P" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/alirashidAR"><img src="https://avatars.githubusercontent.com/u/110668489?v=4?s=100" width="100px;" alt="Ali Rashid"/><br /><sub><b>Ali Rashid</b></sub></a><br /><a href="https://github.com/openclimatefix/uk-pvnet-app/commits?author=alirashidAR" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/mahmoud-40"><img src="https://avatars.githubusercontent.com/u/116794637?v=4?s=100" width="100px;" alt="Mahmoud Abdulmawlaa"/><br /><sub><b>Mahmoud Abdulmawlaa</b></sub></a><br /><a href="https://github.com/openclimatefix/uk-pvnet-app/commits?author=mahmoud-40" title="Code">💻</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/meghana-0211"><img src="https://avatars.githubusercontent.com/u/136890863?v=4?s=100" width="100px;" alt="Meghana Sancheti"/><br /><sub><b>Meghana Sancheti</b></sub></a><br /><a href="https://github.com/openclimatefix/uk-pvnet-app/commits?author=meghana-0211" title="Code">💻</a></td>
</tr>
</tbody>
</table>
Expand Down
15 changes: 6 additions & 9 deletions src/pvnet_app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

from pvnet_app.config import get_union_of_configs, save_yaml_config
from pvnet_app.data.nwp import download_all_nwp_data, preprocess_nwp_data
from pvnet_app.data.gsp import get_gsp_and_national_capacities
from pvnet_app.data.satellite import (
check_model_satellite_inputs_available,
download_all_sat_data,
Expand Down Expand Up @@ -164,15 +165,11 @@ def app(
logger.info("Loading capacities from the database")

db_connection = DatabaseConnection(url=os.getenv("DB_URL"), base=Base_Forecast, echo=False)
with db_connection.get_session() as session:
#  Pandas series of most recent GSP capacities
gsp_capacities = get_latest_gsp_capacities(
session=session, gsp_ids=gsp_ids, datetime_utc=t0 - timedelta(days=2),
)

# National capacity is needed if using summation model
national_capacity = get_latest_gsp_capacities(session, [0])[0]

gsp_capacities, national_capacity = get_gsp_and_national_capacities(
db_connection=db_connection,
gsp_ids=gsp_ids,
t0=t0,
)
# Download satellite data
logger.info("Downloading satellite data")
sat_available = download_all_sat_data()
Expand Down
37 changes: 37 additions & 0 deletions src/pvnet_app/data/gsp.py
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

0 comments on commit 8fcb60a

Please sign in to comment.