netcdf4 extract for subset of lat lon

前端 未结 7 789
时光取名叫无心
时光取名叫无心 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:47

    If you like pandas, then you should think about checking out xarray.

    import xarray as xr
    
    ds = xr.open_dataset('http://geoport.whoi.edu/thredds/dodsC/usgs/data2/rsignell/models/ncep/narr/air.2m.1980.nc',
                         decode_cf=False)
    lat_bnds, lon_bnds = [40, 43], [-96, -89]
    ds.sel(lat=slice(*lat_bnds), lon=slice(*lon_bnds))
    

提交回复
热议问题