次のように、GRIB ファイルを反復処理して目的のレコードを見つけ、データを取得する必要があります。
for g in grbs:
print g.shortName, g.typeOfLevel, g.level # print info about all GRIB records and check names
if (g.shortName == shortName and g.typeOfLevel == typeOfLevel and g.level == level):
tmp = np.array(g.values)
# now work with tmp as numpy array
緯度と経度の配列を取得するには、次を使用lt, ln = g.latlons()
しg
ますgrbs
。
https://software.ecmwf.int/wiki/display/GRIB/GRIB+API+examplesのセクション python の例を読んでください(pygrib はこのライブラリを使用して GRIB を読み取ります)。
大きな GRIB ファイルからデータを取得する最速の方法は、インデックスを作成することです。
# use attributes what you want to build index
indx = pygrib.index(gribfile,'typeOfLevel','level','parameterName')
# important: msg is an array and may have more then one record
# get U wind component on 10 m above ground
msg = indx.select(level = 10, typeOfLevel = "heightAboveGround",
parameterName = "U U-component of wind m s**-1")
u10 = np.array(msg[0].values)
# get V wind component on 10 m above ground
msg = indx.select(level = 10, typeOfLevel = "heightAboveGround",
parameterName = "V V-component of wind m s**-1")
v10 = np.array(msg[0].values)