Search code examples
netcdfnco

NCO: can we remove dimension without modifying coordinates attribute?


I have a netcdf file :

dimensions:
  y = 453 ;
  x = 453 ;
  plev = 1 ;
  time = UNLIMITED ; // (1460 currently)
variables:
  double plev(plev) ;
    plev:name = "plev" ;
    plev:standard_name = "air_pressure" ;
    plev:long_name = "pressure" ;
    plev:units = "Pa" ;
    plev:axis = "Z" ;
    plev:positive = "down" ;
  float va925(time, plev, y, x) ;
    va925:_FillValue = 1.e+20f ;
    va925:missing_value = 1.e+20f ;
    va925:coordinates = "lon lat plev" ;
    va925:grid_mapping = "Lambert_Conformal" ;

I would like to remove the plev dimension, but keep plev variable and do not modify va925 coordinates attribute.

So I would like :

dimensions:
  y = 453 ;
  x = 453 ;
  time = UNLIMITED ; // (1460 currently)
variables:
  double plev;
    plev:name = "plev" ;
    plev:standard_name = "air_pressure" ;
    plev:long_name = "pressure" ;
    plev:units = "Pa" ;
    plev:axis = "Z" ;
    plev:positive = "down" ;
  float va925(time, y, x) ;
    va925:_FillValue = 1.e+20f ;
    va925:missing_value = 1.e+20f ;
    va925:coordinates = "lon lat plev" ;
    va925:grid_mapping = "Lambert_Conformal" ;

I have tried with : ncwa -a plev in.nc out.nc But it modifies va925 coordinates such as : va925:coordinates = "lon lat ";

I can change it again with : ncatted -h -O -a coordinates,va925,m,c,"lon lat plev" out.nc But it means that I have to loop on the variable name, which is too long!

Thank you in advance,

Lola


Solution

  • As you have discovered, ncwa automatically removes the averaged dimensions from the coordinates attribute. There is no switch to turn this off. It took a lot of work to include this feature so it is ironic that some users want to disable it :) You have already discovered and rejected the obvious workaround with ncatted. A lengthier workaround would be to rename all the coordinates attributes before using ncwa, then rename back afterwards, e.g.,

    ncrename -a .coordinates,impeachment in.nc
    ncwa -a lon in.nc out.nc
    ncrename -a .impeachment,coordinates out.nc