| 17 | |
| 18 | |
| 19 | |
| 20 | == ncap2 == |
| 21 | |
| 22 | The most powerful and quickly evolving tool from the nco set of functions |
| 23 | |
| 24 | 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]] |
| 25 | |
| 26 | 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) |
| 27 | |
| 28 | <code> |
| 29 | 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 |
| 30 | 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 |
| 31 | </code> |
| 32 | |
| 33 | |
| 34 | == cdo == |
| 35 | |
| 36 | A command that handle many operations one would like to do when working on outputs of models of the Earth System : |
| 37 | * changing of time axis |
| 38 | * regridding (many grid are already implemented and it is an even more versatile tool) |
| 39 | * complex operations... |
| 40 | |
| 41 | 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}} |
| 42 | |
| 43 | <code> |
| 44 | |
| 45 | cdo -v # print list of available operators [[BR]] |
| 46 | 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]] |
| 47 | cdo -h remapcon # informations about a command [[BR]] |
| 48 | cdo remapcon,my_grid my_climatology.nc my_regridded_climatology.nc # conservative regridding to an other resolution [[BR]] |
| 49 | |
| 50 | </code> |
| 51 | |
| 52 | my_grid could be a file like : |
| 53 | |
| 54 | <code> |
| 55 | gridtype = lonlat |
| 56 | gridsize = 220 |
| 57 | xname = longitude |
| 58 | xunits = degrees_east |
| 59 | yname = latitude |
| 60 | yunits = degrees_north |
| 61 | xsize = 20 |
| 62 | ysize = 11 |
| 63 | xfirst = -18.75 |
| 64 | xinc = 3.75 |
| 65 | yfirst = 20 |
| 66 | </code> |
| 67 | |
| 68 | |
| 69 | |
| 70 | |
| 71 | <code> |
| 72 | cdo sinfov my_file.nc #most info on the file |
| 73 | cdo griddes my_file.nc #grid description (check that the type is not generic (which means unrecognised and thus not useable for mapping |
| 74 | </code> |
| 75 | |
| 76 | 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) |
| 77 | <code> |
| 78 | ncatted -a coordinates,my_var,o,c,"nav_lon nav_lat" sst_data.nc |
| 79 | </code> |
| 80 | |
| 81 | or to correct a wrong spelling of an attribute |
| 82 | |
| 83 | <code> |
| 84 | ncatted -a units,latitude,m,c,"degrees_north" force2002.nc |
| 85 | </code> |
| 86 | |
| 87 | == Operator chaining == |
| 88 | 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 |
| 89 | |
| 90 | # Simple combination: |
| 91 | <code> |
| 92 | cdo sub -dayavg ifile2 -timavg ifile1 ofile |
| 93 | </code> |
| 94 | |
| 95 | |
| 96 | instead of : |
| 97 | |
| 98 | <code> |
| 99 | cdo timavg ifile1 tmp1 |
| 100 | |
| 101 | cdo dayavg ifile2 tmp2 |
| 102 | |
| 103 | cdo sub tmp2 tmp1 ofile |
| 104 | |
| 105 | rm tmp1 tmp2 |
| 106 | </code> |
| 107 | |
| 108 | |
| 109 | == To install a newer version than the default one on asterix/obelix == |
| 110 | |
| 111 | <code> |
| 112 | get files from https://code.zmaw.de/projects/cdo/files |
| 113 | ./configure --prefix=/home/users/your_ACCOUNT/ --with-netcdf=/usr |
| 114 | |
| 115 | make clean |
| 116 | make |
| 117 | make install |
| 118 | </code> |
| 119 | |
| 120 | If you installed proj and hdf5 libraries somewhere, their can also be support for these file formats : |
| 121 | |
| 122 | <code> |
| 123 | ./configure --prefix=/home/users/your_ACCOUNT/ --with-netcdf=/usr --with-proj=/path/to/install --with-hdf5=/path/where/installed |
| 124 | </code> |
| 125 | |