From a6a99c9b111fedd4870d1d9975e312ab5ec9cf18 Mon Sep 17 00:00:00 2001 From: Mostafa Farrag Date: Mon, 23 Dec 2024 17:23:14 +0100 Subject: [PATCH] add testcase for the polyfile with 2*5 dimensions --- hydrolib/core/dflowfm/polyfile/models.py | 27 +++++++++++++++++-- .../polylines/leftsor-5-columns.pliz | 4 +++ .../dflowfm/polyfile/test_polyline_models.py | 22 +++++++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 tests/data/input/dflowfm_individual_files/polylines/leftsor-5-columns.pliz diff --git a/hydrolib/core/dflowfm/polyfile/models.py b/hydrolib/core/dflowfm/polyfile/models.py index 41a7254ee..c84cfc879 100644 --- a/hydrolib/core/dflowfm/polyfile/models.py +++ b/hydrolib/core/dflowfm/polyfile/models.py @@ -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) @@ -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 diff --git a/tests/data/input/dflowfm_individual_files/polylines/leftsor-5-columns.pliz b/tests/data/input/dflowfm_individual_files/polylines/leftsor-5-columns.pliz new file mode 100644 index 000000000..a3006d269 --- /dev/null +++ b/tests/data/input/dflowfm_individual_files/polylines/leftsor-5-columns.pliz @@ -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 diff --git a/tests/dflowfm/polyfile/test_polyline_models.py b/tests/dflowfm/polyfile/test_polyline_models.py index e1241910f..4a8bb4d83 100644 --- a/tests/dflowfm/polyfile/test_polyline_models.py +++ b/tests/dflowfm/polyfile/test_polyline_models.py @@ -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])