-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #84 from roshnaeem/open-meteo
Accessing open-meteo dataset from AWS s3 using docker
- Loading branch information
Showing
4 changed files
with
90 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
OPEN_METEO_MODELS=ncep_gfs013 | ||
OPEN_METEO_VARIABLES=temperature_2m,precipitation,cloud_cover | ||
OPEN_METEO_MAX_AGE_DAYS=3 | ||
OPEN_METEO_REPEAT_INTERVAL=5 | ||
OPEN_METEO_CONCURRENT=4 |
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 |
---|---|---|
@@ -1,4 +1,3 @@ | ||
.env | ||
scripts/datapipes/test.nc | ||
scripts/datapipes/UK_PV_metadata.csv | ||
scripts/datapipes/nwp_data | ||
|
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,29 @@ | ||
version: '3.8' | ||
|
||
x-shared_environment: &shared_environment | ||
LOG_LEVEL: ${LOG_LEVEL:-info} | ||
|
||
services: | ||
open-meteo-api: | ||
image: ghcr.io/open-meteo/open-meteo | ||
container_name: open-meteo-api | ||
ports: | ||
- "8080:8080" | ||
command: serve | ||
volumes: | ||
- data:/app/data | ||
restart: always | ||
environment: | ||
<<: *shared_environment | ||
open-meteo-sync: | ||
image: ghcr.io/open-meteo/open-meteo | ||
container_name: open-meteo-sync | ||
command: sync ${OPEN_METEO_MODELS} ${OPEN_METEO_VARIABLES} --past-days ${OPEN_METEO_MAX_AGE_DAYS} --repeat-interval ${OPEN_METEO_REPEAT_INTERVAL} --concurrent ${OPEN_METEO_CONCURRENT} | ||
volumes: | ||
- data:/app/data | ||
restart: always | ||
environment: | ||
<<: *shared_environment | ||
|
||
volumes: | ||
data: |
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,56 @@ | ||
import requests | ||
import pandas as pd | ||
from datetime import datetime, timedelta | ||
import xarray as xr | ||
|
||
from quartz_solar_forecast.pydantic_models import PVSite | ||
|
||
def fetch_open_meteo_temperature(site: PVSite, ts: datetime): | ||
""" | ||
Fetch hourly temperature data from the local Open-Meteo API for a specific site. | ||
:param site: The PV site object containing latitude and longitude. | ||
:param ts: Timestamp for when the forecast is desired. | ||
:return: A Dataset with the requested weather data. | ||
""" | ||
|
||
variables = ['temperature_2m', 'precipitation', 'cloud_cover'] | ||
|
||
# Format the timestamp to a suitable string format for the API | ||
start_date = ts.strftime('%Y-%m-%d') | ||
end_date = (ts + timedelta(days=2)).strftime('%Y-%m-%d') | ||
|
||
# Construct the API URL | ||
api_url = ( | ||
f"http://127.0.0.1:8080/v1/forecast?latitude={site.latitude}&longitude={site.longitude}" | ||
f"&hourly={','.join(variables)}" | ||
f"&start_date={start_date}&end_date={end_date}" | ||
) | ||
|
||
try: | ||
response = requests.get(api_url) | ||
response.raise_for_status() | ||
data = response.json() | ||
|
||
df = pd.DataFrame({ | ||
'time': pd.to_datetime(data['hourly']['time']), | ||
'temperature_2m': data['hourly'].get('temperature_2m', [None] * len(data['hourly']['time'])), | ||
'precipitation': data['hourly'].get('precipitation', [None] * len(data['hourly']['time'])), | ||
'cloud_cover': data['hourly'].get('cloud_cover', [None] * len(data['hourly']['time'])) | ||
}).set_index('time') | ||
|
||
# Convert the DataFrame to an xarray Dataset | ||
data_xr = xr.Dataset.from_dataframe(df) | ||
|
||
return df | ||
|
||
except requests.RequestException as e: | ||
print(f"Request failed: {e}") | ||
return None | ||
|
||
|
||
# Example usage | ||
site = PVSite(latitude=47.1, longitude=8.4, capacity_kwp=1) | ||
ts = datetime.now() | ||
data = fetch_open_meteo_temperature(site, ts) | ||
print(data) |