I want to set all values below a constant c to c itself in a netcdf file: file.nc
A solution using climate data operators (CDO) would be
cdo mul -gec,$c file.nc file.nc t1.nc
cdo add -mulc,$c -ltc,$c file.nc t1.nc output.nc
rm -f t1.nc
But is there a neater/shorter way to do this?
Using Python with NumPy and netCDF4 you could do the following:
Good luck!
ncap2's clipping operator is most concise:
You can use NCO's ncap2 to do this easily.
For example, set all values of
x
below 100 to 100 infile.nc
and output infile2.nc
: