Search code examples
netcdfncocdo-climate

Aggregate different netcdf variables and write output


I have a netcdf files with 3 variables, nammed v1, v2, v3. I would like to aggregate those variables and create a new variable v4, as follow:

v4 = (v1*0.1)+(v2*0.2)+(v3*0.2)

I know how to aggregate 2 variables using cdo :

cdo expr,’sum=var1+var2;’ ifile ofile

But how could I handle more specific netcdf calculations like the one required?


Solution

  • CDO will be able to handle the formula you require:

    cdo expr,’v4=(v1*0.1)+(v2*0.2)+(v3*0.2)’ ifile ofile
    

    If you want to add the variable to the files, just do this:

    cdo aexpr,’sum=var1+var2;v4=(v1*0.1)+(v2*0.2)+(v3*0.2)’ ifile ofile