Search code examples
netcdfnetcdf4ncocdo-climate

Select data along non-conventional dimension with CDO or NCO


I have a large number of NetCDF files from which I would like to extract a small number of variables for one location, and merge them into a new NetCDF file. The dimensions of the files are:

dimensions:
    time = 18 ;
    level = 65 ;
    levelh = 66 ;
    domain = 36 ;

I can subtract/merge the files for all domains with something like:

cdo select,name=u,v file1.nc file2.nc out.nc

But all other operators seem to be related to selections in space (e.g. sellonlatbox) or time (e.g. seltimestep), but I can't find a way to select only 1 domain from the NetCDF files. Is this possible with CDO's or NCO's?


Solution

  • Not sure I fully understand the question/intent. NCO treats all dimensions equally. If you want domain #17 then try

    ncrcat -v u,v -d domain,17 file1.nc file2.nc out.nc
    

    If file1.nc and file2.nc are not sequential in a record coordinate then try

    ncecat -v u,v -d domain,17 file1.nc file2.nc out.nc
    

    ADDED 20180929:

    or if you don't like that, and the files do not have a record dimension yet are time-sequential then before using ncrcat turn the temporal dimension into a record coordinate for each file with

    ncks -O --mk_rec_dmn time file1.nc file1.nc
    ncks -O --mk_rec_dmn time file2.nc file2.nc
    ...
    

    etc. and proceed as above. That may be the best way forward with NCO.