Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle padding in netcdf3 translation #367

Merged
merged 3 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion kerchunk/netCDF3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions kerchunk/tests/test_netcdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 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"
latitudes = rootgrp.createVariable("lat", "f4", ("lat",))
longitudes = rootgrp.createVariable("lon", "f4", ("lon",))
Expand Down
Loading