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

couple of small fixes and improvements to D-HyDAMO #172

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
5 changes: 3 additions & 2 deletions hydrolib/dhydamo/converters/hydamo2df.py
Original file line number Diff line number Diff line change
Expand Up @@ -536,8 +536,9 @@ def weirs(
"""

index = np.zeros((len(weirs.code)))
if (profile_groups is not None) & ("stuwid" in profile_groups):
index[np.isin(weirs.globalid, np.asarray(profile_groups.stuwid))] = 1
if profile_groups is not None:
if "stuwid" in profile_groups:
index[np.isin(weirs.globalid, np.asarray(profile_groups.stuwid))] = 1

rweirs = weirs[index == 0]
for weir in rweirs.itertuples():
Expand Down
1 change: 1 addition & 0 deletions hydrolib/dhydamo/core/drtc.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ def from_hydamo(
logger.info(
f"Management for pump {management.pompid} is included in FM."
)
continue
else:
raise ValueError(
"Only management_devices and pumps can be connected to a management object."
Expand Down
15 changes: 9 additions & 6 deletions hydrolib/dhydamo/geometry/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ def mesh1d_add_branch_from_linestring(
linestring: LineString,
node_distance: Union[float, int],
name: Union[str, None] = None,
long_name: Union[str, None] = None,
structure_chainage: Union[List[float], None] = None,
max_dist_to_struc: Union[float, None] = None,
) -> str:
Expand All @@ -230,7 +231,7 @@ def mesh1d_add_branch_from_linestring(
structure_chainage=structure_chainage,
max_dist_to_struc=max_dist_to_struc,
)
branchid = network.mesh1d_add_branch(branch, name=name)
branchid = network.mesh1d_add_branch(branch, name=name, long_name=long_name)

return branchid

Expand All @@ -239,6 +240,7 @@ def mesh1d_add_branches_from_gdf(
network: Network,
branches: gpd.GeoDataFrame,
branch_name_col: str,
branch_long_name_col: str,
node_distance: float,
max_dist_to_struc: float = None,
structures=None,
Expand Down Expand Up @@ -280,20 +282,21 @@ def mesh1d_add_branches_from_gdf(
structure_chainage[branchid] = u

# Loop over all branches, and add structures
for branchname, geometry in zip(
branches[branch_name_col].tolist(), branches["geometry"].tolist()
for branchname, branchlongname, geometry in zip(
branches[branch_name_col].tolist(),
branches[branch_long_name_col].tolist(),
branches["geometry"].tolist()
):
# Create branch
branch = Branch(geometry=np.array(geometry.coords[:]))
# Generate nodes on branch
branch.generate_nodes(
mesh1d_edge_length=node_distance,
structure_chainage=structure_chainage[branchname]
if branchname in structure_chainage
else None,
if branchname in structure_chainage else None,
max_dist_to_struc=max_dist_to_struc,
)
network.mesh1d_add_branch(branch, name=branchname)
network.mesh1d_add_branch(branch, name=branchname, long_name=branchlongname)


def mesh1d_set_branch_order(network: Network, branchids: list, idx: int = None) -> None:
Expand Down
14 changes: 6 additions & 8 deletions hydrolib/dhydamo/io/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,11 @@ def read_gpkg_layer(
startnr[branch] = min(volgnr, startnr[branch])

# Determine relative order of points in profile (required if the point numbering is not subsequent)
order_rel = []
for branch, volgnr in zip(groupbyvalues, order):
lst_volgnr = [x[1] for x in zip(groupbyvalues, order) if x[0] == branch]
lst_volgnr.sort()
for i, x in enumerate(lst_volgnr):
if volgnr == x:
order_rel.append(i)
layer_sorted = layer.sort_values([groupby_column, order_column])
order_rel = layer_sorted[order_column]
order_rel = np.array([0 if x1 < x2 else 1 for x1, x2 in zip(order_rel[:-1], order_rel[1:])])
order_rel = np.append([1], order_rel) # shift one place further
order_rel = np.arange(len(order_rel)) - pd.Series(np.where(order_rel == 1, np.arange(len(order_rel)), np.nan)).fillna(method='ffill')

# Filter branches with too few points
singlepoint = counts < 2
Expand All @@ -282,7 +280,7 @@ def read_gpkg_layer(
layer.geometry, order, groupbyvalues, order_rel
):
# lines[branch][volgnr - startnr[branch]] = point
lines[branch][volgnr_rel] = point
lines[branch][int(volgnr_rel)] = point

# Group geometries to lines
for branch in branches[~singlepoint]:
Expand Down