python netcdf: making a copy of all variables and attributes but one

后端 未结 5 1023
南笙
南笙 2020-12-09 10:42

I need to process a single variable in a netcdf file that actually contains many attributes and variable. I think it is not possible to update a netcdf file (see question Ho

5条回答
  •  半阙折子戏
    2020-12-09 11:31

    The nccopy utility in C netCDF versions 4.3.0 and later includes an option to list which variables are to be copied (along with their attributes). Unfortunately, it doesn't include an option for which variables to exclude, which is what you need.

    However, if the list of (comma-delimited) variables to be included doesn't cause the nccopy command-line to exceed system limits, this would work. There are two variants for this option:

    nccopy -v var1,var2,...,varn input.nc output.nc
    nccopy -V var1,var2,...,varn input.nc output.nc
    

    The first (-v) includes all the variable definitions, but only data for the named variables. The second (-V) doesn't include definitions or data for unnamed variables.

提交回复
热议问题