Skip to content

Commit

Permalink
fixed 1d2d reading
Browse files Browse the repository at this point in the history
  • Loading branch information
veenstrajelmer committed Oct 30, 2023
1 parent e607ba7 commit 2f0eec2
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 5 deletions.
3 changes: 2 additions & 1 deletion hydrolib/core/dflowfm/net/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,8 @@ class Mesh1d(BaseModel):
)

def is_empty(self) -> bool:
return self.mesh1d_node_x.size == 0
# return self.mesh1d_node_x.size == 0
return self.meshkernel.mesh1d_get().node_x.size == 0

def _get_mesh1d(self) -> mk.Mesh1d:
"""Return mesh1d from meshkernel. Note that the meshkernel.Mesh1d instance
Expand Down
3 changes: 2 additions & 1 deletion hydrolib/core/dflowfm/net/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ def read_mesh1d_network1d(self, mesh1d: Mesh1d) -> None:

# Process network
mesh1d._process_network1d()
mesh1d._set_mesh1d() # TODO: we still require this here to sync new attrs with meshkernel instance

ds.close()

Expand All @@ -86,7 +87,7 @@ def read_mesh2d(self, mesh2d: Mesh2d) -> None:
setattr(mesh2d, meshkey, self._read_nc_attribute(ds[nckey]))
# TODO: replace with xugrid reader

mesh2d._set_mesh2d() # TODO: we still require this here to sync new attrs with meshkernel instance
mesh2d._set_mesh2d() # TODO: we still require this here to sync new attrs with meshkernel instance

ds.close()

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ multi_line_output = 3
line_length = 88

[tool.pytest.ini_options]
addopts = "-m \"not plots\""
markers = [
"plots",
"docker"
Expand Down
26 changes: 23 additions & 3 deletions tests/dflowfm/test_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def test_create_1d_by_branch():
network.to_file(test_output_dir / "test_net.nc")


@pytest.mark.plots
# @pytest.mark.plots
def test_create_1d_branch_structure_offset():

line = np.array([[0, 0], [100, 0]])
Expand Down Expand Up @@ -120,7 +120,7 @@ def get_circle_gl(r, detail=100):
return polygon


@pytest.mark.plots
# @pytest.mark.plots
def test_create_1d_2d_1d2d():

# Define line (spiral)
Expand Down Expand Up @@ -261,8 +261,20 @@ def test_read_net_nc(filepath):

# Create network model
network = NetworkModel(filepath=filepath)
# network = networkmodel.network
assert not network._mesh1d.is_empty()
assert network._mesh2d.is_empty()

# test whether meshkernel instance and hydrolib mesh2d/mesh1d instance are consistent
nnodes_internal = network._mesh2d.mesh2d_node_x.size
nnodes_mk = network._mesh2d.get_mesh2d().node_x.size
nnodes_mk2 = network._mesh2d.meshkernel.mesh2d_get().node_x.size
assert nnodes_internal == nnodes_mk == nnodes_mk2
nnodes_internal = network._mesh1d.mesh1d_node_x.size
nnodes_mk = network._mesh1d._get_mesh1d().node_x.size
nnodes_mk2 = network._mesh1d.meshkernel.mesh1d_get().node_x.size
assert nnodes_internal == nnodes_mk == nnodes_mk2



@pytest.mark.parametrize("filepath", cases)
Expand Down Expand Up @@ -442,7 +454,8 @@ def test_read_net_nc_2d_without_faces(self):
# test whether meshkernel instance and hydrolib mesh2d instance are consistent
nnodes_internal = network._mesh2d.mesh2d_node_x.size
nnodes_mk = network._mesh2d.get_mesh2d().node_x.size
assert nnodes_internal == nnodes_mk
nnodes_mk2 = network._mesh2d.meshkernel.mesh2d_get().node_x.size
assert nnodes_internal == nnodes_mk == nnodes_mk2


class TestNCExplorer:
Expand Down Expand Up @@ -641,6 +654,13 @@ def test_add_1d2d_links():
np.array([[3, 70], [4, 62], [5, 54], [6, 45], [7, 37], [8, 29]]),
)

# test whether meshkernel instance and hydrolib mesh2d instance are consistent
nnodes_internal = network._mesh1d.mesh1d_node_x.size
nnodes_mk = network._mesh1d._get_mesh1d().node_x.size
nnodes_mk2 = network._mesh1d.meshkernel.mesh1d_get().node_x.size
assert nnodes_internal == nnodes_mk == nnodes_mk2



def test_write_netcdf_with_custom_fillvalue_correctly_writes_fillvalue():
nc_output_file = Path(test_output_dir / "test.nc")
Expand Down

0 comments on commit 2f0eec2

Please sign in to comment.