Open FlippingBinary opened 4 years ago
A pull request would be welcomed.
Normally, a GRIB file can be opened with
pygrib.open(filename)
and this works fine. It would be nice to be able to download a GRIB file and parse it withpygrib
without first saving it to disk. Thepygrib.fromstring()
function seems to do something similar, but it does not create a GRIB message iterator. It only handles a single GRIB message.
@FlippingBinary Hello, I recently met the same problem, and I've found a possible solution. As one GRIB message starts with b'GRIB'
and ends with b'7777'
, it is possible to split the bytes into several bytes sequences by finding all the b'7777GRIB'
in the bytes object, then using pygrib.fromstring()
to decode all the sequences and put all of them in one list, this may be a substitutive solution. Hope this may help you.
To save others time, here's an example of loading the first GRIB message from a GRIB byte string. data
contains multiple GRIB messages in a byte string.
index = data.find(b"7777GRIB")
first_message = data[: index + 4]
grb_message = pygrib.fromstring(first_message)
Normally, a GRIB file can be opened with
pygrib.open(filename)
and this works fine. It would be nice to be able to download a GRIB file and parse it withpygrib
without first saving it to disk. Thepygrib.fromstring()
function seems to do something similar, but it does not create a GRIB message iterator. It only handles a single GRIB message.