I have a working program on an x86 linux machine that uses pynio to read grib2 files from NOAA's NBM product. A simplified version of the code looks like the following:
import Nio
f = Nio.open_file('foo.grib2', mode='r', options=None)
vars = list(f.variables)
When I print the list of variables, I get things like
APCP_P8_L1_acc1h
APCP_P9_L1_acc1h
APTMP_P0_L103
ASNOW_P8_L1_acc1h
CAPE_P0_L1
CAPE_P2_L1
CEIL_P0_L2
CEIL_P0_L215
CEIL_P5_L215
CEIL_probability2
DIST_P0_2L1_103
etc.
Now I have to port my program to an architecture (aarch64) that doesn't support the Nio
module, so I apparently have to use the cfgrib
module instead and began working with that today.
varlist = []
datasets = cfgrib.open_datasets('foo.grib2') # Opens a single file as a list of datasets
for ds in datasets:
for v in ds.variables:
varlist.append(v)
varlist = list(set(varlist)) # eliminate duplicate entries
This new list contains entries that look like:
aptmp
asnow
atmosphere
atmosphereSingleLayer
cape
ceil
cloudBase
cloudCeiling
cloudTop
d2m
dswrf
gust
h
heightAboveGround
heightAboveSea
etc.
The important points to note here are that
- There is no direct correspondence between variable names obtained using the two different methods;
- Multiple variables that I previously worked with (e.g.,
CEIL_P0_L2
,CEIL_P0_L215
,CEIL_P5_L215
) seem to correspond to recurrences of the variable (e.g.,ceil
) in different sub-datasets when I read the file withcfgrib
; - Other variable names show up (e.g.,
atmosphere
,atmosphereSingleLayer
) that seems to play a role other than as an actual numerical field. - A number of grid fields show up with the variable name
unknown
(not shown in partial listings above), and I have no idea how to figure out what these are, even printing all of the fields for the dataset.
My questions: Why are the variable names different, and, more importantly, how do I use cfgrib
to reliably identify and extract the fields corresponding to the original variable names as seen (or constructed?) by Nio
?
Caveat: The original Nio
program was last run on NBM files from nearly a year ago, whereas I'm running cfgrib
on files obtained from the same source in August 2021. I suppose the internal structure of these files could have changed in the interim, though that seems unlikely.