【问题标题】:Cannot modify specific variable values over a specific dimension in netcdf无法修改 netcdf 中特定维度上的特定变量值
【发布时间】:2017-03-21 17:03:26
【问题描述】:

我有一个包含 4-D 变量的 netcdf 文件:

variables:
    double maxvegetfrac(time_counter, veget, lat, lon) ;
        maxvegetfrac:_FillValue = 1.00000002004088e+20 ;
        maxvegetfrac:history = "From Topo.115MaCTRL_WAM_360_180" ;
        maxvegetfrac:long_name = "Vegetation types" ;
        maxvegetfrac:missing_value = 1.e+20f ;
        maxvegetfrac:name = "maxvegetfrac" ;
        maxvegetfrac:units = "-" ;

    double mask_veget(time_counter, veget, lat, lon) ;
        mask_veget:missing_value = -1.e+34 ;
        mask_veget:_FillValue = -1.e+34 ;
        mask_veget:long_name = "IF MYVEG4 EQ 10 AND I GE 610 AND J GT 286 THEN 16 ELSE MYVEG4" ;
        mask_veget:history = "From desert_115Ma_3" ;

我想使用变量“mask_veget”作为掩码来改变变量“maxvegetfrac”在特定区域的值,以及其“veget”维度的选定值。 为此,我正在使用 ncap2。例如,如果我想将第 5 级 veget 维度的 maxvegetfrac 值设置为 500,其中 mask_veget 等于 6,我会这样做:

> ncap2 -s "where (mask_veget(:,:,:,:)== 6) maxvegetfrac(:,5,:,:) = 500" test.nc

我的问题是,在生成的 test.nc 文件中,maxvegetfrac 已在“veget”维度的第一级被修改,而不是第五个。如果我在整个植物维度上运行脚本,我会得到相同的结果:

ncap2 -s "where (mask_veget(:,:,:,:)== 6) maxvegetfrac(:,:,:,:) = 500" test.nc

所以我在某个地方弄错了,但是……在哪里? 任何帮助表示赞赏!

【问题讨论】:

    标签: netcdf netcdf4 nco


    【解决方案1】:

    您可能不知道的几件事 您不应该在 where 正文中对变量进行超切片 - 目前没有任何意义。

    可以在 where 语句中使用 hyperslab 来证明其单个索引 作为具有单个值的暗淡折叠

    试试这个:

    /*** hyper.nco *****/ 
    maxvegetfrac5=maxvegetfrac(:,5,:,:);
    
    where( mask_veget(:,5,:,:)== 6 )
       maxvegetfrac5=500.0;
    
    /* put the hyperslab back in */
    maxvegetfrac(:,5,:,:)=maxvegetfrac5;
    /* script end *****/   
    

    现在使用命令运行脚本

    ncap2 -v -O -S hyper.nco test.nc out.nc
    

    ...亨利

    【讨论】:

      猜你喜欢
      • 2018-03-30
      • 2020-06-21
      • 1970-01-01
      • 2016-07-04
      • 2018-09-29
      • 2018-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多