修改netcdf文件的变量属性

3
我试图修改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 ;

to

        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

1
在此期间,我建议为“Time”变量添加一个“standard_name”属性,并将属性值设置为“time”。 - alani
3个回答

3
您在 ncatted 参数周围放置的单引号导致双引号变成字面量,这不是您想要的。 在您的参数中没有文字,空格或特殊字符,因此只需删除所有引号即可:

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

太棒了,谢谢!稍作修改,将 time 改为 Time 即可使其正常运行。 - Hayden

2
我找到了一种使用 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)

1
我认为您也可以使用cdo setcalendar命令对此进行排序:
 cdo setcalendar,proleptic_gregorian in.nc out.nc

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接