Skip to content

Commit

Permalink
More error catching in splitting layer ds
Browse files Browse the repository at this point in the history
  • Loading branch information
bdestombe committed Nov 22, 2023
1 parent d4374d1 commit 00febad
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion nlmod/dims/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,16 @@ def split_layers_ds(
# 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

0 comments on commit 00febad

Please sign in to comment.