我有一个netCDF文件monthly_qc_data.nc
,它在0.5º的边界框中表示一个调用Lai_500m
的参数的月值。
考虑到边界框/netCDF文件的中心是参考点。我想计算参数Lai_500m
与此参数在边界框中心的值之间的差值。
为此,我使用以下代码:
##SPATIAL VARIANCE
os.chdir(inbasedir)
data = xr.open_dataset('monthly_qc_data.nc')
ref_data = data.where((data['lat'] == 10) & (data['lon'] == 10)) #considering the poin lat:10 and lon:10 as the center of the bounding box
dif_data = data.where((data['Lai_500m'] - ref_data))
不幸的是,这将返回以下错误:
ufunc 'bitwise_and' not supported for the input types, and the inputs could not be
safely coerced to any supported types according to the casting rule ''safe''
我还尝试使用python netCDF4:
from netCDF4 import Dataset
os.chdir(inbasedir)
dataset = Dataset("monthly_qc_data.nc")
dif_data = dataset.variables['Lai_500m'][:,:,:] - dataset.variables['Lai_500m'][:,10,10]
谁也返回了(明显的)错误:
ValueError: operands could not be broadcast together with shapes (12,120,120) (12,)
有谁知道如何克服这个问题吗?
发布于 2019-03-01 06:34:34
您应该能够以浮点型的形式获取ref_data,然后从数据集中减去。
ref_data = float(data.Lai_500m.sel(lat=10.0, lon=10.0).values)
dif_data = data.Lai_500m - ref_data
发布于 2019-03-03 04:33:55
我知道您正在寻找python的答案,但为了以防万一,下面是如何使用cdo从命令行执行相同功能的方法:
cdo sub in.nc -remapnn,lon=10/lat=10 in.nc diff.nc
https://stackoverflow.com/questions/54928140
复制相似问题