netCDF文件的写出

def netCDF_out(tp, dims, coords, filename):
    tp1 = []
    for key, value in tp.items():
        # print(key, xr.DataArray(value))
        tp1.append(xr.DataArray(value))
    tp1 = xr.concat(tp1, dim='date')
    output_file = f"文件路径\\{filename}.nc"
    tpv = xr.Variable(dims, tp1)
    tpset1 = xr.Dataset({filename: (dims, tpv)}, coords=coords)
    tpset1.to_netcdf(output_file)

tp是一个dictionary的名字, 可以用其它的代替, 只要略微修改取值的方法即可, 这里用到的库只有xarray

posted @ 2023-07-12 16:23  yccdu  阅读(34)  评论(0编辑  收藏  举报