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
标签:文件,tp,filename,dims,写出,netCDF,tp1,xr,coords From: https://www.cnblogs.com/gaojunonly1/p/17547843.html