0

I have a netCDF file with the foll. ncdump:

netcdf test_nc {
dimensions:
    time = UNLIMITED ; // (20 currently)
    latitude = 360 ;
    longitude = 720 ;
    N = 3 ;
    strlen = 1 ;
variables:
    float data_array(time, latitude, longitude, N) ;
        data_array:_FillValue = -9999.f ;
        data_array:units = "1" ;
        data_array:long_name = "data_array" ;
    char N(N, strlen) ;
    double latitude(latitude) ;
        latitude:standard_name = "latitude" ;
        latitude:units = "degrees_north" ;
    double longitude(longitude) ;
        longitude:standard_name = "longitude" ;
        longitude:units = "degrees_east" ;
    double time(time) ;
        time:standard_name = "time" ;
        time:units = "days since 2000-01-01 00:00:00.0" ;
        time:calendar = "gregorian" ;
}

How do I extract the last variable in the data_array group? If I use ncks, I can extract all of data_array like this:

ncks -v data_array test_nc.nc output_nc.nc

However, I only want to extract the variable corresponding to N=3 in data_array. Any solution using python netCDF4 or nco tools will work for me (but not using cdo), also needs to work on windows.

user308827
  • 21,227
  • 87
  • 254
  • 417

1 Answers1

2

If I understand correctly you use eccentric terminology and call a "group" and "variable" what others call a "variable" and a "hyperslab", respectively. The NCO solution is to use the hyperslab option (-d) with most any operator, such as ncks :

ncks -d N,2 -v data_array in.nc out.nc

Indices are 0-based by default so N=2 gives you the last slice in N.

Charlie Zender
  • 5,929
  • 14
  • 19