繁体   English   中英

替换 netcdf 变量并重写为新的 netcdf 文件

[英]replacing a netcdf variable and rewrite to a new netcdf file

任何人都可以帮助我解决以下问题。 我有一个具有以下维度和变量的 netcdf 文件:维度(大小):y(100)、n2(2)、x(100)、变量(维度):int64 valid_time()、int64 start_time()、float64 y( y), float64 y_bounds(y,n2), float64 x(x), float64 x_bounds(x,n2), int16 沉淀(y,x), int8 proj()

netcdf 包含一个用于沉淀的二维数组 (100,100)。 现在我有一个新的相同大小的二维数组 (100,100) 具有不同的值。 我想知道如何用新的数组替换 netcdf 中的数组并将其重写为新的 netcdf。 我尝试了以下代码,但它无法替换数组(它可以重写并将 file.nc 重命名为 newfile.nc 而不替换数组)

import xarray as xr
ds=xr.open_dataset('file.nc')
precip=ds.variables['precipitation']
precip=np.array(precip)
precip=new_array
ds.to_netcdf('newfile.nc')

你试过了吗

import xarray as xr
ds=xr.open_dataset('file.nc')
ds.variables['precipitation'] = new_array
ds.to_netcdf('newfile.nc)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM