是否有与 xarray 函数等效的 netCDF4 来从 netCDF 文件中选择纬度和特定时间范围的值:
hndl_nc.sel(time=slice(start_date, end_date)).sel(lon=lon, lat=lat, method='nearest')
我不想使用 cdo 或 nco
根据您的特定数据集会有差异,但是像这样的函数应该在特定坐标和时间片上提取值:
def variable_pull(site_lat, site_lon, lat, lon, var, time_slice):
lat_idx = (np.abs(lat-site_lat)).argmin()
lon_idx = (np.abs(lon-site_lon)).argmin()
return var[time_slice, lat_idx, lon_idx]
对于使用 netCDF4 打开的数据集,与此类似:
f = ncdf.Dataset("filepath","r")
lat = f.variables['lat'][:]
lon = f.variables['lon'][:]
var = f.variables['var'][:]
f.close()
site_lat = your coordinates of interest
site_lon = your coordinates of interest
values = variable_pull(site_lat, site_lon, lat, lon, var, time_slice)