diff --git a/README.md b/README.md index 4e8d30b..5aec993 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,7 @@ params = { "current": ["temperature_2m"] } -responses = om.get("https://api.open-meteo.com/v1/forecast", params=params) +responses = om.weather_api("https://api.open-meteo.com/v1/forecast", params=params) response = responses[0] print(f"Coordinates {response.Latitude()}°E {response.Longitude()}°N") print(f"Elevation {response.Elevation()} m asl") @@ -33,9 +33,9 @@ print(f"Timezone difference to GMT+0 {response.UtcOffsetSeconds()} s") # Current values current = response.Current() -current_series = list(map(lambda i: current.Series(i), range(0, current.SeriesLength()))) -current_temperature_2m = next(filter(lambda x: x.Variable() == Variable.temperature and x.Altitude() == 2, current_series)) -current_relative_humidity_2m = next(filter(lambda x: x.Variable() == Variable.relative_humidity and x.Altitude() == 2, current_series)) +current_variables = list(map(lambda i: current.Variables(i), range(0, current.VariablesLength()))) +current_temperature_2m = next(filter(lambda x: x.Variable() == Variable.temperature and x.Altitude() == 2, current_variables)) +current_relative_humidity_2m = next(filter(lambda x: x.Variable() == Variable.relative_humidity and x.Altitude() == 2, current_variables)) print(f"Current time {current.Time()}") print(f"Current temperature_2m {current_temperature_2m.Value()}") @@ -55,11 +55,11 @@ import numpy as np hourly = response.Hourly() hourly_time = range(hourly.Time(), hourly.TimeEnd(), hourly.Interval()) -hourly_series = list(map(lambda i: hourly.Series(i), range(0, hourly.SeriesLength()))) +hourly_variables = list(map(lambda i: hourly.Variables(i), range(0, hourly.VariablesLength()))) -hourly_temperature_2m = next(filter(lambda x: x.Variable() == Variable.temperature and x.Altitude() == 2, hourly_series)).ValuesAsNumpy() -hourly_precipitation = next(filter(lambda x: x.Variable() == Variable.precipitation, hourly_series)).ValuesAsNumpy() -hourly_wind_speed_10m = next(filter(lambda x: x.Variable() == Variable.wind_speed and x.Altitude() == 10, hourly_series)).ValuesAsNumpy() +hourly_temperature_2m = next(filter(lambda x: x.Variable() == Variable.temperature and x.Altitude() == 2, hourly_variables)).ValuesAsNumpy() +hourly_precipitation = next(filter(lambda x: x.Variable() == Variable.precipitation, hourly_variables)).ValuesAsNumpy() +hourly_wind_speed_10m = next(filter(lambda x: x.Variable() == Variable.wind_speed and x.Altitude() == 10, hourly_variables)).ValuesAsNumpy() ``` ### Pandas diff --git a/openmeteo_requests/Client.py b/openmeteo_requests/Client.py index 43b6d9b..a7f8425 100644 --- a/openmeteo_requests/Client.py +++ b/openmeteo_requests/Client.py @@ -5,7 +5,7 @@ from typing import TypeVar import requests -from openmeteo_sdk.ApiResponse import ApiResponse +from openmeteo_sdk.WeatherApiResponse import WeatherApiResponse T = TypeVar("T") TSession = TypeVar("TSession", bound=requests.Session) @@ -42,9 +42,9 @@ def _get(self, cls: type[T], url: str, params: any) -> list[T]: pos += length + 4 return messages - def get(self, url: str, params: any) -> list[ApiResponse]: + def weather_api(self, url: str, params: any) -> list[WeatherApiResponse]: """Get and decode as weather api""" - return self._get(ApiResponse, url, params) + return self._get(WeatherApiResponse, url, params) def __del__(self): """cleanup""" diff --git a/pyproject.toml b/pyproject.toml index 2b5d614..c1f2d89 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,7 +19,7 @@ classifiers = [ "Programming Language :: Python :: 3.11", ] requires-python = ">=3.8.1" -dependencies = ["openmeteo_sdk>=1.3.0", "requests"] +dependencies = ["openmeteo_sdk>=1.4.0", "requests"] [project.optional-dependencies] spark = ["pyspark>=3.0.0"] diff --git a/tests/test_methods.py b/tests/test_methods.py index 22083fa..ac3a8d2 100644 --- a/tests/test_methods.py +++ b/tests/test_methods.py @@ -20,7 +20,7 @@ def test_fetch_all(): # 'current_weather': 1, } - responses = om.get("https://archive-api.open-meteo.com/v1/archive", params=params) + responses = om.weather_api("https://archive-api.open-meteo.com/v1/archive", params=params) # responses = om.get("http://127.0.0.1:8080/v1/archive", params=params) assert len(responses) == 3 response = responses[0] @@ -36,10 +36,10 @@ def test_fetch_all(): print(f"Generation time {response.GenerationTimeMilliseconds()} ms") hourly = response.Hourly() - hourly_series = list(map(lambda i: hourly.Series(i), range(0, hourly.SeriesLength()))) + hourly_variables = list(map(lambda i: hourly.Variables(i), range(0, hourly.VariablesLength()))) - temperature_2m = next(filter(lambda x: x.Variable() == Variable.temperature and x.Altitude() == 2, hourly_series)) - precipitation = next(filter(lambda x: x.Variable() == Variable.precipitation, hourly_series)) + temperature_2m = next(filter(lambda x: x.Variable() == Variable.temperature and x.Altitude() == 2, hourly_variables)) + precipitation = next(filter(lambda x: x.Variable() == Variable.precipitation, hourly_variables)) assert temperature_2m.ValuesLength() == 48 assert precipitation.ValuesLength() == 48