Set zeros to NaN (or equivalent)
Added by Holly Ayres about 5 years ago
Hello,
I was wondering if there was a way to set zero values to NaN or equivalent (missing data?) using CDO. I need to do this for -ymonmean averaging of sea ice, so it does not include grid boxes/years that do not have any sea ice in? I would normally do this on Matlab but my output netcdf files are causing problems further on, so I figured it's worth a try in CDO as these output files I have got working.
Thank you,
Holly
Replies (5)
RE: Set zeros to NaN (or equivalent) - Added by Holly Ayres about 5 years ago
Or, possibly a way to average just ignoring zeros? A bit of a long shot.
Thank you,
Holly
RE: Set zeros to NaN (or equivalent) - Added by Ralf Mueller about 5 years ago
hi!
Set a constant value (here zero) to missing value with
cdo -setctomiss,0Check "here:https://code.mpimet.mpg.de/projects/cdo/embedded/index.html#x1-310001.7 for how missing values are handled by CDO
hth + merry Xmas
ralf
RE: Set zeros to NaN (or equivalent) - Added by Ralf Mueller about 5 years ago
ah, in case you don't know: the term missing value is part of the netcdf standard. it is used for a certain numeric value, which indicates that the data at this point is missing. _FillValue is an equivalent term for this (https://www.unidata.ucar.edu/software/netcdf/docs/fill_values.html).
Avoid NaN whenever you can, because different tools might handle this in different ways whereas the stuff above is part of the standard.
cheers
ralf
RE: Set zeros to NaN (or equivalent) - Added by Holly Ayres about 5 years ago
Thank you for this, very helpful!
Is there a way to just do a -ymonmean and not include zeros? Cut out the middle man so to speak.
Thank you,
Holly
RE: Set zeros to NaN (or equivalent) - Added by Ralf Mueller about 5 years ago
as i said: you can set them to missing values and they will be ignored
cdo -yearmonmean -setctomiss,0 <input> <output>