Skip to content

Commit

Permalink
unique station names in gdf and fix timezone
Browse files Browse the repository at this point in the history
  • Loading branch information
veenstrajelmer committed Feb 29, 2024
1 parent 062f791 commit f0864b5
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions dfm_tools/observations.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,11 +572,17 @@ def ddl_ssh_read_catalog(meta_dict=None, old=False):

# import re
# stat_naam_alphanumeric = df["Naam"].str.replace('[^0-9a-zA-Z]+', '-', regex=True)
# generate unique names, we need suffixes since not all station codes are unique
# TODO: make this more generic
station_name_unique = ddl_slev_gdf["Code"]
station_name_unique2 = [name + "-1" if duplicated else name for duplicated, name in zip(station_name_unique.duplicated(), station_name_unique)]
ddl_slev_gdf["station_name_unique"] = station_name_unique2
if ddl_slev_gdf["station_name_unique"].duplicated().sum():
raise Exception("still duplicated station codes")
station_name_unique2 = pd.Series(station_name_unique2)
station_name_unique3 = [name.replace("-1","-2") if duplicated else name for duplicated, name in zip(station_name_unique2.duplicated(), station_name_unique2)]
ddl_slev_gdf["station_name_unique"] = station_name_unique3
dupl_bool = ddl_slev_gdf["station_name_unique"].duplicated(keep=False)
dupl_df = ddl_slev_gdf.loc[dupl_bool, ["Code", "Naam", "station_name_unique"]].sort_values("Code")
if dupl_bool.sum():
raise Exception(f"still duplicated station codes\n{dupl_df}")

return ddl_slev_gdf

Expand Down Expand Up @@ -951,7 +957,7 @@ def ddl_ssh_retrieve_data(ssh_catalog_gpd, dir_output, time_min, time_max, meta_
# data = data.rename("Meetwaarde.Waarde_Numeriek", "values")

# dropping timezone is required to get proper encoding in time variable (in file)
data.index = data.index.tz_localize(None)
data.index = data.index.tz_convert(None)
# set name so xarray recognizes the time coordinate/index
data.index.name = "time"

Expand Down

0 comments on commit f0864b5

Please sign in to comment.