向 netcdf 文件添加一个随时间增加的新变量 nco [英] add a new variable to a netcdf file that increases with time nco

查看:63
本文介绍了向 netcdf 文件添加一个随时间增加的新变量 nco的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在现有的 netcdf 文件中添加一个新变量,该变量随文件的时间变量线性增加,也就是说,在第一个时间片上,该变量到处都是数字 1,在第二个时间片上,它是设置为 2 等

I want to add a new variable to an existing netcdf file which simply increases linearly with the time variable of file, that is to say, on the first time slice the variable has the number 1 everywhere, on the second timeslice it is set to 2, etc.

我知道如何在 python 或 fortran 中打开文件并定义和添加变量并写出修改后的文件,但我希望可能有一种使用 nco.我还想知道是否可以通过使用 ncdump 将文件转储为 CDL 格式,对其进行破解并使用 ncgen 将其转回 netcdf 来实现,但这似乎更加冗长且有问题比 python 方法.

I know how to open the file in python or fortran and define and add the variable and write out the modified file, but I was hoping that there might be a quick and easy way to do this from the command line using nco. I also wondered if I could do it by dumping the file to CDL format with ncdump, hacking it and turning it back to netcdf with ncgen, but that seemed more longwinded and problematic than the python approach.

推荐答案

对于一维数组使用这个

ncap2 -s 'var=array(1,1,$time)' in.nc out.nc

对于多维数组,只需将其添加到零数组

For multi-dimensional arrays just add that to the zero-array

ncap2 -s 'var=array(0,0,/$time,$lat,$lon/)+array(1,1,$time)' in.nc out.nc

数组的数值类型由数组函数的第一个参数的类型决定.有关详细信息,请参阅 array() 上的手册.

The numeric type of the array is determined by the type of the first argument to the array function. See the manual on array() for details.

这篇关于向 netcdf 文件添加一个随时间增加的新变量 nco的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆