NCO Arithmetic Operators and Their Uses

NCO Arithmetic Operators and Their Uses

Postby yiboj » Mon Apr 04, 2016 10:21 am

The NCO (netCDF Operators) utilities are a set of powerful command line tools for manipulating and analyzing netCDF (including HDF5) files. They can be used to subset, aggregate and modify data and metadata stored in netCDF. If the NCO utilities are not installed on your computer they can be found here: http://nco.sourceforge.net/

Some useful utilities offered by NCO are their arithmetic manipulators that allow you to add, multiply, divide and subtract data between files . The default for ncbo is to subtract.

Here is an example command:

ncbo --op_typ=sbt ncesAvg1997.nc ncesAvg1998.nc sbt19978.nc

This will create a file called sbt19978.nc that contains the difference between ncesAvg1997.nc and ncesAvg1998.nc.
ncbo is the command and --op_typ=sbt means that the operation to be preformed is subtraction. Instructions can be found here http://nco.sourceforge.net/nco.html .
Other options include add for addition, mlt for multiplication, and dvd for division.

The following image shows the sea surface temperature data that results when the average files for the years 1997 and 1998 are subtracted.

sst_diff.jpg
sst_diff.jpg (45.09 KiB) Viewed 3328 times


Standard deviation can also be calculated using the nco utilites. If we have a file called in.nc of which we want to find the standard deviation of some variables we can do these three commands to get it.

    1. ncwa –v variable_name in.nc out.nc
    2. ncbo –v variable_name in.nc out.nc out.nc
    3. ncwa –y rmssdn out.nc out.nc

To see your answer do ncdump out.nc and find the value for your variable_name.

It is also relatively easy to create a graph of standard deviation over time. Fist you will need to concatenate your files together using the nce/ncrcat commands that are described above. Once you have a concatenated file follow these steps:
1. Find the mean of your concatenated files
    ncwa catfile.nc mean.nc
2. Subtract the mean from the concatenated file
    ncbo catfile.nc mean.nc difference.nc
3. Now use the rmssdn option to finish the calculation and averages over lat and lon
    ncwa –y rmssdn –a lat,lon difference.nc output.nc

Now you have a file that contains the standard deviation over time.
yiboj
 
Posts: 130
Joined: Mon Mar 30, 2015 11:22 am

Return to Data Access and Services