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

Cannot save results loaded with filter #156

Merged
merged 2 commits into from
Jan 13, 2025
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
2 changes: 2 additions & 0 deletions mikeio1d/res1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@

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


class Res1D:
Expand Down Expand Up @@ -308,6 +309,7 @@ def save(self, file_path):
self.reader.load_dynamic_data()
connection_original = self.result_data.Connection
self.result_data.Connection = Connection.Create(file_path)
Res1DExtensions.RemoveUnusedDataItems(self.result_data)
self.result_data.Save()
self.result_data.Connection = connection_original

Expand Down
21 changes: 21 additions & 0 deletions tests/test_various.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import pytest

import mikeio1d
from mikeio1d import Res1D
from mikeio1d.result_network.various import make_proper_variable_name

Expand All @@ -18,6 +19,13 @@ def test_file_path_res11():
return os.path.join(test_folder_path, "testdata", "network_cali.res11")


@pytest.fixture
def test_file_path2():
test_folder_path = os.path.dirname(os.path.abspath(__file__))
# Original file name was Exam6Base.res1d
return os.path.join(test_folder_path, "testdata", "network.res1d")


def test_make_proper_variable_name():
mpvn = make_proper_variable_name # alias
assert mpvn("a") == "a"
Expand Down Expand Up @@ -71,3 +79,16 @@ def test_res11_to_res1d_conversion(test_file_path_res11):
df_res1d = res1d.read()

assert df_res11.max().max() == df_res1d.max().max()


def test_saving_with_filter(test_file_path2):
res_unfiltered = mikeio1d.open(test_file_path2)
assert res_unfiltered.quantities == ["WaterLevel", "Discharge"]

res_filtered = mikeio1d.open(test_file_path2, quantities=["WaterLevel"])
res_filtered.save("filtered.res1d")

res_filtered = mikeio1d.open("filtered.res1d")
assert res_filtered.quantities == ["WaterLevel"]

os.remove("filtered.res1d")
Loading