Changes between Version 14 and Version 15 of Documentation/UserGuide/StudyNetCDF


Ignore:
Timestamp:
2020-05-11T16:18:36+02:00 (4 years ago)
Author:
aducharne
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Documentation/UserGuide/StudyNetCDF

    v14 v15  
    33 
    44Author: S. Luyssaert and J. Ryder [[BR]] 
    5 Last revision: 2020/02/28, B. Guenet [[BR]] 
     5Last revision: 2020/02/28, B. Guenet; 2020/05/11, A. Ducharne [[BR]] 
     6 
     7== **ncview: a quick tool for vizualization** == 
     8The quickest way of all to look at NetCDF files and to quickly plot some outputs is to use ncview: 
     9 
     10{{{ 
     11ncview myJob_20060101_20061231_1M_sechiba_history.nc 
     12}}} 
     13 
     14Unfortunately the ncview application can be sometimes a little unstable. 
    615 
    716== **nco** == 
    8  
    917 
    1018nco is a very powerful tool to print data, modify variable names, concatenate, etc on netcdf file. A detailled documentation can be found here http://nco.sourceforge.net/ 
     
    1523This command print all the informations stored in your netcdf file. Some prefix can extract only the information you need. 
    1624 
    17    * To look at header information: 
     25To look at header information: 
    1826 
    1927{{{ 
     
    2129}}} 
    2230 
    23    * To extract one variable (here for 'fluxlat', the latent heat flux) 
     31To extract one variable (here for 'fluxlat', the latent heat flux) 
    2432 
    2533{{{ 
     
    2735}}} 
    2836 
    29    * To extract one variable and show them in a tabulated way (here for 'fluxlat', the latent heat flux) 
     37To extract one variable and show them in a tabulated way (here for 'fluxlat', the latent heat flux) 
    3038 
    3139{{{ 
     
    3745This command change the name of a given variable/dimension depending on the prefix you are using 
    3846 
    39    * To rename a variable within the file (here for 'fluxlat', the latent heat flux) 
     47To rename a variable within the file (here for 'fluxlat', the latent heat flux) 
    4048{{{ 
    4149ncrename -v fluxlat,latent_heat_flux myJob_20060101_20061231_1M_sechiba_history.nc  
    4250}}} 
    4351 
    44    * To rename a variable and create a new file (here for 'fluxlat', the latent heat flux) 
     52To rename a variable and create a new file (here for 'fluxlat', the latent heat flux) 
    4553{{{ 
    4654ncrename -v fluxlat,latent_heat_flux myJob_20060101_20061231_1M_sechiba_history.nc mynewfile.nc 
    4755}}} 
    4856 
    49    * To rename a dimension within the file (here for 'lon', the longitude) 
     57To rename a dimension within the file (here for 'lon', the longitude) 
    5058{{{ 
    5159ncrename -d lon,longitude myJob_20060101_20061231_1M_sechiba_history.nc  
    5260}}} 
    5361 
    54    * To rename a variable and create a new file (here for 'lon', the longitude) 
     62To rename a variable and create a new file (here for 'lon', the longitude) 
    5563{{{ 
    5664ncrename -d lon,longitude myJob_20060101_20061231_1M_sechiba_history.nc mynewfile.nc 
     
    97105[https://linux.die.net/man/1/ncra ncra] does the same with a time average, to get climatologies. 
    98106 
     107=== ncatted 
     108 
     109Sometimes, one just need to add the attribute coordinates (linking to the variables defining the longitude and latitude positions) to enable the recognition of the grid that is used. In that cases the ncatted command might be useful 
     110 
     111 
     112{{{ 
     113   ncatted -a coordinates,my_var,o,c,"nav_lon nav_lat" sst_data.nc 
     114}}} 
     115 
     116or to correct a wrong spelling of an attribute 
     117 
     118{{{ 
     119   ncatted -a units,latitude,m,c,"degrees_north" force2002.nc 
     120}}} 
     121 
    99122=== ncap2  
    100123 
    101124The most powerful and quickly evolving tool from the nco set of functions 
    102125 
    103 search what you are looking on this growing list of answers [[https://sourceforge.net/p/nco/discussion/|forum nco]] 
     126Search what you are looking on this growing list of answers [[https://sourceforge.net/p/nco/discussion/|forum nco]] 
    104127 
    105128A simple example showing different capacities (creation of a variable, use of a mask, call to an attribute, count the total and the size of the field (we can restrict this operation to a dimension as shown on the second line) 
     
    110133}}} 
    111134 
    112 === ncatted 
    113  
    114 Sometimes, one just need to add the attribute coordinates (linking to the variables defining the longitude and latitude positions) to enable the recognition of the grid that is used. In that cases the ncatted command might be useful 
    115  
    116  
    117 {{{ 
    118    ncatted -a coordinates,my_var,o,c,"nav_lon nav_lat" sst_data.nc 
    119 }}} 
    120  
    121 or to correct a wrong spelling of an attribute 
    122  
    123 {{{ 
    124    ncatted -a units,latitude,m,c,"degrees_north" force2002.nc 
    125 }}} 
    126  
    127  
    128 == cdo == 
     135== **cdo** == 
    129136 
    130137An alternative to nco is cdo. They are basically doing similar things but dependending on what you want to do the command line might be easier with one or another. Details on cdo are here https://code.mpimet.mpg.de/projects/cdo cdo is useful for : 
     
    133140  * complex operations... 
    134141 
    135 Below a list of classical command: 
     142== List of classical cdo command (non exhaustive) 
    136143 
    137144 
     
    183190}}} 
    184191 
    185  
    186 == Operator chaining == 
    187 It is one of the main features of CDO. Use it as But operators with a arbitrary list of input files cannot be combined with other operators 
    188  
    189  Simple combination: 
     192== Operator chaining 
     193It is one of the main features of CDO. Beware, however, that operators with an arbitrary list of input files cannot be combined with other operators. 
     194 
     195Simple combination example: 
    190196{{{ 
    191197   cdo sub -dayavg ifile2 -timavg ifile1 ofile 
    192198}}} 
    193  
    194  
    195  instead of : 
     199instead of: 
    196200{{{ 
    197201  cdo timavg ifile1 tmp1 
     
    204208}}} 
    205209 
    206 CDO can also be used to regrid NetCDF files. It is very straight and fast. Contrary to Ferret I [SL] did not find how to increase the memory allocation for CDO. Thus for very large files Ferret seems to be the software of your choice. 
    207  
    208 The call has the following structure: 
     210== Regridding 
     211 
     212CDO can also be used to regrid NetCDF files. It is very straight and fast. The call has the following structure: 
    209213{{{ 
    210214cdo -f nc -regriddingMethod,gridTemplate.nc input.nc output.nc 
    211215}}} 
     216 
     217Note that Sebastiaan Luyssaert did not find how to increase the memory allocation for CDO, contrary to Ferret. Thus, to regrid very large files, Ferret seems to be the software of your choice. 
    212218 
    213219There are three regridding methods: remapbil (bilinear interpolation), remapbic (bicubic interpolation), remapnn (nearest neighbour), remapcon (conservative regridding). Use remapnn and remapcon to avoid weird values if your variable is heterogeneous. 
     
    221227}}} 
    222228 
    223 == ncview: a quick alternative == 
    224 The quickest way of all to look at NetCDF files and to quickly plot some outputs is to use ncview: 
    225  
    226 {{{ 
    227 ncview myJob_20060101_20061231_1M_sechiba_history.nc 
    228 }}} 
    229  
    230 Unfortunately the ncview application can be sometimes a little unstable.