2016-06-03 2 views
1

모든 lat, lng가 grib2 파일에있는 uvIndex을 얻으려고합니다. 이것은 파일을 가져 오는 곳의 link입니다. 문제는 파일의 구조를 이해할 수 없어 데이터를 얻을 수 없다는 것입니다. 파일을 읽으려면 pygrib을 사용하고 있습니다. 여기 grib2 파일의 위도 경도 값을 반복하는 방법은 무엇입니까?

내가 해봤 코드입니다 :

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

내가 달성하기 위해 노력하고있어 각국 위도 걷고를 반복하고 해당 uvIndex 값을 인쇄하거나 위도 길이를 입력하고 해당 값을 얻을 중 하나입니다 . pygrib의 문서를 읽었지만 내 용도에 맞는 적절한 명령을 찾을 수 없습니다. 도와주세요.

답변

2

당신은 여기에 같은 데이터를 얻을, 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 (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) 
관련 문제