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

Bugfix: convert res11 to res1d correctly. #93

Merged
merged 1 commit into from
Mar 23, 2024
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
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it necessary to set it back to the original connection?

Copy link
Collaborator Author

@gedaskir gedaskir Mar 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not necessary, but it is good not to confuse by saving the file what is the original specification of the loaded file.


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.
Loading