1

How can I use the CDO delete operator to remove variable-specific and/or global attributes of a NetCDF?

As far as I understand from the help pages of the operator, I should provide a comma-separated list of attributes, keyed by param, but:

$ cdo delete,param="pr@missing_value,Title" ifile.nc ofile.n
cdo    delete (Warning): Parameter >pr:missing_value< not found!
cdo    delete (Warning): Parameter >Title< not found!

NOTE: this is the list of attributes of my test file:

$ cdo showattribute ifile.nc
pr:
   long_name = "precipitation"
   units = "mm"
   missing_value = -999
Global:
   Conventions = "CF-1.5" 
   Title = "Ninja Title"
   Created on = "Wed Aug 25 03:29:12 2021"

Using CDO version 1.9.9

ClimateUnboxed
  • 7,106
  • 3
  • 41
  • 86
Campa
  • 4,267
  • 3
  • 37
  • 42

1 Answers1

2

Actually I usually find nco is much more appropriate for this kind of task.

You can delete the attribute of the variable using ncatted

ncatted -a att_nm,var_nm,mode,att_type,att_val

so in your case it would be

ncatted -O -a missing_value,pr,d,, file.nc 

d is for "delete", see this page for usage

To delete the global attribute, using this answer, you would instead write

ncatted -O -a title,global,d,, file.nc

Hint: you can also add the -h option to prevent additions to the netcdf history global attribute

ClimateUnboxed
  • 7,106
  • 3
  • 41
  • 86