在netcdf文件中重命名维度

时间:2018-06-04 07:27:25

标签: netcdf nco

我是nco的初学者,我希望对我的工作流程提出一些建议,并对我遇到的问题提供一些帮助。

我有these data,它包含两个不同时间步的3D盐度值:

dimensions:
    t = 780 ;
    z = 54 ;
    y = 450 ;
    x = 3600 ;
variables:
    double time(t) ;
        time:units = "days since 1-1-1 00:00:0.0" ;
    float level(z) ;
        level:units = "[m]" ;
    float lat(y) ;
    float lon(x) ;
    float salt(x, y, z) ;
        salt:units = "psu * 1000 + 35" ;
        salt:missingvalue = "-1.0E34" ;
        salt:longname = "salinity" ;

我想连接两个netcdf文件。

为此,我首先使用ncecat *.nc -O merged.nc

dimensions:
    record = UNLIMITED ; // (2 currently)
    t = 780 ;
    z = 54 ;
    y = 450 ;
    x = 3600 ;
variables:
    double time(record, t) ;
        time:units = "days since 1-1-1 00:00:0.0" ;
    float level(record, z) ;
        level:units = "[m]" ;
    float lat(record, y) ;
    float lon(record, x) ;
    float salt(record, x, y, z) ;
        salt:units = "psu * 1000 + 35" ;
        salt:missingvalue = "-1.0E34" ;
        salt:longname = "salinity" ;

现在变量time和维t是虚假的。因此,我使用ncks -O -x -v time merged.nc merged.nc删除了它们:

    record = UNLIMITED ; // (2 currently)
    y = 450 ;
    z = 54 ;
    x = 3600 ;
variables:
    float lat(record, y) ;
    float level(record, z) ;
        level:units = "[m]" ;
    float lon(record, x) ;
    float salt(record, x, y, z) ;
        salt:units = "psu * 1000 + 35" ;
        salt:missingvalue = "-1.0E34" ;
        salt:longname = "salinity" ;

现在,我想用record重命名维ncrename -d record,time merged.nc。该命令运行时没有错误或警告。但当我ncdump -h merged.nc时,我得到错误

  

ncdump:merged.nc:NetCDF:HDF错误

这是什么意思?我哪里做错了?

修改

按照Charlie Zender

发布的答案
ncecat -O -u time *.nc merged.nc
ncks -O -x -v time merged.nc merged.nc

结果:

dimensions:
    time = UNLIMITED ; // (2 currently)
    y = 450 ;
    z = 54 ;
    x = 3600 ;
    t = 780 ;
variables:
    float lat(time, y) ;
    float level(time, z) ;
        level:units = "[m]" ;
    float lon(time, x) ;
    float salt(time, x, y, z) ;
        salt:units = "psu * 1000 + 35" ;
        salt:missingvalue = "-1.0E34" ;
        salt:longname = "salinity" ;
    double time(time, t) ;
        time:units = "days since 1-1-1 00:00:0.0" ;

// global attributes:
        :history = "Tue Jun  5 09:08:25 2018: ncks -O -x -v time merged.nc merged.nc\nTue Jun  5 09:08:19 2018: ncecat -O -u time OFES_salt_mmean_607.nc OFES_salt_mmean_608.nc merged.nc" ;
        :NCO = "netCDF Operators version 4.7.4 (http://nco.sf.net)" ;
        :nco_openmp_thread_number = 1 ;

1 个答案:

答案 0 :(得分:4)

首先,我推荐的命令是

ncecat -O -u time *.nc merged.nc

这样就无需将record重命名为time。然后

ncks -O -x -v time merged.nc merged.nc

这有用吗?

回答编辑问题:

关于使用ncrename收到的错误,您可能遇到了here描述的netCDF4库错误。推荐的解决方案是转换为netCDF3,重命名,然后根据需要转换回netCDF4:

ncks -3 in.nc out.nc
ncrename -d record,time out.nc
ncks -4 out.nc out.nc