Skip to content

Commit

Permalink
Merge pull request #214 from Deltares/feature/issue213
Browse files Browse the repository at this point in the history
added option to use None for headlines in referencelines dstability
  • Loading branch information
wfaustmann authored Jan 20, 2025
2 parents b72dce7 + 678fea4 commit 75a12a8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
10 changes: 5 additions & 5 deletions geolib/models/dstability/dstability_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,13 +671,13 @@ def add_head_line(
persistable_headline = waternet.add_head_line(
str(self._get_next_id()), label, notes, points, is_phreatic_line
)
return int(persistable_headline.Id)
return persistable_headline.Id

def add_reference_line(
self,
points: List[Point],
bottom_headline_id: int,
top_head_line_id: int,
bottom_headline_id: Optional[str] = None,
top_head_line_id: Optional[str] = None,
label: str = "",
notes: str = "",
scenario_index: Optional[int] = None,
Expand Down Expand Up @@ -708,8 +708,8 @@ def add_reference_line(
label,
notes,
points,
str(bottom_headline_id),
str(top_head_line_id),
bottom_headline_id,
top_head_line_id,
)
return int(persistable_reference_line.Id)

Expand Down
10 changes: 6 additions & 4 deletions geolib/models/dstability/internal.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,20 +169,22 @@ def add_reference_line(
label: str,
notes: str,
points: List[Point],
bottom_head_line_id: str,
top_head_line_id: str,
bottom_head_line_id: Optional[str] = None,
top_head_line_id: Optional[str] = None,
) -> PersistableReferenceLine:
reference_line = PersistableReferenceLine(
Id=reference_line_id, Label=label, Notes=notes
)
reference_line.Points = [PersistablePoint(X=p.x, Z=p.z) for p in points]

if not self.has_head_line_id(bottom_head_line_id):
if bottom_head_line_id is not None and not self.has_head_line_id(
bottom_head_line_id
):
raise ValueError(
f"Unknown headline id {bottom_head_line_id} for bottom_head_line_id"
)

if not self.has_head_line_id(top_head_line_id):
if top_head_line_id is not None and not self.has_head_line_id(top_head_line_id):
raise ValueError(
f"Unknown headline id {top_head_line_id} for top_head_line_id"
)
Expand Down
21 changes: 20 additions & 1 deletion tests/models/dstability/test_waternets.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def test_add_head_line(self):
label="TestHL", points=points, is_phreatic_line=True
)
headline = dsm.datastructure.waternets[0].get_head_line(str(headline_id))
assert isinstance(headline_id, int)
assert isinstance(headline_id, str)
assert pytest.approx(headline.Points[0].X) == -20.0
assert dsm.waternets[0].PhreaticLineId == headline.Id

Expand Down Expand Up @@ -53,3 +53,22 @@ def test_add(self):
bottom_headline_id=-1,
top_head_line_id=head_line_2_id,
)

@pytest.mark.unittest
def test_add_interpolation(self):
dsm = DStabilityModel()

points = [Point(x=-20.0, z=-2.0), Point(x=50.0, z=-2.0)]
_ = dsm.add_head_line(label="TestHL_1", points=points, is_phreatic_line=True)
head_line_2_id = dsm.add_head_line(
label="TestHL_2", points=points, is_phreatic_line=False
)

# adding valid reference line with interpolation
_ = dsm.add_reference_line(
label="TestRL",
points=points,
top_head_line_id=head_line_2_id,
)
assert dsm.waternets[0].ReferenceLines[0].BottomHeadLineId is None
assert dsm.waternets[0].ReferenceLines[0].TopHeadLineId == head_line_2_id

0 comments on commit 75a12a8

Please sign in to comment.