Skip to content

Commit

Permalink
feat: update to sdk 1.4.0 naming
Browse files Browse the repository at this point in the history
  • Loading branch information
patrick-zippenfenig committed Oct 30, 2023
1 parent 8b63d76 commit b87ea4c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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()}")
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions openmeteo_requests/Client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"""
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
8 changes: 4 additions & 4 deletions tests/test_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand Down

0 comments on commit b87ea4c

Please sign in to comment.