Skip to content

Commit

Permalink
Bugfix: convert res11 to res1d correctly. (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
gedaskir authored Mar 23, 2024
1 parent 3f84151 commit 89f2f3c
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,4 @@ tests/testdata/w_right_discharge_in_structure.extract.txt
tests/testdata/lts_event_statistics.merged.res1d
tests/testdata/lts_monthly_statistics.merged.res1d
tests/testdata/catchment_merge_c.res1d
tests/testdata/network_cali.res1d
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@

### Changed

## [0.6.1] - 2024-02-024
## [0.6.1] - 2024-03-22

### Fixed

- Loading MIKE IO 1D together with MIKE+Py
- Fixed override_name parameter that was not working in ResultFrameAggregator
- Fixed converting res11 to res1d

## [0.6] - 2024-02-08

Expand Down
5 changes: 4 additions & 1 deletion mikeio1d/res1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
from .pandas_extension import Mikeio1dAccessor # noqa: F401

from System import DateTime
from DHI.Mike1D.Generic import Connection


class Res1D:
Expand Down Expand Up @@ -396,8 +397,10 @@ def save(self, file_path):
file_path : str
File path for the new res1d file.
"""
self.data.Connection.FilePath.Path = file_path
connection_original = self.data.Connection
self.data.Connection = Connection.Create(file_path)
self.data.Save()
self.data.Connection = connection_original

def extract(
self,
Expand Down
20 changes: 20 additions & 0 deletions tests/test_various.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ def test_file_path():
return os.path.join(test_folder_path, "testdata", "network_chinese.res1d")


@pytest.fixture
def test_file_path_res11():
test_folder_path = os.path.dirname(os.path.abspath(__file__))
return os.path.join(test_folder_path, "testdata", "network_cali.res11")


def test_make_proper_variable_name():
mpvn = make_proper_variable_name # alias
assert mpvn("a") == "a"
Expand Down Expand Up @@ -50,3 +56,17 @@ def test_mikeio1d_and_mikepluspy_coexistence(test_file_path):
script_path = os.path.join(test_folder_path, "call_mikepluspy_mikeio1d.py")
exit_code = subprocess.call(["python", script_path, test_file_path])
assert exit_code == 0


def test_res11_to_res1d_conversion(test_file_path_res11):
res11 = Res1D(test_file_path_res11)

test_file_path_res1d = test_file_path_res11.replace("res11", "res1d")
res11.save(test_file_path_res1d)

res1d = Res1D(test_file_path_res1d)

df_res11 = res11.read()
df_res1d = res1d.read()

assert df_res11.max().max() == df_res1d.max().max()
Binary file added tests/testdata/network_cali.res11
Binary file not shown.

0 comments on commit 89f2f3c

Please sign in to comment.