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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.