Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions nlmod/read/knmi.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@

@cache.cache_netcdf(coords_3d=True, coords_time=True)
def get_recharge(ds, method="linear", most_common_station=False):
"""Add multiple recharge packages to the groundwater flow model with knmi
data by following these steps:
"""Add recharge to model dataset from KNMI data.

Add recharge to the model dataset with knmi data by following these steps:
1. check for each cell (structured or vertex) which knmi measurement
stations (prec and evap) are the closest.
2. download precipitation and evaporation data for all knmi stations that
were found at 1
3. create a recharge package in which each cell has a reference to a
3. create a recharge array in which each cell has a reference to a
timeseries. Timeseries are created for each unique combination of
precipitation and evaporation. The following packages are created:
a. the rch package itself in which cells with the same
Expand All @@ -40,7 +41,7 @@ def get_recharge(ds, method="linear", most_common_station=False):
method : str, optional
If 'linear', calculate recharge by subtracting evaporation from precipitation.
If 'separate', add precipitation as 'recharge' and evaporation as 'evaporation'.
The defaults is 'linear'.
The default is 'linear'.
most_common_station : bool, optional
When True, only download data from the station that is most common in the model
area. The default is False
Expand Down Expand Up @@ -71,6 +72,8 @@ def get_recharge(ds, method="linear", most_common_station=False):
dims = ("y", "x")
elif ds.gridtype == "vertex":
dims = ("icell2d",)
else:
raise ValueError("gridtype should be structured or vertex")
dims = ("time",) + dims

shape = [len(ds_out[dim]) for dim in dims]
Expand Down
2 changes: 2 additions & 0 deletions nlmod/read/nhi.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ def get_gwo_wells(
params.update(kwargs)

r = requests.get(url, auth=(username, password), params=params, timeout=timeout)
if not r.ok:
r.raise_for_status()
content = r.content.decode("utf-8")
if len(content) == 0:
if page == 1:
Expand Down
6 changes: 3 additions & 3 deletions tests/test_005_external_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ def test_get_recharge_steady_state():

def test_get_recharge_not_available():
ds = nlmod.get_ds([100000, 110000, 420000, 430000])
time = pd.date_range("2010", pd.Timestamp.now())
ds = nlmod.time.set_ds_time(ds, start="2000", time=time)
with pytest.raises(ValueError):
time = [pd.Timestamp.now().normalize()]
ds = nlmod.time.set_ds_time(ds, start=time[0] - pd.Timedelta(days=21), time=time)
with pytest.raises(KeyError):
ds.update(nlmod.read.knmi.get_recharge(ds))


Expand Down
Loading