1

I have two timeseries netcdf files with the same number of steps:

  1. U.nc with variable name u10.
  2. V.nc with variable name v10. Now I want to add multiply U.nc with U.nc similarily, V.nc with V.nc.

I also want to add U.nc with V.nc., the variables u10 and v10 should be added.

How can I do this?

ClimateUnboxed
  • 7,106
  • 3
  • 41
  • 86

2 Answers2

1

you can do it with CDO

Adding u with u:

cdo mul u.nc u.nc ubyu.nc

and

cdo ubyu.nc vbyv.nc usumv.nc

However it seems what you want to do is make the wind vector, for that you can merge the files and then use the expr operator

cdo merge u.nc v.nc uv.nc
cdo expr,'wind=sqrt(u10*u10+v10*v10)' uv.nc wind.nc 

See the tutorial here for more details on the the expr operator

ClimateUnboxed
  • 7,106
  • 3
  • 41
  • 86
1

A similar answer to Adrian Tompkins's above.

cdo -L -expr,'wind=sqrt(u10*u10+v10*v10)' -merge u.nc v.nc uv.nc wind.nc 

This uses method chaining. Depending on how CDO was built, you may or may not need -L.

Robert Wilson
  • 3,192
  • 11
  • 19
  • What does the -L "lock" effectively do? I sometimes get a segmentation fault when attempting to use chained commands (esp. on my desktop) - would this use of -L resolve that issue? – ClimateUnboxed Dec 21 '20 at 20:54
  • Issues are explained here: https://code.mpimet.mpg.de/projects/cdo/wiki#Segfault-with-netcdf4-files. If the hdf5 library on your system is not threadsafe, you need to add - L for chaining to always work. – Robert Wilson Dec 21 '20 at 21:28
  • brilliant, thanks... I checked the documentation but there is not much detail on this option there. This is great, I often had to rewrite code avoiding chaining due to the seg fault. thanks! – ClimateUnboxed Dec 22 '20 at 08:52
  • easy solution is to install CDO from conda. Everything is threadsafe that way. Installing hdf5 from source threadsafe seems to be a pain – Robert Wilson Dec 22 '20 at 10:53