From 08677c504ff90836c889e6f407ae8256dae24d85 Mon Sep 17 00:00:00 2001 From: Luc DURON Date: Sat, 2 Mar 2024 21:52:55 +0100 Subject: [PATCH 1/3] Fix ikle in test_from_scratch --- tests/io_test.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/io_test.py b/tests/io_test.py index 60a03a9..40f518b 100644 --- a/tests/io_test.py +++ b/tests/io_test.py @@ -133,7 +133,7 @@ def test_from_scratch(tmp_path): x = np.random.rand(100) y = np.random.rand(100) - ikle = Delaunay(np.vstack((x, y)).T).simplices + ikle = Delaunay(np.vstack((x, y)).T).simplices + 1 # IKLE tables are 1-indexed # Creating a minimal dataset ds = xr.Dataset( @@ -145,7 +145,6 @@ def test_from_scratch(tmp_path): "x": ("node", x), "y": ("node", y), "time": pd.date_range("2020-01-01", periods=10), - # Add "ikle2" or "ikle3" as required by your mesh }, ) ds.attrs["ikle2"] = ikle From 0c0b3fcc4350f4157b303034a1e49d6d80d3c752 Mon Sep 17 00:00:00 2001 From: Luc DURON Date: Sat, 2 Mar 2024 22:03:42 +0100 Subject: [PATCH 2/3] Fix header date missing (fix #20) --- xarray_selafin/xarray_backend.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/xarray_selafin/xarray_backend.py b/xarray_selafin/xarray_backend.py index 4f7fe8e..c7e6359 100644 --- a/xarray_selafin/xarray_backend.py +++ b/xarray_selafin/xarray_backend.py @@ -12,6 +12,9 @@ from xarray_selafin import Serafin +DEFAULT_DATE_START = (1900, 1, 1, 0, 0, 0) + + def compute_duration_between_datetime(t0, time_serie): return (time_serie - t0).astype("timedelta64[s]").astype(float) @@ -69,7 +72,7 @@ def write_serafin(fout, ds): date = datetime.strptime(first_date_str, '%Y-%m-%dT%H:%M:%S.%f') slf_header.date = attrgetter("year", "month", "day", "hour", "minute", "second")(date) except ValueError: - slf_header.date = (1900, 1, 1, 0, 0, 0) + slf_header.date = DEFAULT_DATE_START # Variables try: @@ -269,6 +272,8 @@ def open_dataset( is_2d = slf.header.is_2d # Prepare dimensions, coordinates, and data variables + if slf.header.date is None: + slf.header.date = DEFAULT_DATE_START times = [datetime(*slf.header.date) + timedelta(seconds=t) for t in slf.time] npoin2 = slf.header.nb_nodes_2d ndp3 = slf.header.nb_nodes_per_elem From 3bf6b8a42f21a8aaf2cbc297c71f312d1cb4fc65 Mon Sep 17 00:00:00 2001 From: Luc DURON Date: Sat, 2 Mar 2024 22:13:47 +0100 Subject: [PATCH 3/3] Add " " for SERAFIN file format --- xarray_selafin/Serafin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xarray_selafin/Serafin.py b/xarray_selafin/Serafin.py index 0f76d46..6522830 100644 --- a/xarray_selafin/Serafin.py +++ b/xarray_selafin/Serafin.py @@ -214,7 +214,7 @@ def _set_file_format_and_precision(self, file_format): if file_format in ("SERAFIND", " D"): self._set_as_double_precision() else: - if file_format not in ("SERAFIN ", "SERAFINS", "SERAPHIN"): + if file_format not in (" ", "SERAFIN ", "SERAFINS", "SERAPHIN"): logger.warning( 'Format "%s" is unknown and is forced to "SERAFIN "' % file_format )