Skip to content

Commit

Permalink
Merge pull request #390 from martindurant/cdf3_version
Browse files Browse the repository at this point in the history
Infer netCDF3 version
  • Loading branch information
martindurant authored Nov 7, 2023
2 parents cd0f414 + 0b4e2c5 commit fa74e51
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions kerchunk/netCDF3.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,18 @@ def __init__(
self.out = {}
self.storage_options = storage_options
with fsspec.open(filename, **(storage_options or {})) as fp:
magic = fp.read(4)
assert magic[:3] == b"CDF"
version = magic[3]
fp.seek(0)
super().__init__(
fp, *args, mmap=False, mode="r", maskandscale=False, **kwargs
fp,
*args,
mmap=False,
mode="r",
maskandscale=False,
version=version,
**kwargs,
)
self.filename = filename # this becomes an attribute, so must ignore on write

Expand Down Expand Up @@ -187,7 +197,8 @@ def translate(self):
compression=None,
)
part = ".".join(["0"] * len(shape)) or "0"
out[f"{dim}/{part}"] = [self.filename] + [
out[f"{dim}/{part}"] = [
self.filename,
int(self.chunks[dim][0]),
int(self.chunks[dim][1]),
]
Expand Down

0 comments on commit fa74e51

Please sign in to comment.