How to extract a single variable using NCO. Associated variable problem

657 views Asked by At

I am trying extract to a single variable kd_490 from a NetCDF file (over thredds) using NCO.

My code is below:

ncks -v kd_490 -d lat,40.0,70.0 -d lon,-20.0,15.0 https://rsg.pml.ac.uk/thredds/dodsC/cci/v4.2-release/geographic/daily/kd/1998/ESACCI-OC-L3S-K_490-MERGED-1D_DAILY_4km_GEO_PML_KD490_Lee-19980102-fv4.2.nc out.nc

However, along with kd_490 it also extracts kd_490_bias and kd_490_rmsd. I know that ncks extracts "associated" variables. See here. However, I am not clear on why NCO is identifying these as "associated" variable.

I cannot figure out a way to only select the variable kd_490. Adding "-C" to the code results in the grid being wrong. Does anyone know how?

Note: CDO can solve this problem. However, CDO is less efficient at extracting the spatial subset in the code, so NCO is more appropriate.

1

There are 1 answers

0
Charlie Zender On BEST ANSWER

NCO identifies kd_490_bias and kd_490_rmsd as associated variables because of the ancillary_variables attribute in kd_490:

   float kd_490(time,lat,lon) ;
      kd_490:_FillValue = 9.96921e+36f ;
      kd_490:long_name = "Downwelling attenuation coefficient at 490nm, derived using Lee 2005 equation and bbw from Zhang 2009 (following the SeaDAS Kd_lee algorithm)" ;
      kd_490:units = "m-1" ;
      kd_490:ancillary_variables = "kd_490_rmsd kd_490_bias" ;
      kd_490:grid_mapping = "crs" ;
      kd_490:parameter_vocab_uri = "http://vocab.ndg.nerc.ac.uk/term/P071/19/CFSN0064" ;
      kd_490:standard_name = "volume_attenuation_coefficient_of_downwelling_radiative_flux_in_sea_water" ;
      kd_490:units_nonstandard = "m^-1" ;
      kd_490:_ChunkSizes = 1, 270, 270 ;

as documented here. To extract kd_490 without the ancillary variables, but with the grid variables (which are other "associated" variables), this works for me:

ncks -O -C -v kd_490,crs,lat,lon -d lat,40.0,70.0 -d lon,-20.0,15.0 https://rsg.pml.ac.uk/thredds/dodsC/cci/v4.2-release/geographic/daily/kd/1998/ESACCI-OC-L3S-K_490-MERGED-1D_DAILY_4km_GEO_PML_KD490_Lee-19980102-fv4.2.nc ~/foo2.nc