gribfile='gfs20191010.0p25' #file containing 384 hours of forecast data for variable Geopotential Height
grbs=pygrib.open(gribfile)
grb1=grbs.select(name='Geopotential Height')[0:24]
day1 = grb1.values
When I run the above code I get the following error:
AttributeError: 'list' object has no attribute 'values'
The .values key will work when only selecting the first item in the list as shown below:
grb1 = grbs.select(name='Geopotential Height')[0]
But not when I do
grb1 = grbs.select(name='Geopotential Height')[0:24]
I understand that for the .values key the format is dict.values, but I cannot figure out how to retrieve the data within the first 24 list items. My goal is to take in the first 24 files for the selected variable (Geopotential Height) as a numpy array, but in order to do this I need to be able to extract the information contained in each file using .values.
I have been following documentation for pygrib found at: https://jswhit.github.io/pygrib/docs/
According to the documentation link you provided:
So, when you do this:
You are taking the result of
select
(which is a list), and then slicing that list (which yields another list). The sliced list is then bound togrb1
. Therefore, grb1 is a list ofgribmessage
instances.As the Pyhton exception states, a list does not have a
values
attribute. However, a singlegribmessage
, presumably, does.Not sure if this gets you closer to the result you're expecting, but you can use a list comprehension to get the
value
s from thegribmessage
instances in your list: