Skip to content

Commit

Permalink
Merge branch 'main' into simple
Browse files Browse the repository at this point in the history
  • Loading branch information
ecomodeller authored Nov 30, 2023
2 parents 627d89f + 886661f commit 8c6af48
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
11 changes: 11 additions & 0 deletions mikeio/dfs/_dfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,17 @@ def _valid_timesteps(dfsFileInfo: DfsFileInfo, time_steps) -> Tuple[bool, List[i
TimeAxisType.TimeEquidistant,
):
time_step_file = time_axis.TimeStep

if time_step_file <= 0:

if nt > 1:
raise ValueError(f"Time step must be a positive number. Time step in the file is {time_step_file} seconds.")

warnings.warn(
f"Time step is {time_step_file} seconds. This must be a positive number. Setting to 1 second."
)
time_step_file = 1

freq = pd.Timedelta(seconds=time_step_file)
time = pd.date_range(start_time_file, periods=nt, freq=freq)
elif time_axis.TimeAxisType == TimeAxisType.CalendarNonEquidistant:
Expand Down
2 changes: 1 addition & 1 deletion mikeio/dfsu/_dfsu.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def _read_dfsu_header(self, dfs):
element_ids=el_ids,
node_ids=node_ids,
n_layers=dfs.NumberOfLayers,
n_sigma=dfs.NumberOfSigmaLayers,
n_sigma=min(dfs.NumberOfSigmaLayers, dfs.NumberOfLayers),
validate=False,
)
elif self._type == DfsuFileType.DfsuSpectral1D:
Expand Down
14 changes: 14 additions & 0 deletions tests/test_dfs2.py
Original file line number Diff line number Diff line change
Expand Up @@ -870,3 +870,17 @@ def test_MIKE_SHE_output():
assert g2.x[0] == g.x[0] + 30 * g.dx
assert g2.y[0] == g.y[0] + 35 * g.dy
assert g2.origin == pytest.approx((g2.x[0], g2.y[0]))


def test_read_dfs2_static_dt_zero():

with pytest.warns(UserWarning, match="positive"):
ds = mikeio.read("tests/testdata/single_time_dt_zero.dfs2")
assert ds.n_timesteps == 1
assert ds.shape == (1, 2, 2)

with pytest.warns(UserWarning, match="positive"):
ds2 = mikeio.read("tests/testdata/single_time_dt_zero.dfs2", time=0)

assert ds2.shape == (2,2)
assert "time" not in ds2.dims
Binary file added tests/testdata/single_time_dt_zero.dfs2
Binary file not shown.

0 comments on commit 8c6af48

Please sign in to comment.