How to include static variable with time varying variables in a netCDF file using Climate Data Operator (CDO)?

huangapple go评论54阅读模式
英文:

How to include static variable with time varying variables in a netCDF file using Climate Data Operator (CDO)?

问题

我有两个netCDF文件。一个文件elevation.nc仅包含区域的'elevation'。另一个文件climate.nc具有('lat', 'lon', 'prcp', 'temp')。我已经使用以下命令:

cdo merge elevation.nc climate.nc merged.nc

merge.nc文件仅包含了elevation记录日期的单一prcptemp

如何在merged.nc中获取与climate.nc类似的变化的prcptemp,同时还包括静态变量elevation

英文:

I have two netCDF files. One file elevation.nc contains just the 'elevation' of an area. Other file climate.nc has ('lat', 'lon','prcp', 'temp'). I have used the following:

cdo merge  elevation.nc climate.nc merged.nc

The merge.nc file only has on single prcp and temp from the date that the elevation had been recorded.

How to get time varying prcp and temp in merged.nc similar to climate.nc but also with the static variable elevation?

答案1

得分: 1

只需要将输入文件的顺序颠倒,以确保多步文件是第一个输入文件,因为cdo从中获取维度。所以这将起作用:

cdo merge climate.nc elevation.nc merged.nc

如果你按“错误”的顺序执行(即首先是单个时间步输入文件),cdo会明确告诉你一个警告,它会截断时间相关文件的所有剩余步骤,以匹配第一个输入文件:

cdo    merge (Warning): Input stream 1 has 1 timestep. Stream 2 has more timesteps, skipped!

将输入顺序颠倒,使最长的输入文件首先,一切都正常,不会出现警告。

英文:

You only need to reverse the order of the input files to ensure that the multi-step file is the first input file as cdo takes the dimensions from that. So this would work:

cdo merge climate.nc elevation.nc merged.nc

If you do it in the "wrong" order (i.e. the single timestep input file first) cdo explicitly tells you in a warning that it is chopping off all the remaining steps of the time-dependent file in order to match the first input file:

cdo    merge (Warning): Input stream 1 has 1 timestep. Stream 2 has more timesteps, skipped!

Reversing the input order to have the longest input file first, everything works fine and no warning is given.

答案2

得分: 1

主要问题是发现 elevation.nc 具有单个时间步属性。在合并之前,必须删除此属性。因此,以下步骤将涉及(使用 nco 中的 ncks):

ncwa -a time elevation.nc test1.nc
ncks -O -x -v time test1.nc test2.nc # 移除时间属性
ncks -A -v hgt test2.nc climate.nc # 将 hgt 或 elevation.nc 附加到 climate.nc
英文:

the main issue was found to be that the elevation.nc has a single time step attribute. It is essential to remove this attribute before the merge. hence, the steps shall involve (using ncks from nco):

ncwa -a time elevation.nc test1.nc
ncks -O -x -v time test1.nc test2.nc #removing the time attribute
ncks -A -v hgt test2.nc  climate.nc #appending the hgt or elevation.nc with climate.nc

答案3

得分: 1

这将更加简洁,但您需要测试以确保其按预期工作:

ncwa -O -x -v time -a time elevation.nc test1.nc
ncks -A -v hgt test1.nc climate.nc
英文:

This would be more concise, though you'll have to test it to be sure it works as expected:

ncwa -O -x -v time -a time elevation.nc test1.nc
ncks -A -v hgt test1.nc climate.nc

huangapple
  • 本文由 发表于 2023年2月16日 17:34:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/75470299.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定