修改netcdf文件的变量属性

Modifying variable attribute of netcdf file

我正在尝试修改 netcdf 文件中时间变量的日历类型,以从 GREGORIAN 更改为 gregorian,因为我认为这会在我尝试访问时间时引起问题稍后分析中的变量。

        double Time(Time) ;
                Time:long_name = "Time" ;
                Time:units = "days since 1979-01-01 00:00:00" ;
                Time:cartesian_axis = "T" ;
                Time:calendar_type = "GREGORIAN" ;
                Time:calendar = "GREGORIAN" ;
                Time:bounds = "Time_bounds" ;
                Time:_ChunkSizes = 1 ;

        double Time(Time) ;
                Time:long_name = "Time" ;
                Time:units = "days since 1979-01-01 00:00:00" ;
                Time:cartesian_axis = "T" ;
                Time:calendar_type = "gregorian" ;
                Time:calendar = "gregorian" ;
                Time:bounds = "Time_bounds" ;
                Time:_ChunkSizes = 1 ;

我已经尝试使用 nco 函数 nccat,但我似乎无法获得正确的语法。我试过了:

ncatted -a 'calendar,time,o,c,"gregorian"' Ocean_v_1994_01.nc out.nc

我找到了一种使用 R 和 ncdf4 包执行此操作的方法。解决方案是:

library(ncdf4)
mydata <- nc_open("Ocean_v_1994_01.nc", write = TRUE)

ncatt_put(mydata, "Time", 'calendar', attval = 'gregorian', prec = 'text')
ncatt_put(mydata, "Time", 'calendar_type', attval = 'gregorian', prec = 'text')

# check result 
ncatt_get(mydata, "Time")

nc_sync(mydata)
nc_close(mydata)

您在 ncatted 参数两边放置的单引号导致双引号变成文字,这不是您想要的。您的论点中没有文字、空格或特殊字符,因此只需删除所有引号:

ncatted -a calendar,time,o,c,gregorian Ocean_v_1994_01.nc out.nc

我认为您也可以使用 cdo setcalendar 命令对其进行排序:

 cdo setcalendar,proleptic_gregorian in.nc out.nc