2

uvIndexgrib2 ファイルに存在するすべての緯度経度を取得しようとしています。これは、ファイルを取得している場所からのリンクです。問題は、データを取得できるようにファイルの構造を理解できないことです。pygribファイルの読み取りに使用しています。

私が試したコードは次のとおりです。

grbs = pygrib.open('uv.t12z.grbf01.grib2')
grb = grbs.select(name='UV index')[0]
print grb.data(23.5,55.5)

私が達成しようとしているのは、すべての緯度経度を反復処理して対応する uvIndex 値を出力するか、緯度経度を入力して対応する値を取得することです。のドキュメントを読んでくださいが、pygrib私の目的に役立つ適切なコマンドが見つかりませんでした。助けてください。

4

1 に答える 1

3

次のように、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)
于 2016-06-03T10:53:01.017 に答える