Stand With Ukraine

Friday, January 6, 2012

Summation along a dimension

Suppose you have a netcdf file with temporal data of say evaporation (in meters). And you want to know how much water evaporates during a year. And also you do not want to loose time writing a program for this. Fortunately we have NCO. I did the procedure for the ERA-Interim reanalysis file downloaded from the ECMWF site. I picked the year 1985. The header of the file looks like this:


Here is the description of the procedure that I used:
  1. Calculate the mean of the variable along the specified dimension (time in my case).
    ~# ncra -d time,0,729 -v e evap-1985.nc mean_evap_1985.nc
    
    Here I was not sure whether I should take care of the scale_factor and add_offset. The answer is no, because nco takes care of it for you.
  2. Then, since sum = mean * ntimes, I use the mean to get the sum. Minus is because of the model convention, they consider the flux negative if it is upwards.
    ~# ncap -O -s "e=-730*e" mean_evap_1985.nc sum_evap_1985.nc
    
  3. So we have our resulting field in the file sum_evap_1985.nc, which can be viewed using ncview. The field looks as shown below. I do not know how to save the legend in ncview, so the figure is not very informative. The result corresponds to the means given by ECMWF: E-P and P.

Data source: "ECMWF ERA-Interim data used here have been obtained from the ECMWF data server."