Skip to content

Commit

Permalink
add testcase for the polyfile with 2*5 dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
MAfarrag committed Dec 23, 2024
1 parent 3e8ed26 commit a6a99c9
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
27 changes: 25 additions & 2 deletions hydrolib/core/dflowfm/polyfile/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,30 @@ class PolyObject(BaseModel):


class PolyFile(ParsableFileModel):
"""Poly-file (.pol/.pli/.pliz) representation."""
"""
Poly-file (.pol/.pli/.pliz) representation.
Notes:
- The `has_z_values` attribute is used to determine if the PolyFile contains z-values.
- The `has_z_values` is false by default and should be set to true if the PolyFile path ends with `.pliz`.
- The `***.pliz` file should have a 2*3 structure, where the third column contains the z-values, otherwise
(the parser will give an error).
- If there is a label in the file, the parser will ignore the label and read the file as a normal polyline file.
```
tfl_01
2 2
0.00 1.00 #zee
0.00 2.00 #zee
```
- if the file is .pliz, and the dimensions are 2*5 the first three columns will be considered as x, y, z values
and the last two columns will be considered as data values.
```
L1
2 5
63.35 12.95 -4.20 -5.35 0
45.20 6.35 -3.00 -2.90 0
```
"""

has_z_values: bool = False
objects: Sequence[PolyObject] = Field(default_factory=list)
Expand All @@ -106,7 +129,7 @@ def _get_serializer(cls) -> Callable:

@classmethod
def _get_parser(cls) -> Callable:
# TODO Prevent circular dependency in Parser
# Prevent circular dependency in Parser
from .parser import read_polyfile

return read_polyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
L1
2 5
63.35 12.95 -4.20 -5.35 0
45.20 6.35 -3.00 -2.90 0
22 changes: 22 additions & 0 deletions tests/dflowfm/polyfile/test_polyline_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,25 @@ def test_with_z_and_pliz_extension_2by3(self, polylines_dir: Path):
assert len(polyfile.objects[0].points) == 2
assert points[0] == Point(x=0, y=0, z=5, data=[])
assert points[1] == Point(x=0, y=2, z=5, data=[])

def test_with_z_and_pliz_extension_2by5(self, polylines_dir: Path):
"""
The test check a 2*5 polyline file with z values in the third and fourth columns, the extension is correct,
but the dimensions are 2*5.
```
L1
2 5
63.35 12.95 -4.20 -5.35 0
45.20 6.35 -3.00 -2.90 0
```
- The first three columns are the x, y, and z values.
The rest of the columns are the data values.
"""
path = polylines_dir / "leftsor-5-columns.pliz"
polyfile = PolyFile(path)
points = polyfile.objects[0].points
assert len(polyfile.objects[0].points) == 2
assert points[0] == Point(x=63.35, y=12.95, z=-4.2, data=[-5.35, 0])
assert points[1] == Point(x=45.2, y=6.35, z=-3, data=[-2.90, 0])

0 comments on commit a6a99c9

Please sign in to comment.