| 50 | |
| 51 | |
| 52 | XXXXXXXXXXXXXX |
| 53 | |
| 54 | 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. |
| 55 | |
| 56 | The call has the following structure: |
| 57 | {{{ |
| 58 | cdo -f nc -regriddingMethod,gridTemplate.nc input.nc output.nc |
| 59 | }}} |
| 60 | |
| 61 | 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. |
| 62 | |
| 63 | 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. |
| 64 | |
| 65 | Some examples: |
| 66 | {{{ |
| 67 | 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 |
| 68 | 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 |
| 69 | }}} |
| 70 | |
| 71 | |
| 72 | |
| 73 | == ncap2 == |
| 74 | |
| 75 | The most powerful and quickly evolving tool from the nco set of functions |
| 76 | |
| 77 | See the file of exemples : {{:reunions_orchidee:ncap2.pdf| ncap2 file}} or 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]] |
| 78 | |
| 79 | A simple exemple 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) |
| 80 | |
| 81 | <code> |
| 82 | ncap2 -O -s 'missing_flag[$y,$x]=0;where(t2m_daily!=t2m_daily@missing_value) missing_flag=1;missing_count=float(missing_flag.total())/missing_flag.size();print(missing_count)' stomate_restart.nc ~/foo.nc |
| 83 | ncap2 -O -s 'missing_flag[$y,$x]=0;where(t2m_daily!=t2m_daily@missing_value) missing_flag=1;missing_count=float(missing_flag.total($x))/missing_flag.size($x);print(missing_count)' stomate_restart.nc ~/foo.nc |
| 84 | </code> |
| 85 | |
| 86 | |
| 87 | == cdo == |
| 88 | |
| 89 | A command that handle many operations one would like to do when working on outputs of models of the Earth System : |
| 90 | * changing of time axis |
| 91 | * regridding (many grid are already implemented and it is an even more versatile tool) |
| 92 | * complex operations... |
| 93 | |
| 94 | 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}} |
| 95 | |
| 96 | <code> |
| 97 | |
| 98 | cdo -v # print list of available operators [[BR]] |
| 99 | 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]] |
| 100 | cdo -h remapcon # informations about a command [[BR]] |
| 101 | cdo remapcon,my_grid my_climatology.nc my_regridded_climatology.nc # conservative regridding to an other resolution [[BR]] |
| 102 | |
| 103 | </code> |
| 104 | |
| 105 | my_grid could be a file like : |
| 106 | |
| 107 | <code> |
| 108 | gridtype = lonlat |
| 109 | gridsize = 220 |
| 110 | xname = longitude |
| 111 | xunits = degrees_east |
| 112 | yname = latitude |
| 113 | yunits = degrees_north |
| 114 | xsize = 20 |
| 115 | ysize = 11 |
| 116 | xfirst = -18.75 |
| 117 | xinc = 3.75 |
| 118 | yfirst = 20 |
| 119 | </code> |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | <code> |
| 125 | cdo sinfov my_file.nc #most info on the file |
| 126 | cdo griddes my_file.nc #grid description (check that the type is not generic (which means unrecognised and thus not useable for mapping |
| 127 | </code> |
| 128 | |
| 129 | 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) |
| 130 | <code> |
| 131 | ncatted -a coordinates,my_var,o,c,"nav_lon nav_lat" sst_data.nc |
| 132 | </code> |
| 133 | |
| 134 | or to correct a wrong spelling of an attribute |
| 135 | |
| 136 | <code> |
| 137 | ncatted -a units,latitude,m,c,"degrees_north" force2002.nc |
| 138 | </code> |
| 139 | |
| 140 | == Operator chaining == |
| 141 | It is one of the main features of CDO. Use it as often as possible. But Note: Operatos with a arbitrary list of input files cannot be combined with other operators |
| 142 | |
| 143 | # Simple combination: |
| 144 | <code> |
| 145 | cdo sub -dayavg ifile2 -timavg ifile1 ofile |
| 146 | </code> |
| 147 | |
| 148 | |
| 149 | instead of : |
| 150 | |
| 151 | <code> |
| 152 | cdo timavg ifile1 tmp1 |
| 153 | |
| 154 | cdo dayavg ifile2 tmp2 |
| 155 | |
| 156 | cdo sub tmp2 tmp1 ofile |
| 157 | |
| 158 | rm tmp1 tmp2 |
| 159 | </code> |
| 160 | |
| 161 | |
| 162 | == To install a newer version than the default one on asterix/obelix == |
| 163 | |
| 164 | <code> |
| 165 | get files from https://code.zmaw.de/projects/cdo/files |
| 166 | ./configure --prefix=/home/users/your_ACCOUNT/ --with-netcdf=/usr |
| 167 | |
| 168 | make clean |
| 169 | make |
| 170 | make install |
| 171 | </code> |
| 172 | |
| 173 | If you installed proj and hdf5 libraries somewhere, their can also be support for these file formats : |
| 174 | |
| 175 | <code> |
| 176 | ./configure --prefix=/home/users/your_ACCOUNT/ --with-netcdf=/usr --with-proj=/path/to/install --with-hdf5=/path/where/installed |
| 177 | </code> |
| 178 | |
| 179 | |