【问题标题】:dimension called "time" exists, but variable "time" uses a different dimension存在称为“时间”的维度,但变量“时间”使用不同的维度
【发布时间】:2016-03-05 02:15:27
【问题描述】:

如何给这个特殊的 netCDF 文件一个合适的时间轴?

“时间”既作为维度又作为变量存在, 但是时间变量使用“序列\日期\数字”作为它的维度

有两个挑战: 1. 变量与维度的问题;和 2. "serial\ date\ number" 在某些系统上显示为空格(带有反斜杠分隔符),但在其他系统上显示为下划线("serial_date_number")。

netcdf 
dimensions:
 lon = 80 ;
 lat = 41 ;
 pres = 27 ;
 time = 12053 ;
 serial\ date\ number = 12053 ;
variables:
 double u_mjo(time, pres, lat, lon) ;
 double lon(lon) ;
 lon:units = "degrees_east" ;
 double lat(lat) ;
 lat:units = "degrees_north" ;
 double p_level(pres) ;
 p_level:units = "hPa" ;
 double time(serial\ date\ number) ;
 time:units = "days since 0000-01-01 00:00 UTC" ;
  ...

【问题讨论】:

    标签: netcdf nco


    【解决方案1】:

    这是对我有用的过程仅使用 NCO 命令(无 ncdump/手动编辑/ncgen 步骤):

    从 OPeNDAP 数据集中提取 4 个时间步到本地 netCDF 文件allfields.nc

       ncks -d time,0,3 -d serial_date_number,0,3
        http://weather.rsmas.miami.edu/repository/opendap/synth:100ae90b-71ac-4d38-add9-f8982a976322:L2FsbGZpZWxkcy5uYw==/entry
        -O allfields.nc
    

    time变量解压到单独的文件time.nc

    ncks -v time allfields.nc time.nc
    

    提取所有除了time 变量到一个单独的文件fixed.nc(这也删除了有问题的serial_date_number 维度`):

    ncks -C -x -v time allfields.nc fixed.nc
    

    将维度serial_data_number重命名为time

    ncrename -O -d serial_date_number,time time.nc
    

    将固定时间的文件追加到不带时间的文件中:

    ncks -A time.nc fixed.nc
    

    我在这个工作流程中使用和创建的文件可以在这里看到: http://geoport.whoi.edu/thredds/catalog/usgs/data2/rsignell/models/mapes/catalog.html

    【讨论】:

    • 是的。做得好。想不出比 Rich 更优雅的解决方案了。不知道下划线是怎么回事。我假设简单地将维度“serial_date_number”重命名为“time”会失败,因为“字符串匹配到正在使用的名称”。如果它有效,那会更优雅,但 netCDF 库会阻止它。不知道为什么重命名为相同大小的现有维度一定会失败,但确实如此。 cz
    【解决方案2】:

    将 original.nc 转换为 fixed.nc,解决这两个挑战的解决方案是(经过多次争论):

    # 1. extract time from the original.nc file to create a new file with only time:
     ncks -v time original.nc time.nc
    
    # 2. remove the time variable from original.nc (which removes the problematic `serial_date_number dimension`)
     ncks -C -x -v time original.nc fixed.nc
    
    #3. Fix the time.nc file manually, with a text editor:
     ncdump time.nc > time.txt   # dump netCDF to text
        ## text-edit time.txt to fix up header, 
        ## creating time = UNLIMITED ; // (12053 currently)
     ncgen -o newtime.nc < time.txt   # remake netCDF from text
    
    # 4. Finally, concatenate the new time variable file into fixed.nc
     ncks -A newtime.nc fixed.nc
    

    【讨论】:

      【解决方案3】:

      在 Ubuntu 14.04 上我能够做到:

      ncrename -v variable\ with\ whitespace,variable_with_whitespace filein.nc fileout.nc
      

      【讨论】:

      • 当然,但你能说得更具体一点吗?
      猜你喜欢
      • 1970-01-01
      • 2020-12-16
      • 2023-03-26
      • 2011-06-23
      • 1970-01-01
      • 2021-03-06
      • 1970-01-01
      • 2022-01-19
      • 1970-01-01
      相关资源
      最近更新 更多