在使用NCL處理nc文件時(shí),
如果是wrfout結(jié)果,可以用“wrf_ij_to_ll”、“wrf_ll_to_ij ”或者“wrf_user_xy_to_ll”函數(shù)找到距離特定位置(如觀測(cè)點(diǎn))對(duì)應(yīng)的網(wǎng)格文件中最近的網(wǎng)格點(diǎn);
如果是普通的netcdf文件,可能用distance和nearest關(guān)鍵字找不到想要的函數(shù),ncl在介紹時(shí)用了“closest”關(guān)鍵字。我們簡(jiǎn)單看一下兩個(gè)函數(shù)的差異:
wrf_ll_to_ij : Finds the nearest model grid indices (i,j) to the specified location(s) in longitude and latitude (deprecated). 翻譯為:查找經(jīng)度和緯度到指定位置最近的模型網(wǎng)格索引(i,j)。(不建議使用,6.6版本ncl建議使用更新的wrf_user_xy_to_ll等函數(shù))。
getind_latlon2d :Returns the indices (subscripts) of two-dimensional latitude/longitude arrays closest to a user-specified latitude/longitude coordinate pair.? 翻譯為:返回最接近用戶(hù)指定的緯度/經(jīng)度坐標(biāo)對(duì)的二維緯度/經(jīng)度數(shù)組的索引(下標(biāo))。
還有個(gè)特殊的重要問(wèn)題:有的矩形網(wǎng)格的nc文件中,lat和lon是線(xiàn)性變化的,所以是一緯數(shù)組。而上述函數(shù)使用的是二維數(shù)組作為被查閱的數(shù)據(jù),這時(shí)候就要將一維的數(shù)據(jù)轉(zhuǎn)換為二維數(shù)據(jù),方法如下:
? ? ? ? nlat_1d = dimsizes(lat_1d)
nlon_1d = dimsizes(lon_1d)
lat2d = conform_dims((/nlat_1d(0),nlon_1d(0)/),lat_1d,0) ;構(gòu)建netcdf文件二維經(jīng)緯度
lon2d = conform_dims((/nlat_1d(0),nlon_1d(0)/),lon_1d,1)
構(gòu)建好了就可以使用上述找最近距離的函數(shù)了。