Skip to content

Commit

Permalink
Use ground level as default when critical level is not set
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-kipawa committed Sep 17, 2024
1 parent bc92114 commit 62fca31
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions mikeio1d/result_network/result_reach.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,13 @@ def _get_start_node(self):
"""
Returns the start node of the reach.
"""
return self.res1d.data.Nodes[self.reaches[0].StartNodeIndex]
return self.res1d.data.Nodes[self.reaches[0].StartNodeIndex].Id

def _get_end_node(self):
"""
Returns the end node of the reach.
"""
return self.res1d.data.Nodes[self.reaches[-1].EndNodeIndex]
return self.res1d.data.Nodes[self.reaches[-1].EndNodeIndex].Id

def _get_full_flow_discharge(self) -> float:
"""
Expand Down Expand Up @@ -371,17 +371,30 @@ def interpolate_reach_critical_level(self, chainage: float) -> float:
reach = self._get_reach_for_chainage(chainage)
start_chainage = reach.LocationSpan.StartChainage
end_chainage = reach.LocationSpan.EndChainage
start_critical_level = getattr(
self.res1d.data.Nodes[reach.StartNodeIndex].__implementation__, "CriticalLevel", None
)
end_critical_level = getattr(
self.res1d.data.Nodes[reach.EndNodeIndex].__implementation__, "CriticalLevel", None
)
start_node = self.res1d.data.Nodes[reach.StartNodeIndex].__implementation__
end_node = self.res1d.data.Nodes[reach.EndNodeIndex].__implementation__
start_critical_level = getattr(start_node, "CriticalLevel", None)
end_critical_level = getattr(end_node, "CriticalLevel", None)

if (
start_critical_level is None
or np.isnan(start_critical_level)
or np.isinf(start_critical_level)
):
start_critical_level = getattr(start_node, "GroundLevel", None)

if (
end_critical_level is None
or np.isnan(end_critical_level)
or np.isinf(end_critical_level)
):
end_critical_level = getattr(end_node, "GroundLevel", None)

if start_critical_level is None or end_critical_level is None:
return np.nan

critical_slope = (end_critical_level - start_critical_level) / (
end_chainage - start_chainage
)

return start_critical_level + critical_slope * (chainage - start_chainage)

0 comments on commit 62fca31

Please sign in to comment.