From 66be64c5a0e3c6d1abb1ac1c78beafaedec280ac Mon Sep 17 00:00:00 2001 From: OnnoEbbens Date: Fri, 27 Sep 2024 11:18:25 +0200 Subject: [PATCH] fix for knmi precipitation data station attribute is sometimes a series with duplicate entries #241 --- hydropandas/io/knmi.py | 15 ++++++++++----- hydropandas/observation.py | 5 ++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/hydropandas/io/knmi.py b/hydropandas/io/knmi.py index c0a9044a..3cb9983c 100644 --- a/hydropandas/io/knmi.py +++ b/hydropandas/io/knmi.py @@ -54,7 +54,10 @@ def get_knmi_obs( **kwargs: fill_missing_obs : bool, optional if True nan values in time series are filled with nearby time series. - The default is False. + The default is False. Note: if the given stn has no data between start and + end the data from nearby stations is used. In this case the metadata of the + Observation is the metadata from the nearest station that has any + measurement in the given period. interval : str, optional desired time interval for observations. Options are 'daily' and 'hourly'. The default is 'daily'. @@ -1214,8 +1217,7 @@ def interpret_knmi_file( raise ValueError( f"Cannot handle multiple stations {unique_stn} in single file" ) - else: - stn = df.at[df.index[0], "STN"] + stn = unique_stn[0] if add_day or add_hour: if add_day and add_hour: @@ -1659,7 +1661,10 @@ class of the observations, can be PrecipitationObs or **kwargs: fill_missing_obs : bool, optional if True nan values in time series are filled with nearby time series. - The default is False. + The default is False. Note: if the given stn has no data between start and + end the data from nearby stations is used. In this case the metadata of the + Observation is the metadata from the nearest station that has any + measurement in the given period. interval : str, optional desired time interval for observations. Options are 'daily' and 'hourly'. The default is 'daily'. @@ -1674,7 +1679,7 @@ class of the observations, can be PrecipitationObs or Returns ------- - obs_list : list of obsevation objects + obs_list : list of observation objects collection of multiple point observations """ diff --git a/hydropandas/observation.py b/hydropandas/observation.py index 71fcb0be..dbb3a8a9 100644 --- a/hydropandas/observation.py +++ b/hydropandas/observation.py @@ -1083,7 +1083,10 @@ def from_knmi( end date of observations. The default is None. fill_missing_obs : bool, optional if True nan values in time series are filled with nearby time series. - The default is False. + The default is False. Note: if the given stn has no data between start and + end the data from nearby stations is used. In this case the metadata of the + Observation is the metadata from the nearest station that has any + measurement in the given period. interval : str, optional desired time interval for observations. Options are 'daily' and 'hourly'. The default is 'daily'.