-
Notifications
You must be signed in to change notification settings - Fork 78
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
Is it possible to open a GRIB2 message from a bytes
instance?
#326
Comments
I'd also be very interested in this - I have a custom class implementing |
Hello, I agree this would be a useful feature. It's not there yet, but perhaps in the meantime you could be interested in trying our new package 'earthkit-data', which does enable this. In fact, it uses cfgrib in the background, so the xarray dataset will be the same. Warning: earthkit-data is currently beta, and not yet for operational use, but it is available on PyPi and conda-forge. It has the same dependency on ecCodes that cfgrib has. https://github.com/ecmwf/earthkit-data Here's an example of how to create a bytes object (which you already have) and create an xarray from it. I should mention that this method does not create any temporary file (that would be cheating!).
If you need to pass any kwargs to cfgrib, this shows how: Best regards, |
Kerchunk does this: https://github.com/fsspec/kerchunk/blob/main/kerchunk/grib2.py import eccodes
import cfgrib
data # type: bytes
mid = eccodes.codes_new_from_message(data)
m = cfgrib.cfmessage.CfMessage(mid) |
Hi, I have a GRIB2 message as a byte array in memory (
bytes
type). Is it possible to open it with cfgrib without writing it to disk first?I tried
cfgrib.open_dataset
andcfgrib.open_file
. I also tried passingio.BytesIO
instance of my byte array with no success.This is cfgrib-0.9.10.3 with eccodes-2.16.0 on Ubuntu 20.04 LTS.
Thank you!
The text was updated successfully, but these errors were encountered: