Personal tools

NCO

From MohidWiki

Revision as of 11:38, 3 December 2008 by Guillaume (talk | contribs) (1 revision)
Jump to: navigation, search

They are netcdf files averagers, concateners and renamer operators that act on a netcdf dataset hyperslab or an ensemble of netcdf datasets hyperslabs.

Examples

ncrename

Rename the variable p to pressure and t to temperature in netCDF ‘in.nc’. In this case p must exist in the input file (or ncrename will abort), but the presence of t is optional:

> ncrename -v p,pressure -v .t,temperature in.nc

Rename the attribute long_name to largo_nombre in the variable u, and no other variables in netCDF ‘in.nc’.

> ncrename -a u:long_name,largo_nombre in.nc

ncks extracts

Extract variables time and pressure from netCDF ‘in.nc’. If ‘out.nc’ does not exist it will be created. Otherwise the you will be prompted whether to append to or to overwrite ‘out.nc’:

> ncks -v time,pressure in.nc out.nc
> ncks -C -v time,pressure in.nc out.nc

The first version of the command creates an ‘out.nc’ which contains time, pressure, and any coordinate variables associated with pressure. The ‘out.nc’ from the second version is guaranteed to contain only two variables time and pressure.

nca averages

The following command performs the time average over an ensemble of files (they don't need to be the same size):

> ncra file1.nc file2.nc ... filen.nc mean.nc

Applied examples

Renaming variables names

Renames the Vel._X variables to Vel_X. This is because the "." character isn't a very good idea to be present in a netcdf variable name, or in any variable at all. The matlab scripts don't read such variables.

>  for i in `find . | grep 'Portugal_Hydrodynamic'`; 
>  do ncrename -v .Vel._X,Vel_X -v .Vel._Y,Vel_Y -v .Vel._Z,Vel_Z -v .Vel._Z,Vel_Z $i;
>  done;

Biscay exercise. Formatting data correctly

G. Reffray helped us a lot to get the correct netcdf files format for the Biscay intercomparison. Here are the lines he provided:

> ncpdq -U -h -O -a lat,lon MOHID_GRIDT_12.nc MOHID_GRIDT_12.nc
> ncpdq -h -U -F -O -d deptht,3,43 MOHID_GRIDT_12.nc MOHID_GRIDT_12.nc
> ncpdq -h -O -U -a -deptht MOHID_GRIDT_12.nc MOHID_GRIDT_12.nc
> ncks -h -O -v temperature,salinity MOHID_GRIDT_12.nc MOHID_GRIDT_12.nc

The first line transposes the lat and lon dimensions. The second line trims the deptht dimension. The third line inverts the deptht dimension, and finally, the last line, excludes all variables, except the temperature and the salinity.