我有一个netcdf文件,在一个带有一个变量的网格上有大约100个timesteps,它是在timesteps上累积的。我现在感兴趣的是计算每个时间步对变量值的贡献(即连续时间步的差值)
目前,我使用以下顺序:
cdo seltimestep,$i ...
cdo sub $i ${i-1} ...
将每个差异计算到一个新文件中cdo mergetime ...
合并到一个结果文件中李>在我看来,这似乎是非常繁琐的和不理想的表现。由于时间步长太多,我无法使用cdo管道,因此需要同时创建许多文件
有没有更好的解决方案,可以用cdo(或其他类似nco/ncl的东西)将累积变量转换为时间步长值
如果要使用
cdo
,不需要所有这些循环和编写大量文件,只需使用函数deltat
:与python解决方案一样,这将比您使用的循环快几个数量级,并且具有作为命令行单行程序的优势
或者,更不简洁的是,如果您知道长度,您可以将这两个系列区别开来(我展示了这一点,因为这种技术在其他上下文中可能很有用):
累积字段上的Postscript强> 请注意,上面的解决方案和本页上发布的两个python解决方案产生的输出比输入少一个timestep,,即它们丢弃了第一个timestep。在某些情况下,例如,如果有一个模型通量场在预测中累积(似乎是这样),则不希望放弃第一个时间步(因为这是从预测开始时的零到第一步的累积)。在这种情况下,您可以提取第一步并将其插入文件的“前面”,如下所示:
您还应该确保对python解决方案也这样做
您可以将整个过程作为一个管道(有时管道可能会导致总线错误或seg故障,通常可以使用“-L”选项来执行顺序操作)
如果你有seg故障,试试这个
这是为了防止舍入和准确性问题,如果您有压缩数据(即键入NC_SHORT):
numpy's diff计算连续条目的差异
我怀疑您的文件中有一个多维变量,因此下面是一个通用示例:
^{} 是我在这方面的首选工具:
相关问题 更多 >
编程相关推荐