netcdf4 extract for subset of lat lon

前端 未结 7 850
时光取名叫无心
时光取名叫无心 2020-11-30 06:56

I would like to extract a spatial subset of a rather large netcdf file. From Loop through netcdf files and run calculations - Python or R

from pylab import          


        
7条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-30 07:29

    Small change needs to be made to the lonbounds part (data are degrees east), because the longitude value ranges from 0 to 359 in the data, so negative numbers will not work in this case. Also the calculation for latli and latui needs to be switched because the value goes from north to south, 89 to -89.

    latbounds = [ 40 , 43 ]
    lonbounds = [ 260 , 270 ] # degrees east
    lats = f.variables['latitude'][:] 
    lons = f.variables['longitude'][:]
    
    # latitude lower and upper index
    latli = np.argmin( np.abs( lats - latbounds[1] ) )
    latui = np.argmin( np.abs( lats - latbounds[0] ) ) 
    
    # longitude lower and upper index
    lonli = np.argmin( np.abs( lons - lonbounds[0] ) )
    lonui = np.argmin( np.abs( lons - lonbounds[1] ) )  
    

提交回复
热议问题