提取 NetCDF 变量并创建新的 NetCDF

Extract NetCDF Variable and create New NetCDF

我在处理 NetCDF 文件方面需要一些帮助。我总共有 10 个文件,分别为 10 年。每年都有多个(相同的)变量,其中一些还涵盖每日值。在这里,我向您展示一个结构示例:

(base) thess2ice@local:rhone_smb_modelling $ ncdump -h Rhone_AWS_1990.nc
netcdf Rhone_AWS_1990 {
dimensions:
    x = 402 ;
    y = 852 ;
    time = 1460 ;
variables:
    double x(x) ;
        x:_FillValue = NaN ;
        x:standard_name = "x" ;
        x:long_name = "longitude" ;
        x:units = "degrees_east" ;
    double y(y) ;
        y:_FillValue = NaN ;
        y:standard_name = "y" ;
        y:long_name = "latitude" ;
        y:units = "degrees_north" ;
    float HGT(y, x) ;
        HGT:_FillValue = -9999.f ;
        HGT:units = "m" ;
        HGT:long_name = "Elevation" ;
    float ASPECT(y, x) ;
        ASPECT:_FillValue = -9999.f ;
        ASPECT:units = "degrees" ;
        ASPECT:long_name = "Aspect of slope" ;
    float SLOPE(y, x) ;
        SLOPE:_FillValue = -9999.f ;
        SLOPE:units = "degrees" ;
        SLOPE:long_name = "Terrain slope" ;
    float MASK(y, x) ;
        MASK:_FillValue = -9999.f ;
        MASK:units = "boolean" ;
        MASK:long_name = "Glacier mask" ;
    int64 time(time) ;
        time:units = "hours since 1990-01-01 00:00:00" ;
        time:calendar = "proleptic_gregorian" ;
    double T2(time, y, x) ;
        T2:_FillValue = NaN ;
        T2:units = "K" ;
        T2:long_name = "Temperature at 2 m" ;
    double RRR(time, y, x) ;
        RRR:_FillValue = NaN ;
        RRR:units = "mm" ;
        RRR:long_name = "Total precipitation (liquid+solid)" ;
    double ACC(y, x) ;
        ACC:_FillValue = -9999. ;
        ACC:units = "mm yr^-1" ;
        ACC:long_name = "Accumulation from RRR_solid" ;
    double MELT_I(y, x) ;
        MELT_I:_FillValue = -9999. ;
        MELT_I:units = "mm yr^-1" ;
        MELT_I:long_name = "Melt from PDD" ;
    double MELT_S(y, x) ;
        MELT_S:_FillValue = -9999. ;
        MELT_S:units = "mm yr^-1" ;
        MELT_S:long_name = "Melt from PDD" ;
    double SMB(y, x) ;
        SMB:_FillValue = -9999. ;
        SMB:units = "mm yr^-1" ;
        SMB:long_name = "SMB from PDD" ;

我需要将数据作为模型的输入进行操作。我需要从 10 个 NetCDF 文件中提取的变量是 SMB 变量,它只是每个网格单元的年度值。所以我想构建一个 NetCDF 的形式:

(year, y, x) for the SMB variable

我知道 ncks 命令已经可以只提取 SMB 变量,但我无法一次将它应用于多个文件(假设是当前目录中的所有 nc 文件)并随后将它们放入一个 NetCDF 文件中跨越所有 10 年。

有人可以帮我吗? 太棒了!

特蕾莎

记录在案的 NCO ncecat 命令 here 完全符合您的要求:

ncecat -u time -v SMB Rhone_AWS_199*.nc out.nc