jeremiahpslewis / dwdbulk

dwdbulk: Easy Access to Open German Weather Data
MIT License
10 stars 2 forks source link

Forecast lookup by latitude, longitude rather than station name? #2

Open drmrbrewer opened 4 years ago

drmrbrewer commented 4 years ago

This library looks promising, thanks!

Is it possible to do a forecast data lookup based on latitude, longitude? I can't see anything in the examples... it would be something similar to what is in In [1] to In [3] of this page but using lat/long rather than e.g. "Berlin".

bakunin75 commented 4 years ago

You can use the following workaround to obtain the station_id of the closest station to your input lat and lon.

import pandas as pd
from dwdbulk.api import observations

resolution = "10_minutes"
parameter = "air_temperature"
df_stations = observations.get_stations(resolution,parameter)
lat, lon = .., ..
df_stations["delta_lon_lat"] = (df_stations.geo_lon - lon).abs() + (df_stations.geo_lat-lat).abs()
df_stations.sort_values(by="delta_lon_lat", inplace=True)
station_id = df_stations.station_id.iloc[0]