netcdf文件的修改变量属性

问题描述 投票:3回答: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 ;

        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
    

[我正在尝试修改netcdf文件中时间变量的日历类型,以从GREGORIAN更改为gregorian,因为我认为当我尝试在...内访问时间变量时,这会引起问题。] >>> < [

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

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)

我想您也可以使用cdo setcalendar命令对此进行排序:

cdo setcalendar,proleptic_gregorian in.nc out.nc

netcdf nco
3个回答
3
投票
您在ncatted参数周围放置的单引号会导致双引号变成文字,这不是您想要的。参数中没有文字,空格或特殊字符,因此请删除所有引号:

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)


0
投票
我想您也可以使用cdo setcalendar命令对此进行排序:

cdo setcalendar,proleptic_gregorian in.nc out.nc

© www.soinside.com 2019 - 2024. All rights reserved.