earthobservations / wetterdienst

Open weather data for humans.
https://wetterdienst.readthedocs.io/
MIT License
347 stars 54 forks source link

Interpolation for PRECIPITATION_HEIGHT only returns NaNs #1127

Closed mxmlnmrk closed 8 months ago

mxmlnmrk commented 8 months ago

Describe the bug As stated in the documentation for interpolation (https://wetterdienst.readthedocs.io/en/latest/usage/python-api.html#interpolation), I used the exact same code from the documentation example to request interpolated precipitation data. It works for the coordinates in the example, however, when lat and lon are changed, it only returns NaNs.

To Reproduce This is the code from the example in the documentation, which works:

import datetime as dt
from wetterdienst.provider.dwd.observation import DwdObservationRequest
from wetterdienst import Parameter, Resolution

request = DwdObservationRequest(
    parameter=Parameter.PRECIPITATION_HEIGHT,
    resolution=Resolution.HOURLY,
    start_date=dt.datetime(2022, 1, 1),
    end_date=dt.datetime(2022, 1, 20),
)

values = request.interpolate(latlon=(50.0, 8.9))

df = values.df

print(df.head())

and this code returns only NaN:

import datetime as dt
from wetterdienst.provider.dwd.observation import DwdObservationRequest
from wetterdienst import Parameter, Resolution

request = DwdObservationRequest(
    parameter=Parameter.PRECIPITATION_HEIGHT,
    resolution=Resolution.HOURLY,
    start_date=dt.datetime(2022, 1, 1),
    end_date=dt.datetime(2022, 1, 20),
)

values = request.interpolate(latlon=(52.8, 12.9))

df = values.df

print(df.head())

Expected behavior For all coordinates within germany, I expect to get data returned.

Desktop:

gutzbenj commented 8 months ago

Dear @mxmlnmrk ,

Thanks for reporting your issue!

We previously had set opinionated maximum station distances per parameter and specifically for precipitation_height we had set a maximum distance of 20 km of possible stations to use for interpolation. The available stations that can be used for interpolation may vary depending on the location in Germany. This is the issue with your code snipped and our example!

The new PR at https://github.com/earthobservations/wetterdienst/pull/1129 allows for flexible configuration of the maximum station distance per parameter:

import datetime as dt

from wetterdienst import Parameter, Resolution, Settings
from wetterdienst.provider.dwd.observation import DwdObservationRequest

settings = Settings(ts_interpolation_station_distance={"precipitation_height": 25}).  # for the given latlon tuple this is the required maximum distance

request = DwdObservationRequest(
    parameter=Parameter.PRECIPITATION_HEIGHT,
    resolution=Resolution.HOURLY,
    start_date=dt.datetime(2022, 1, 1),
    end_date=dt.datetime(2022, 1, 20),
    settings=settings,
)

values = request.interpolate(latlon=(52.8, 12.9))

df = values.df

However keep in mind: The farther the distance the less accurate the actual interpolation and especially precipitation is extremely inhomogeneous!

mxmlnmrk commented 8 months ago

That worked, thanks for the quick response!