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?
You can use NCO's ncap2 to do this easily.
For example, set all values of x
below 100 to 100 in file.nc
and output in file2.nc
:
>>> ncap2 -s 'where(x<100.) x=100;' file.nc -O file2.nc
ncap2's clipping operator is most concise:
ncap2 -s 'x=x>>100' in.nc out.nc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With