Changes between Version 10 and Version 11 of Documentation/UserGuide/StudyNetCDF


Ignore:
Timestamp:
2020-02-28T15:22:22+01:00 (4 years ago)
Author:
bguenet
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Documentation/UserGuide/StudyNetCDF

    v10 v11  
    6868The most powerful and quickly evolving tool from the nco set of functions 
    6969 
    70 search what you are looking on this growing list of answers [[http://sourceforge.net/search/index.php?words=&sort=posted_date&sortdir=desc&offset=0&group_id=3331&type_of_search=forums|forum nco]] 
     70search what you are looking on this growing list of answers [[https://sourceforge.net/p/nco/discussion/|forum nco]] 
    7171 
    7272A 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) 
     
    7878 
    7979 
    80  
    81  
    82  
    83 XXXXXXXXXXXXXX 
    84  
    85 Similar to Ferret (see also How To), 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. 
    86  
    87 The call has the following structure: 
    88 {{{ 
    89 cdo -f nc -regriddingMethod,gridTemplate.nc input.nc output.nc 
    90 }}} 
    91  
    92 There 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. 
    93  
    94 For the template file with your target grid, it can be any netcdf with regular lat/lon. A trick here is to use "full paths" and not relative paths to the files in order to work. 
    95  
    96 Some examples: 
    97 {{{ 
    98 cdo -f nc -remapbil,/gpfs/cru/rst08auu/code/target.0.5degree.gpp.grid.45N.nc esa.ecv.smo.0.25deg.grid.monthly.1979.2010.nc esa.ecv.smo.0.25deg.grid.monthly.1979.2010.cdo.remapped.0.5deg.remapbil.45N.nc 
    99 cdo -f nc -remapnn,/gpfs/cru/rst08auu/code/target.0.5degree.gpp.grid.45N.nc esa.ecv.smo.0.25deg.grid.monthly.1979.2010.nc esa.ecv.smo.0.25deg.grid.monthly.1979.2010.cdo.remapped.0.5deg.remapnn.45N.nc 
    100 }}} 
    101  
     80 * '''ncatted''' 
     81 
     82Sometimes, 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 
     83 
     84 
     85{{{ 
     86   ncatted -a coordinates,my_var,o,c,"nav_lon nav_lat" sst_data.nc 
     87}}} 
     88 
     89or to correct a wrong spelling of an attribute 
     90 
     91{{{ 
     92   ncatted -a units,latitude,m,c,"degrees_north" force2002.nc 
     93}}} 
    10294 
    10395 
    10496== cdo == 
    10597 
    106 A command that handle many operations one would like to do when working on outputs of models of the Earth System : 
     98An 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 : 
    10799  * changing of time axis 
    108100  * regridding (many grid are already implemented and it is an even more versatile tool) 
    109101  * complex operations... 
    110102 
    111 See the website of the project {{https://code.zmaw.de/projects/cdo/wiki}} or the doc : {{:reunions_orchidee:cdo-manual.pdf| CDO Manual}} and  the  {{:reunions_orchidee:cdo_refcard.pdf | quickref}} 
    112  
    113 <code>  
    114  
    115    cdo -v # print list of available operators [[BR]] 
    116    cdo -V # version (if very old, think of downloading the source and install a new version, as it is a tool that is evolving quickly [[BR]] 
    117    cdo -h remapcon # informations about a command [[BR]] 
    118    cdo remapcon,my_grid my_climatology.nc my_regridded_climatology.nc # conservative regridding to an other resolution [[BR]] 
    119  
    120 </code> 
     103Below a list of classical command: 
     104 
     105 
     106 * print list of available operators [[BR]] 
     107{{{  
     108   cdo -v  
     109}}}  
     110 
     111 * print the version you are using (if very old, think of downloading the source and install a new version, as it is a tool that is evolving quickly) 
     112{{{ 
     113   cdo -V 
     114}}} 
     115 
     116 * more info on the file 
     117{{{ 
     118   cdo sinfov my_file.nc 
     119}}} 
     120 
     121 * grid description 
     122{{{  
     123   cdo griddes my_file.nc  
     124}}} 
     125 
     126 
     127* print some information about the command remapcon 
     128{{{ 
     129   cdo -h remapcon 
     130}}} 
     131 
     132* an example of a conservative regridding to an other resolution 
     133{{{ 
     134   cdo remapcon,my_grid my_climatology.nc my_regridded_climatology.nc  
     135}}} 
    121136 
    122137my_grid could be a file like : 
    123138 
    124 <code>   
     139{{{ 
    125140   gridtype  = lonlat 
    126141   gridsize  = 220 
     
    134149   xinc      = 3.75 
    135150   yfirst    = 20 
    136 </code> 
    137  
    138  
    139  
    140  
    141 <code> 
    142    cdo sinfov my_file.nc #most info on the file 
    143    cdo griddes my_file.nc #grid description (check that the type is not generic (which means unrecognised and thus not useable for mapping 
    144 </code> 
    145  
    146 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 (see https://code.zmaw.de/boards/1/topics/55) 
    147 <code> 
    148    ncatted -a coordinates,my_var,o,c,"nav_lon nav_lat" sst_data.nc 
    149 </code> 
    150  
    151 or to correct a wrong spelling of an attribute 
    152  
    153 <code> 
    154    ncatted -a units,latitude,m,c,"degrees_north" force2002.nc 
    155 </code> 
     151}}} 
     152 
     153 
     154 
     155 
     156 
    156157 
    157158== Operator chaining == 
     
    177178 
    178179 
    179 == To install a newer version than the default one on asterix/obelix == 
    180  
    181 <code> 
    182    get files from https://code.zmaw.de/projects/cdo/files 
    183    ./configure --prefix=/home/users/your_ACCOUNT/ --with-netcdf=/usr 
    184  
    185    make clean 
    186    make 
    187    make install 
    188 </code> 
    189  
    190 If you installed proj and hdf5 libraries somewhere, their can also be support for these file formats : 
    191  
    192 <code> 
    193    ./configure --prefix=/home/users/your_ACCOUNT/ --with-netcdf=/usr --with-proj=/path/to/install --with-hdf5=/path/where/installed 
    194 </code> 
     180Similar to Ferret (see also How To), 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. 
     181 
     182The call has the following structure: 
     183{{{ 
     184cdo -f nc -regriddingMethod,gridTemplate.nc input.nc output.nc 
     185}}} 
     186 
     187There 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. 
     188 
     189For the template file with your target grid, it can be any netcdf with regular lat/lon. A trick here is to use "full paths" and not relative paths to the files in order to work. 
     190 
     191Some examples: 
     192{{{ 
     193cdo -f nc -remapbil,/gpfs/cru/rst08auu/code/target.0.5degree.gpp.grid.45N.nc esa.ecv.smo.0.25deg.grid.monthly.1979.2010.nc esa.ecv.smo.0.25deg.grid.monthly.1979.2010.cdo.remapped.0.5deg.remapbil.45N.nc 
     194cdo -f nc -remapnn,/gpfs/cru/rst08auu/code/target.0.5degree.gpp.grid.45N.nc esa.ecv.smo.0.25deg.grid.monthly.1979.2010.nc esa.ecv.smo.0.25deg.grid.monthly.1979.2010.cdo.remapped.0.5deg.remapnn.45N.nc 
     195}}} 
    195196 
    196197== ncview: a quick alternative ==