Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split layer ds minor changes #295

Merged
merged 5 commits into from
Nov 27, 2023
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
5 changes: 5 additions & 0 deletions nlmod/dims/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def to_model_ds(
angrot=0.0,
drop_attributes=True,
transport=False,
remove_nan_layers=True,
):
"""Transform an input dataset to a groundwater model dataset.

Expand Down Expand Up @@ -125,6 +126,9 @@ def to_model_ds(
transport : bool, optional
flag indicating whether dataset includes data for a groundwater
transport model (GWT). Default is False, no transport.
remove_nan_layers : bool, optional
bdestombe marked this conversation as resolved.
Show resolved Hide resolved
if True remove layers with only nan values in the botm. Default is
True.

Returns
-------
Expand Down Expand Up @@ -174,6 +178,7 @@ def to_model_ds(
anisotropy=anisotropy,
fill_value_kh=fill_value_kh,
fill_value_kv=fill_value_kv,
remove_nan_layers=remove_nan_layers,
)

return ds
Expand Down
14 changes: 12 additions & 2 deletions nlmod/dims/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,20 +223,30 @@ def split_layers_ds(

layers = list(ds.layer.data)

# Work on a shallow copy of split_dict
split_dict = split_dict.copy()

# do some input-checking on split_dict
for lay0 in list(split_dict):
if isinstance(lay0, int) & (ds.layer.dtype != int):
# if layer is an integer, and ds.layer is not of integer type
# replace lay0 by the name of the layer
split_dict[layers[lay0]] = split_dict.pop(lay0)
lay0 = layers[lay0]
if isinstance(split_dict[lay0], int):
if isinstance(split_dict[lay0], (int, np.integer)):
# If split_dict[lay0] is of integer type
# split the layer in evenly thick layers
split_dict[lay0] = [1 / split_dict[lay0]] * split_dict[lay0]
else:
elif hasattr(split_dict[lay0], "__iter__"):
# make sure the fractions add up to 1
assert np.isclose(np.sum(split_dict[lay0]), 1), (
f"Fractions for splitting layer '{lay0}' do not add up to 1."
)
split_dict[lay0] = split_dict[lay0] / np.sum(split_dict[lay0])
else:
raise ValueError(
"split_dict should contain an iterable of factors or an integer"
)

logger.info(f"Splitting layers {list(split_dict)}")

Expand Down
1 change: 1 addition & 0 deletions nlmod/read/regis.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ def get_regis(
variables = variables + ("sdh", "sdv")
ds = ds[list(variables)]

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