This archive contains answers to questions sent to Unidata support through mid-2025. Note that the archive is no longer being updated. We provide the archive for reference; many of the answers presented here remain technically correct, even if somewhat outdated. For the most up-to-date information on the use of NSF Unidata software and data services, please consult the Software Documentation first.
Hello! Thanks for reaching out. Apologies for the delay in responding. I've put together for you a short Jupyter notebook demonstration available on GitHub https://gist.github.com/dcamron/f55df1d59a8972c320ea1773416ce029 to highlight what interacting with GRIB files with pygrib can look like. Pygrib will return your output from `gribmessage.values` as a NumPy array or maskedarray. The corresponding latitudes and longitudes that come out of `gribmessage.latlons()` should mirror the shape of your data values and allow you to dig into plotting. Our python-training website https://unidata.github.io/python-training/) has various examples for using cartopy for map-style plots and displays! I hope this helps. If I didn't quite help with where you're at, don't hesitate to follow up and let me know and I should be able to respond to you much quicker this time! I may also take some time to update that notebook with a plotting example if it would help. Thanks again for reaching out. All the best, Drew > To whom this concerns, > > I have a few questions about using Python and the 'pygrib' library for > interacting with '.grib2' files. > > I'm trying to grab the hour, temperature, lat, lon, and precipitation values > from a .grib2 dataset. > > When printing a line in the dataset, output looks like this: > 38:Temperature:K (instant):lambert:isobaricInhPa:level 100000 Pa:fcst time 1 > hrs:from 20131206050 > > According to > http://www.himpactwxlab.com/home/how-to-wiki/write-grib2-data-with-pygrib#TOC-Get-values-associated-with-the-grib-message, > I can use '.select()' to grab keys then use '.values' to extract the values > from the respective keys. > > The problem is, I'm having trouble correctly hitting the right keys, and > pulling the correct values. For example, after selecting the 'Temperature' > key and printing out the values, the output is lists of lists of > temperatures. The output doesn't makes sense to me to graph it. > > How do I grab the right keys, and get the right values? > > Ticket Details =================== Ticket ID: KDL-157609 Department: Support Python Priority: Low Status: Closed =================== NOTE: All email exchanges with Unidata User Support are recorded in the Unidata inquiry tracking system and then made publicly available through the web. If you do not want to have your interactions made available in this way, you must let us know in each email you send to us.