From 34a1aa61b5312f7f5b10e7ae517a203520112e92 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 30 Oct 2026 12:51:57 +0000 Subject: [PATCH 1/2] Initial plan From f907f97e8de0f0b2f807959fc7e8dbabcf2e719f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 30 Oct 2026 12:53:56 +0000 Subject: [PATCH 2/2] Normalize NC_STRING custom dimensions Co-authored-by: f-brinkmann <58219902+f-brinkmann@users.noreply.github.com> --- sofar/io.py | 2 ++ sofar/sofastream.py | 2 ++ tests/test_io.py | 11 +++++++++++ 3 files changed, 15 insertions(+) diff --git a/sofar/io.py b/sofar/io.py index 98bc783..b328856 100644 --- a/sofar/io.py +++ b/sofar/io.py @@ -177,6 +177,8 @@ def _read_netcdf(filename, verify, verbose, mode): # (the datatype of 'string' is a VLType but its dtype is str) if file[var].dtype in ["S1", str]: dtype = "string" + if file[var].dtype is str: + dimensions += "S" else: dtype = "double" sofa._add_custom_api_entry(var.replace(".", "_"), value, None, diff --git a/sofar/sofastream.py b/sofar/sofastream.py index ee93dc3..61a0efb 100644 --- a/sofar/sofastream.py +++ b/sofar/sofastream.py @@ -216,6 +216,8 @@ def _read_open_file_for_verification(self): setattr(sofa, key, value) else: dimensions = "".join(list(netcdf_variable.dimensions)) + if netcdf_variable.dtype is str: + dimensions += "S" sofa._add_custom_api_entry( key, value, None, dimensions, dtype) sofa.protected = False diff --git a/tests/test_io.py b/tests/test_io.py index c42ef74..b36cb5d 100644 --- a/tests/test_io.py +++ b/tests/test_io.py @@ -333,6 +333,17 @@ def test_read_netcdf_string(): assert sofa_r.SourcePosition_Comment == text assert sofa_r.CustomStrings == text assert sofa_r._convention["CustomStrings"]["type"] == "string" + assert sofa_r._convention["CustomStrings"]["dimensions"] == "MS" + + with sf.SofaStream(file) as streamed_sofa: + streamed = streamed_sofa._read_open_file_for_verification() + assert streamed._convention["CustomStrings"]["dimensions"] == "MS" + + roundtrip_file = os.path.join(temp_dir.name, "roundtrip.sofa") + sf.write_sofa(roundtrip_file, sofa_r) + sofa_roundtrip = sf.read_sofa(roundtrip_file, verify=False, verbose=False) + assert sofa_roundtrip.CustomStrings == text + assert sofa_roundtrip._convention["CustomStrings"]["dimensions"] == "MS" def test_format_value_for_netcdf():