在 netcdf 文件中将所有变量和维度从 int/float 转换为 double [英] convert all the variables and dimensions from int/float to double in netcdf file

查看:71
本文介绍了在 netcdf 文件中将所有变量和维度从 int/float 转换为 double的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有以下内容的 netCDF 文件.ncdump:

I have a netCDF file with the foll. ncdump:

netcdf nc_data {
dimensions:
    lon = 1440 ;
    bounds = 2 ;
    lat = 720 ;
    time = UNLIMITED ; // (6 currently)
variables:
    double lon_bounds(lon, bounds) ;
    double lat_bounds(lat, bounds) ;
    int time(time) ;
        time:units = "year as %Y.%f" ;
        time:calendar = "proleptic_gregorian" ;
        time:long_name = "time" ;
        time:standard_name = "time" ;
        time:axis = "T" ;
    float lat(lat) ;
        lat:units = "degrees_north" ;
        lat:long_name = "latitude" ;
        lat:standard_name = "latitude" ;
        lat:axis = "Y" ;
        lat:bounds = "lat_bounds" ;
    float lon(lon) ;
        lon:units = "degrees_east" ;
        lon:long_name = "longitude" ;
        lon:standard_name = "longitude" ;
        lon:axis = "X" ;
        lon:bounds = "lon_bounds" ;
    float valf(time, lat, lon) ;
        valf: standard_name = "area_fraction"
        valf:missing_value = -9999.f ;
        valf:_fillvalue = -9999.f ;
        valf:long_name = "val fraction" ;
        valf:units = "fraction of grid cell" ;
}

是否有将所有变量和维度从 int/float 转换为 double 的 nco 命令?

Is there a nco command to convert all the variables and dimensions fro int/float to double?

我发现了这个:

ncap2 -s 'valf=double(valf)' nc_data.nc nc_data.nc

但是,这一次只能使用一个变量,而我的文件中有大约 30 个变量

However, this only works one variable at a time and I have ~30 variables in my file

推荐答案

ncap2 可以很好地做到这一点,尽管它需要当前的快照(很快就会变成 4.6.0).请注意,自 NCO 版本 4.5.3 起,您上面使用的命令不会更改输出文件中变量的类型,并且当前快照确实允许它工作.(ncap2 的临时版本要求输出变量的名称与输入变量的名称不同,以便更改其类型,例如 val_dbl=double(valf).

ncap2 can do this elegantly, though it requires the current snapshot (that will shortly become 4.6.0). Note that the command you used above does not change the type of the variable in the output file since NCO version 4.5.3, and the current snapshot does allow it to work. (Interim versions of ncap2 require that the output variable have a different name than the input in order to change its type, e.g., val_dbl=double(valf).

重要的是,ncap2 的当前快照理解变量列表.因此,您可以使用此脚本创建具有更改名称的某些变量的输出文件:

Importantly, the current snapshot of ncap2 understands variable lists. So you could create an output file of certain variables with altered names with this script:

@all=get_vars_in();
*sz=@all.size();

for(idx=0;idx<sz;idx++){

  @var_nm=sprint(@all(idx));

  if( *@var_nm.type() == NC_INT || *@var_nm.type() == NC_FLOAT )
   *@var_nm=*@var_nm.double();

}

不需要重命名变量.

这篇关于在 netcdf 文件中将所有变量和维度从 int/float 转换为 double的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆