dwdweather2 icon indicating copy to clipboard operation
dwdweather2 copied to clipboard

Object-oriented library interface

Open amotl opened this issue 5 years ago • 1 comments

@JohannesRol follows a more object-oriented library interface approach with his dwdopendata package. There, you will create a location object from a factory function obtaining the geolocation and subsequently be able to invoke appropriate methods on that object for acquiring actual weather information.

We like that approach, so it would be nice to see a similar interface here.


Original example

import dwdopendata as dwd

# Acquire location object from coordinates of nearest station.
location = dwd.location(51.898, 8.9876)

# Acquire wind speed data for specific location and time range from specified resolution dataset.
wind_speed = location.wind('2019-05-01T00:00:00', '2019-05-02T00:00:00', '10min')

amotl avatar Jun 03 '19 16:06 amotl

Another proposal

from dwdweather import DwdWeather

# Create main application object with given resolution dataset.
dwd = DwdWeather(resolution='10_minutes')

# Acquire station object by looking up nearest station by given coordinates.
station = dwd.nearest_station(latitude=51.898, longitude=8.9876)

# Acquire wind speed data for specific location and time range.
wind_speed = station.wind(dtstart='2019-05-01T00:00:00', dtend='2019-05-02T00:00:00')

Rationale

As finding the appropriate station depends on the resolution dataset (hourly, 10_minutes, etc.), this information must be available to the machinery before performing any station lookup.

amotl avatar Jun 03 '19 16:06 amotl