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

Allow for small GRIB files #451

Merged
merged 7 commits into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 1 addition & 3 deletions kerchunk/grib2.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,11 @@ def _split_file(f: io.FileIO, skip=0):
while f.tell() < size:
logger.debug(f"extract part {part + 1}")
head = f.read(1024)
if len(head) < 1024:
break # EOF
if b"GRIB" not in head:
f.seek(-4, 1)
continue
ind = head.index(b"GRIB")
start = f.tell() - 1024 + ind
start = f.tell() - len(head) + ind
part_size = int.from_bytes(head[ind + 12 : ind + 16], "big")
f.seek(start)
yield start, part_size, f.read(part_size)
Expand Down
2 changes: 1 addition & 1 deletion kerchunk/tests/test_combine.py
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ def test_cftimes_to_normal(refs):
engine="zarr",
chunks={},
)
assert z.time.dtype == "M8[s]"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what coo_dtypes does, but Xarray definitely normalizes everything to ns. Perhaps a bug was inadvertently fixed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I'm not sure what coo_dtypes does, either, but it seems to no longer be doing what is expected with the latest version of Xarray.

assert z.time.dtype.kind == "M"
assert (
z.time.values
== np.array(["1970-02-01T00:00:00", "1970-03-01T00:00:00"], dtype="M8[s]")
Expand Down
Loading