I have gridded datasets in .nc format. I want to extract data on the basis of latitude and longitude. Latitude and longitude of my datasets are shown below:
import netCDF4
from netCDF4 import Dataset
f= Dataset('data.nc')
f.variables['lat'][:]
array([ 31.5, 30.5, 29.5, 28.5, 27.5, 26.5, 25.5, 24.5, 23.5,
22.5, 21.5, 20.5, 19.5, 18.5], dtype=float32)
f.variables['lon'][:]
array([ 60.5, 61.5, 62.5, 63.5, 64.5, 65.5, 66.5, 67.5, 68.5,
69.5, 70.5, 71.5, 72.5, 73.5, 74.5, 75.5, 76.5, 77.5,
78.5, 79.5, 80.5, 81.5, 82.5, 83.5, 84.5, 85.5, 86.5,
87.5, 88.5, 89.5, 90.5, 91.5], dtype=float32)
suppose I want to extract the data for lat = 29.5 and lon = 65.5 then which code is correct?
f.variables['temp'][:,2,5]
or
f.variables['temp'][:,29.5,65.5]
yours suggestion will be highly appreciated!