meteostat / meteostat-python

Access and analyze historical weather and climate data with Python.
https://dev.meteostat.net/python/
MIT License
437 stars 60 forks source link

Point interpolation weighted method error #148

Open MarineMercier opened 12 months ago

MarineMercier commented 12 months ago

Hi,

I'm having trouble using the weighted interpolation method for a Point between different stations, I've tried :

point = Point(lon=lon, lat=lat)
point.method = "weighted"
monthly_data = Monthly(point, start_date, end_date)

This piece of code returns an error : KeyError: 'wdir' image

The code in _resolve_point(...) looks like this :

if method == "nearest" :
   ...
else : 
   # Join score and elevation of involved weather stations
   data = self._data.join(stations[["score", "elevation"]], on="station")

   if not self.granularity == Granularity.NORMALS:
      excluded = data["wdir"]
      excluded = excluded.groupby(pd.Grouper(level="time", freq=self._freq)).agg("first")

   if self.granularity == Granularity.NORMALS:
      ...

   else : 
      data = data.groupby(pd.Grouper(level="time", freq=self._freq)).apply(weighted_average )
      # Drop RangeIndex
      data.index = data.index.droplevel(1)
      # Merge excluded fields
       data["wdir"] = excluded

with data['wdir'] and excluded referring to each other, while none of them is defined in the file. Using monthly_data = Monthly(Point(lon=lon, lat=lat), start_date, end_date), monthly_data._data seems to never hold a 'wdir' key.

The stations called in self._resolve_point(loc.method, stations, loc.alt,...) is defined as point.get_stations() in interface/timeseries.py, but calling point.get_stations() returns a DataFrame where 'wdir' is also not defined.

Could you please let me know how to find/define this data['wdir'] please? Thanks in advance for your help