From 5ccf077016409c19f0970380f0d3263d4ee1c429 Mon Sep 17 00:00:00 2001 From: Luc DURON Date: Wed, 28 May 2025 11:33:08 +0200 Subject: [PATCH 1/4] Sync some fix from latest PyTelTools commits 1a32c40: Fix mesh_origin to int + build_params a719ed1: Change params(8) header nb_el to 0 --- xarray_selafin/Serafin.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/xarray_selafin/Serafin.py b/xarray_selafin/Serafin.py index 616fece..bac41df 100644 --- a/xarray_selafin/Serafin.py +++ b/xarray_selafin/Serafin.py @@ -120,7 +120,7 @@ class SerafinHeader: - nb_nodes_per_elem : number of nodes per element (= 3 in 2D and 6 in 3D) - nb_nodes_2d : number of 2D nodes (equals to `nb_nodes` in 2D) - - mesh_origin <(float, float)>: x and y shift to apply to written coordinates (set by `set_mesh_origin`) + - mesh_origin <(int, int)>: x and y shift to apply to written coordinates (set by `set_mesh_origin`) - x_stored : east written coordinates [shape = nb_nodes] - y_stored : north written coordinates [shape = nb_nodes] - x : east coordinates [shape = nb_nodes] (set by `_compute_mesh_coordinates`) @@ -177,7 +177,7 @@ def __init__(self, title="", format_type="SERAFIN ", lang=LANG, endian=">"): self.nb_nodes_per_elem = -1 self.nb_nodes_2d = -1 - self.mesh_origin = (0.0, 0.0) + self.mesh_origin = (0, 0) self.x_stored = None self.y_stored = None self.x = None @@ -240,11 +240,11 @@ def build_params(self): 1, 0, self.mesh_origin[0], - self.mesh_origin[0], + self.mesh_origin[1], 0, 0, self.nb_planes, - self.nb_elements, + 0, 0, 1, ) @@ -803,6 +803,7 @@ def from_triangulation(self, nodes, ikle, ipobo=None): self._compute_mesh_coordinates() self.ikle = ikle.flatten() self._build_ikle_2d() + self.build_params() if ipobo is None: self.build_ipobo() else: From 7338a7544dcecfa5f5096f77ed4038820938d135 Mon Sep 17 00:00:00 2001 From: Luc DURON Date: Wed, 28 May 2025 14:22:20 +0200 Subject: [PATCH 2/4] Fix tests (use actions/cache@v3) --- .github/workflows/run_tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml index 0cb6ca2..cc80ce8 100644 --- a/.github/workflows/run_tests.yml +++ b/.github/workflows/run_tests.yml @@ -41,7 +41,7 @@ jobs: - uses: "actions/setup-python@v2" with: python-version: "${{ matrix.python }}" - - uses: "actions/cache@v2" + - uses: "actions/cache@v3" id: "cache" with: path: "${{ env.pythonLocation }}" From 9dd562425beb5d9fe757ee75f35c46c24a2f1938 Mon Sep 17 00:00:00 2001 From: Luc DURON Date: Wed, 28 May 2025 15:20:47 +0200 Subject: [PATCH 3/4] 96b38ca: Prevent warning on SELAFIN file format --- xarray_selafin/Serafin.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/xarray_selafin/Serafin.py b/xarray_selafin/Serafin.py index bac41df..99e88ac 100644 --- a/xarray_selafin/Serafin.py +++ b/xarray_selafin/Serafin.py @@ -210,10 +210,10 @@ def _set_file_format_and_precision(self, file_format): If file format is not recognized, the file is expected to be simple precision """ self.file_format = bytes(file_format, SLF_EIT).ljust(8) - if file_format in ("SERAFIND", " D"): + if file_format in ("SERAFIND", "SELAFIND", " D"): self._set_as_double_precision() else: - if file_format not in (" ", "SERAFIN ", "SERAFINS", "SERAPHIN"): + if file_format not in ("SERAFIN ", "SERAFINS", "SELAFIN ", "SERAPHIN"): logger.warning( 'Format "%s" is unknown and is forced to "SERAFIN "' % file_format ) @@ -246,7 +246,7 @@ def build_params(self): self.nb_planes, 0, 0, - 1, + 0 if self.date is None else 1, ) def _build_ikle_2d(self): From 410a1c42a615cf2a8ffc1ccd5a0ff4fb6be1aa8d Mon Sep 17 00:00:00 2001 From: Luc DURON Date: Wed, 28 May 2025 15:23:53 +0200 Subject: [PATCH 4/4] 1fc6623: Add warning on invalid IPOBO array when reading from file --- xarray_selafin/Serafin.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/xarray_selafin/Serafin.py b/xarray_selafin/Serafin.py index 99e88ac..29b77ee 100644 --- a/xarray_selafin/Serafin.py +++ b/xarray_selafin/Serafin.py @@ -913,6 +913,9 @@ def from_file(self, file, file_size): file.read(4 * self.nb_nodes), dtype=np.dtype(np.int32).newbyteorder(self.endian), ) + # A valid IPOBO should not be equal to zero array + if not np.any(self.ipobo): + logger.warning("The IPOBO array seems corrupted (zeros array). Try to rebuild it with `build_ipobo()`.") file.read(4) # x coordinates