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

use new contacts_set from meshkernel 4.0.2 #602

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
18 changes: 8 additions & 10 deletions hydrolib/core/dflowfm/net/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import netCDF4 as nc
import numpy as np
from meshkernel import Contacts

from hydrolib.core.basemodel import BaseModel

Expand Down Expand Up @@ -123,16 +124,13 @@ def read_link1d2d(self, link1d2d: Link1d2d) -> None:
for meshkey, nckey in self._explorer.link1d2d_var_name_mapping.items():
setattr(link1d2d, meshkey, self._read_nc_attribute(ds[nckey]))

# TODO: setting contacts is not possible yet in meshkernel
# https://github.com/Deltares/MeshKernelPy/issues/107
# https://github.com/Deltares/HYDROLIB-core/issues/575
# so misalignment between link1d2d.link1d2d and
# empty _link1d2d.meshkernel.contacts_get().mesh2d_indices
# mesh1d_indices = link1d2d.link1d2d[:,0]
# mesh2d_indices = link1d2d.link1d2d[:,1]
# import meshkernel as mk
# contacts = mk.Contacts(mesh1d_indices=mesh1d_indices, mesh2d_indices=mesh2d_indices)
# link1d2d.meshkernel.contacts_set(contacts)
# set contacts on meshkernel, use .copy() to avoid strided arrays
mesh1d_indices = link1d2d.link1d2d[:, 0].copy()
mesh2d_indices = link1d2d.link1d2d[:, 1].copy()
contacts = Contacts(
mesh1d_indices=mesh1d_indices, mesh2d_indices=mesh2d_indices
)
link1d2d.meshkernel.contacts_set(contacts)

ds.close()

Expand Down
6 changes: 2 additions & 4 deletions tests/dflowfm/test_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,8 @@ def test_create_1d_2d_1d2d():
network2_con_m1d = network2._link1d2d.meshkernel.contacts_get().mesh1d_indices
network2_con_m2d = network2._link1d2d.meshkernel.contacts_get().mesh2d_indices
assert network2_link1d2d.shape == (21, 2)
# TODO: below asserts fail, since the meshkernel contacts are not set upon reading
# https://github.com/Deltares/HYDROLIB-core/issues/575
# assert network2_con_m1d.size == 21
# assert network2_con_m2d.size == 21
assert network2_con_m1d.size == 21
assert network2_con_m2d.size == 21

# plot both networks
import matplotlib.pyplot as plt
Expand Down