Skip to content

Commit

Permalink
Handle -9999 values in regis (issue #362)
Browse files Browse the repository at this point in the history
  • Loading branch information
rubencalje committed Jul 25, 2024
1 parent 64ba43b commit 9bcbc73
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions nlmod/read/regis.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def get_regis(
remove_nan_layers=True,
drop_layer_dim_from_top=True,
probabilities=False,
nodata=-9999,
):
"""Get a regis dataset projected on the modelgrid.
Expand Down Expand Up @@ -158,6 +159,17 @@ def get_regis(
# rename bottom to botm, as it is called in FloPy
ds = ds.rename_vars({"bottom": "botm"})

# slice data vars
if variables is not None:
if probabilities:
variables = variables + ("sdh", "sdv")
ds = ds[list(variables)]

# since version REGIS v02r2s2 (22.07.2024) NaN values are replaced by -9999
# we set these values to NaN again
for var in variables:
ds[var] = ds[var].where(ds[var] != nodata)

if remove_nan_layers:
# only keep layers with at least one active cell
ds = ds.sel(layer=~(np.isnan(ds["botm"])).all(ds["botm"].dims[1:]))
Expand All @@ -168,12 +180,6 @@ def get_regis(
if drop_layer_dim_from_top:
ds = remove_layer_dim_from_top(ds)

# slice data vars
if variables is not None:
if probabilities:
variables = variables + ("sdh", "sdv")
ds = ds[list(variables)]

ds.attrs["gridtype"] = "structured"
ds.attrs["extent"] = extent
for datavar in ds:
Expand Down

0 comments on commit 9bcbc73

Please sign in to comment.