Skip to content

Commit

Permalink
Fixes earlier new functionality (storage nodes, greenhouses)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruud Hurkmans committed Dec 9, 2024
1 parent 26ad48e commit f12e9cb
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 17 deletions.
20 changes: 9 additions & 11 deletions hydrolib/dhydamo/converters/hydamo2df.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,13 @@ def weirs(
management_device.kunstwerkopeningid
== weir_opening.globalid.to_string(index=False)
]

if weir_opening.empty:
print(f'Skipping {weir.code} because there is no associated opening.')
continue
if weir_mandev.empty:
print(f'Skipping {weir.code} because there is no associated management device.')
continue

# check if a separate name field is present
if "naam" in weirs:
name = weir.naam
Expand Down Expand Up @@ -609,13 +615,8 @@ def weirs(
uselimitflowneg=limitflow,
limitflowneg=maxq,
)
else:
if weir_opening.empty:
print(f'Skipping {weir.code} because there is no associated opening.')
elif weir_mandev.empty:
print(f'Skipping {weir.code} because there is no associated management device.')
else:
print(f'Skipping {weir.code} - conversion failed. Wrong type for soortregelmiddel? It is now {weir_mandev.overlaatonderlaat.to_string(index=False).lower()}.')
else:
print(f'Skipping {weir.code} - from "overlaatonderlaat" {weir_mandev.overlaatonderlaat} the type of structure could not be determined.')

uweirs = weirs[index == 1]
for uweir in uweirs.itertuples():
Expand Down Expand Up @@ -645,10 +646,7 @@ def weirs(
kruinhoogte = np.min(xyz[:,-1])
else:
kruinhoogte = uweir.laagstedoorstroomhoogte




if len(prof) == 0:
# return an error it is still not found
raise ValueError(f"{uweir.code} is not found in any cross-section.")
Expand Down
12 changes: 11 additions & 1 deletion hydrolib/dhydamo/core/hydamo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2225,6 +2225,7 @@ def add_storagenode(
nodeid=None,
usestreetstorage="true",
nodetype="unspecified",
manholeid=None,
name=np.nan,
usetable="false",
bedlevel=np.nan,
Expand All @@ -2242,7 +2243,7 @@ def add_storagenode(
xy = Point(*xy)
if xy is None and chainage is not None:
xy = self.hydamo.branches.loc[branchid].geometry.interpolate(chainage)

# Find the nearest node
if nodeid is not None and not isinstance(nodeid, str):
raise ValueError('If a nodeid is provided, it should be of type string.')
Expand All @@ -2265,13 +2266,17 @@ def add_storagenode(
_, idx_nearest = get_nearest.query(xy.coords[:])
nodeid = f"{float(nodes1d[idx_nearest[0],0]):12.6f}_{float(nodes1d[idx_nearest[0],1]):12.6f}"

if manholeid is None:
manholeid = nodeid

base = {
"type": "storageNode",
"id": id,
"name": id if name is None else name,
"useStreetStorage": usestreetstorage,
"nodeType": nodetype,
"useTable": usetable,
"manholeId": manholeid
}
if nodeid is None:
cds = {'branchid':branchid,
Expand Down Expand Up @@ -2300,6 +2305,11 @@ def add_storagenode(
"levels": levels,
"storageArea": storagearea,
"interpolate": interpolate,
"bedLevel": -999.,
"area":-999.,
"streetLevel": -999.,
"streetStorageArea":-999.,
"storageType": storagetype,
}
else:
raise ValueError(
Expand Down
2 changes: 1 addition & 1 deletion hydrolib/dhydamo/geometry/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ def mesh1d_add_branches_from_gdf(
network.mesh1d_add_branch(branch, name=branchname)


def mesh1d_order_numbers_from_attribute(branches: gpd.GeoDataFrame, missing: list, order_attribute:str, network: Network, exceptions:list=None)-> list:
def mesh1d_order_numbers_from_attribute(branches: gpd.GeoDataFrame, missing: list, order_attribute:str, network: Network, exceptions:list=[])-> list:
"""
mesh1d_order_numbers_from_attribute Method to allocate order numbers to branches based on a common attribute.
Expand Down
23 changes: 19 additions & 4 deletions hydrolib/dhydamo/io/drrreader.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,16 @@ def unpaved_from_input(
# subtract greenhouse area from most occurring land use if no greenhouse area is in the landuse map
if greenhouse_areas is not None:
if cat.geometry.intersects(greenhouse_areas.geometry).any():
area = greenhouse_areas[cat.geometry.intersects(greenhouse_areas.geometry)].geometry.area
if 15 not in lu_counts[num]:
maxind = np.argmax(list(lu_counts[num].values()))
lu_counts[num][list(lu_counts[num].keys())[maxind]] = np.max([0., (lu_counts[num][list(lu_counts[num].keys())[maxind]] - np.round(area/px_area)).values[0]])
intersection_area = cat.geometry.intersection(greenhouse_areas.geometry).area
intersection_area = intersection_area[intersection_area > 0.].values[0]
if 15 in lu_counts[num]:
# divide area to subtract between greenhouses and the most occurring area
remainder = np.max([0., intersection_area - float(lu_counts[num][15]*px_area)])
else:
remainder = intersection_area
maxind = np.argmax(list(lu_counts[num].values()))
print(f'Catchment {cat.code}: subtracting {remainder} m2 from class {maxind} for supplied greenhouse area.')
lu_counts[num][list(lu_counts[num].keys())[maxind]] = np.max([0., (lu_counts[num][list(lu_counts[num].keys())[maxind]] - np.round(remainder/px_area))])

for i in range(1, 13):
if i in lu_counts[num]:
Expand Down Expand Up @@ -739,6 +745,15 @@ def greenhouse_from_input(
]
ms = meteo_areas.iloc[0, :][0] if tm == [] else tm[0].code

if greenhouse_areas is not None:
if cat.geometry.intersects(greenhouse_areas.geometry).any():
intersection_area = cat.geometry.intersection(greenhouse_areas.geometry).area
intersection_area = intersection_area[intersection_area > 0.].values[0]
if 15 in lu_counts[num]:
# divide area to subtract between greenhouses and the most occurring area
print(f'Catchment: {cat.code}: subtracting {np.min([(lu_counts[num][15]*px_area, intersection_area)])} m2 from greenhouse area in landuse map.')
lu_counts[num][15] = np.max([0., (lu_counts[num][15] - np.round(intersection_area/px_area))])

elev = mean_elev[num]["median"]
gh_drr.at[cat.code, "id"] = str(cat.code)
gh_drr.at[cat.code, "area"] = (
Expand Down
Binary file modified hydrolib/tests/data/greenhouse_laterals.gpkg
Binary file not shown.
Binary file modified hydrolib/tests/data/greenhouses.gpkg
Binary file not shown.

0 comments on commit f12e9cb

Please sign in to comment.