I want to extract data from a pygrib.gribmessage
, and I would like to get it in 2-d arrays, but the data(...)
method returns 1-d arrays, and I don't know why. The GRIB file contains WRF data, if that's relevant, and the same problem occurs with any message that I select.
I try to select a geographical subset of data:
> data, lats, lons = grbmsg.data(lat1=52.94, lat2=54.02, lon1=11.05, lon2=12.28)
The resulting arrays are one-dimensional:
> data.shape, lats.shape, lons.shape
((726,), (726,), (726,))
When I don't specify the keyword arguments to data()
, the results are 2-d:
> data1, lats1, lons1 = grbmsg.data()
> data1.shape, lats1.shape, lons1.shape
((669, 859), (669, 859), (669, 859))
According to the pygrib docs:
If the grid type is unprojected lat/lon and a geographic subset is requested (by using the lat1,lat2,lon1,lon2 keywords), then 2-d arrays are returned, otherwise 1-d arrays are returned.
So I would expect to get 2-d data when I specify the lats/lons keywords.
I checked the expand_reduced
attribute; running grbmsg.expand_grid(True)
also does not change anything:
> grbmsg.expand_reduced
True
> grbmsg.expand_grid(True)
> grbmsg.expand_reduced
True
> data, lats, lons = grbmsg.data(lat1=52.94, lat2=54.02, lon1=11.05, lon2=12.28)
# still 1-d results
Am I missing something here? Or is my GRIB file corrupt, maybe? What else can I check?
I'm using pygrib==2.1.4
.