Skip to content

Commit

Permalink
Merge pull request #335 from gwmod/fix-for-#334
Browse files Browse the repository at this point in the history
fix webservice HHNK for #334 and #317
  • Loading branch information
OnnoEbbens committed Apr 19, 2024
2 parents 98392f9 + b5e23cc commit 64605fa
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 37 deletions.
46 changes: 32 additions & 14 deletions nlmod/read/knmi.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,20 +277,38 @@ def get_knmi_at_locations(ds, start="2010", end=None, most_common_station=False)
stns_ev24 = locations["stn_ev24"].unique()

# get knmi data stations closest to any grid cell
oc_knmi_prec = hpd.ObsCollection.from_knmi(
stns=stns_rd,
starts=[start],
ends=[end],
meteo_vars=["RD"],
fill_missing_obs=True,
)
olist_rd, new_stns_rd = [], []
for stnrd in stns_rd:
o = hpd.PrecipitationObs.from_knmi(
meteo_var="RD", stn=stnrd, start=start, end=end, fill_missing_obs=True
)

oc_knmi_evap = hpd.ObsCollection.from_knmi(
stns=stns_ev24,
starts=[start],
ends=[end],
meteo_vars=["EV24"],
fill_missing_obs=True,
)
# if a station has no data in the given period another station is selected
if o.station != stnrd:
locations["stn_rd"] = locations["stn_rd"].replace(stnrd, o.station)

# only add the station if it does not exist yet
if o.station not in new_stns_rd:
olist_rd.append(o)
new_stns_rd.append(o.station)

oc_knmi_prec = hpd.ObsCollection(olist_rd)

olist_ev24, new_stns_ev24 = [], []
for stnev24 in stns_ev24:
o = hpd.EvaporationObs.from_knmi(
meteo_var="EV24", stn=stnev24, start=start, end=end, fill_missing_obs=True
)

# if a station has no data in the given period another station is selected
if o.station != stnev24:
locations["stn_ev24"] = locations["stn_rd"].replace(stnev24, o.station)

# only add the station if it does not exist yet
if o.station not in new_stns_ev24:
olist_ev24.append(o)
new_stns_ev24.append(o.station)

oc_knmi_evap = hpd.ObsCollection(olist_ev24)

return locations, oc_knmi_prec, oc_knmi_evap
2 changes: 1 addition & 1 deletion nlmod/read/waterboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def get_configuration():
"bottom_height": "WS_BODEMHOOGTE",
},
"level_areas": {
"url": "https://kaarten.hhnk.nl/arcgis/rest/services/NHFLO/Peilgebied_beheerregister/MapServer",
"url": "https://kaarten.hhnk.nl/arcgis/rest/services/ws/ws_peilgebieden_vigerend/MapServer",
"summer_stage": [
"ZOMER",
"STREEFPEIL_ZOMER",
Expand Down
22 changes: 0 additions & 22 deletions nlmod/read/webservices.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,28 +179,6 @@ def arcrest(
[feature["attributes"] for feature in data["features"]]
)

# add peilen to gdf
for col, convert_dic in table.items():
df[col].replace(convert_dic, inplace=True)
df.set_index(col, inplace=True)

for oid in gdf["OBJECTID"]:
insert_s = df.loc[
df["PEILGEBIEDVIGERENDID"] == oid, "WATERHOOGTE"
]
if insert_s.index.duplicated().any():
# Error in the database. Reported to Doeke HHNK 20230123
# Continue with unambiguous values
dup = set(insert_s.index[insert_s.index.duplicated()])
logger.warning(
f"Duplicate {dup} values for PEILGEBIEDVIGERENDID {oid} while prompting {url}"
)
insert_s = insert_s[~insert_s.index.duplicated(keep=False)]

gdf.loc[
gdf["OBJECTID"] == oid, insert_s.index
] = insert_s.values

return gdf


Expand Down

0 comments on commit 64605fa

Please sign in to comment.