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 | |
| 82 | 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 |
| 83 | |
| 84 | |
| 85 | {{{ |
| 86 | ncatted -a coordinates,my_var,o,c,"nav_lon nav_lat" sst_data.nc |
| 87 | }}} |
| 88 | |
| 89 | or to correct a wrong spelling of an attribute |
| 90 | |
| 91 | {{{ |
| 92 | ncatted -a units,latitude,m,c,"degrees_north" force2002.nc |
| 93 | }}} |
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> |
| 103 | Below 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 | }}} |
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 | |
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> |
| 180 | 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. |
| 181 | |
| 182 | The call has the following structure: |
| 183 | {{{ |
| 184 | cdo -f nc -regriddingMethod,gridTemplate.nc input.nc output.nc |
| 185 | }}} |
| 186 | |
| 187 | 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. |
| 188 | |
| 189 | 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. |
| 190 | |
| 191 | Some examples: |
| 192 | {{{ |
| 193 | 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 |
| 194 | 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 |
| 195 | }}} |