From 9172468d8b0ecf3beabc00d790588052e7ee8204 Mon Sep 17 00:00:00 2001 From: Matt Iannucci Date: Mon, 2 Oct 2023 08:34:19 -0400 Subject: [PATCH 1/3] Fix padding in netcdf3 translation --- kerchunk/netCDF3.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/kerchunk/netCDF3.py b/kerchunk/netCDF3.py index a3b0c58f..200159d1 100644 --- a/kerchunk/netCDF3.py +++ b/kerchunk/netCDF3.py @@ -207,9 +207,15 @@ def translate(self): outer_shape = size // dt.itemsize offset = start for name in dt.names: + dtype = dt[name] + + # Skip padding, but increment offset. + if name.startswith("_padding_"): + offset += dtype.itemsize + continue + # the order of the names if fixed and important! var = self.variables[name] - dtype = dt[name] base = dtype.base # actual dtype shape = (outer_shape,) + dtype.shape From 7950191b8b15e6345e5d4e4f816fa2506bc38266 Mon Sep 17 00:00:00 2001 From: Matt Iannucci Date: Mon, 2 Oct 2023 13:55:36 -0400 Subject: [PATCH 2/3] Add test case --- kerchunk/tests/test_netcdf.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/kerchunk/tests/test_netcdf.py b/kerchunk/tests/test_netcdf.py index 8df0d919..70c6fda3 100644 --- a/kerchunk/tests/test_netcdf.py +++ b/kerchunk/tests/test_netcdf.py @@ -45,6 +45,11 @@ def unlimited_dataset(tmpdir): rootgrp.createDimension("lat", 10) rootgrp.createDimension("lon", 5) rootgrp.createVariable("time", "f8", ("time",)) + # reference time is an unbounded dimension that is a half byte long, so it + # has padding to line up to be take up exactly one byte. It is here to test that + # kerchunk can handle the padding correctly and still read following variables + # correctly. + rootgrp.createVariable("reference_time", "h", ("time",)) rootgrp.title = "testing" latitudes = rootgrp.createVariable("lat", "f4", ("lat",)) longitudes = rootgrp.createVariable("lon", "f4", ("lon",)) From 7d2fe2340e91b904ddb6050ef4e651f2acea3093 Mon Sep 17 00:00:00 2001 From: Matt Iannucci Date: Mon, 2 Oct 2023 14:00:51 -0400 Subject: [PATCH 3/3] Clean up grammer, trailing whitespace --- kerchunk/tests/test_netcdf.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/kerchunk/tests/test_netcdf.py b/kerchunk/tests/test_netcdf.py index 70c6fda3..baca317a 100644 --- a/kerchunk/tests/test_netcdf.py +++ b/kerchunk/tests/test_netcdf.py @@ -45,9 +45,9 @@ def unlimited_dataset(tmpdir): rootgrp.createDimension("lat", 10) rootgrp.createDimension("lon", 5) rootgrp.createVariable("time", "f8", ("time",)) - # reference time is an unbounded dimension that is a half byte long, so it - # has padding to line up to be take up exactly one byte. It is here to test that - # kerchunk can handle the padding correctly and still read following variables + # reference time is an unbounded dimension that is a half byte long, so it + # has padding to line up to take up exactly one byte. It is here to test that + # kerchunk can handle the padding correctly and read following variables # correctly. rootgrp.createVariable("reference_time", "h", ("time",)) rootgrp.title = "testing"