Changes between Version 4 and Version 5 of Users/SetupNewConfiguration/cdo-interpolation
- Timestamp:
- 2017-03-31T21:21:49+02:00 (7 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Users/SetupNewConfiguration/cdo-interpolation
v4 v5 3 3 [[PageOutline(2)]] 4 4 5 '''You can find here an example of bash script to interpolate forcing core2 files.[[BR]] 6 7 To interpolate files you need to do 3 steps:[[BR]] 8 9 1. have good grid description file (if not you can create it, see instructions 1.) below)[[BR]] 10 11 2. prepare files to be interpolated ((see 2.) below)[[BR]] 12 13 3. remapping on ORCA2 grid ((see 3.) below)'''[[BR]] 14 5 Last edition: '''[[Wikinfo(changed_ts)]]''' by '''[[Wikinfo(changed_by)]]''' 6 7 '''You can find here an example of bash script to interpolate forcing core2 files.''' 8 9 To interpolate files you need to do 3 steps: 10 1. have good grid description file (if not you can create it, see instructions 1.) 11 2. prepare files to be interpolated 12 3. remapping on ORCA2 grid 15 13 16 14 NOTE: This script works with cdo version 1.4.0.1 17 15 18 19 20 16 == 1) Prepare grid description file for the ORCA curvilinear grid 21 17 22 18 You need to prepare a netCDF grid description file for the ORCA curvilinear grid.[[BR]] 23 This file must contain:[[BR]] 24 - a longitude variable with exactly 2 dimensions and the attribute: units = "degrees_east"[[BR]] 25 - a latitude variable with exactly 2 dimensions and the attribute: units = "degrees_north"[[BR]] 26 - a dummy variable with the attribute: coordinates = "xxx yyy" where xxx and yyy are the name of the longitude and latitude variables mentioned just above[[BR]] 27 28 There is an example of a [http://www.unidata.ucar.edu/software/netcdf/ netCDF] grid description file for the T grid of ORCA2:[[BR]] 29 30 19 This file must contain: 20 - a longitude variable with exactly 2 dimensions and the attribute: units = "degrees_east" 21 - a latitude variable with exactly 2 dimensions and the attribute: units = "degrees_north" 22 - a dummy variable with the attribute: coordinates = "xxx yyy" where xxx and yyy are the name of the longitude and latitude variables mentioned just above 23 24 There is an example of a [http://www.unidata.ucar.edu/software/netcdf/ netCDF] grid description file for the T grid of ORCA2: 31 25 {{{ 32 26 netcdf grid_ORCA2_T { … … 44 38 }}} 45 39 46 There is an example of nco commands to create this file from coordinates.nc (input file used by NEMO for its grid description)[[BR]] 47 48 40 There is an example of nco commands to create this file from coordinates.nc (input file used by NEMO for its grid description) 49 41 {{{#!sh 50 42 # select glamt and gphit variables from the coordinates file 51 43 ncks -O -C -a -v glamt,gphit coordinates_ORCA_R2.nc grid_ORCA2_T.nc 52 53 }}} 54 55 make sure that coordinates variables contains only 2 dimension. Use ncwa -a to remove degenerated dimensions (with a size of 1) for example:[[BR]] 56 57 44 }}} 45 46 make sure that coordinates variables contains only 2 dimension. Use ncwa -a to remove degenerated dimensions (with a size of 1) for example: 58 47 {{{#!sh 59 48 # remove degenerated dimention time (if existing) … … 72 61 }}} 73 62 74 75 63 == 2) Prepare file to be interpolated 76 64 77 for a curvilinear grid:[[BR]] 78 79 - you have to follow above spefication[[BR]] 80 81 For a regular lon/lat grid:[[BR]] 82 83 - The coordinate variables must have the same name as the dimensions. You can chose any name. If you use the name x for the dimension then you have to use also x for the coordinate variable.[[BR]] 84 - The coordinate variable must also have the attribute units = "degrees_east" or "degrees_north" to identify the lon/lat variables:[[BR]] 85 65 For a curvilinear grid: 66 - you have to follow above spefication 67 For a regular lon/lat grid: 68 - The coordinate variables must have the same name as the dimensions. You can chose any name. If you use the name x for the dimension then you have to use also x for the coordinate variable. 69 - The coordinate variable must also have the attribute units = "degrees_east" or "degrees_north" to identify the lon/lat variables: 86 70 {{{ 87 71 netcdf etopo5 { … … 98 82 }}} 99 83 100 101 84 == 3) Remapping on ORCA2 102 85 103 '''Generate weights with bilinear interpolation, and then remapping for a scalar field:'''[[BR]] 104 105 106 {{{#!sh 107 86 '''Generate weights with bilinear interpolation, and then remapping for a scalar field:''' 87 {{{#!sh 108 88 cdo genbil,grid_ORCA2_T.nc $file bil_orca2_weights.nc 109 89 cdo remap,grid_ORCA2_T.nc,bil_orca2_weights.nc $file_fill.nc $file_orca2.nc 110 90 }}} 111 91 112 113 where[[BR]] 114 115 - $file_fill.nc is a file whose missing values is filled (see below interpolation_loop.sh)[[BR]] 116 117 - $file_orca2.nc is the output[[BR]] 118 119 - and bil_orca2_weights.nc is a weight file generated (see below)[[BR]] 120 121 122 ''Generate weights with bilinear interpolation, and then remapping for a vectorial field:'''[[BR]] 123 124 125 {{{#!sh 126 92 where 93 - `$file_fill.nc` is a file whose missing values is filled (see below `interpolation_loop.sh`) 94 - `$file_orca2.nc` is the output 95 - and `bil_orca2_weights.nc` is a weight file generated (see below) 96 97 ''Generate weights with bilinear interpolation, and then remapping for a vectorial field:''' 98 {{{#!sh 127 99 cdo genbic,grid_ORCA2_T.nc $file bic_orca2_weights.nc 128 100 cdo remap,grid_ORCA2_T.nc,bic_orca2_weights.nc $file_fill.nc $file_orca2.nc 129 101 }}} 130 102 131 132 where[[BR]] 133 134 - $file_fill.nc is a file whose missing values is filled (see below interpolation_loop.sh)[[BR]] 135 136 - $file_orca2.nc is the output[[BR]] 137 138 - and bic_orca2_weights.nc is a weight file generated (see below)[[BR]] 139 140 141 == Example of "interpolation_loop.sh" script 142 143 This script needs to have input directory in your execution's directory to copy *.nc files and it calls 4 others sub-scripts: "create_orca2.sh", "prepare_mask.sh", "bilweights.sh" and "bicweights.sh"[[BR]] 144 145 146 NOTE: Before running "interpolation_loop.sh", you nedd to checks different things:[[BR]] 147 148 1. control latitude of your mask file. If it goes from north to south and latitude in your file goes from south to north you have to invert it:[[BR]] 149 103 where 104 - `$file_fill.nc` is a file whose missing values is filled (see below `interpolation_loop.sh`) 105 - `$file_orca2.nc` is the output 106 - and `bic_orca2_weights.nc` is a weight file generated (see below) 107 108 == Example of `interpolation_loop.sh` script 109 110 This script needs to have input directory in your execution's directory to copy *.nc files and it calls 4 others sub-scripts: `create_orca2.sh`, `prepare_mask.sh`, `bilweights.sh` and `bicweights.sh` 111 112 NOTE: Before running `interpolation_loop.sh`, you nedd to checks different things: 113 1. control latitude of your mask file. If it goes from north to south and latitude in your file goes from south to north you have to invert it: 150 114 {{{ 151 115 cdo invertlat ${file_mask_land}.nc ${file_mask_land}.SN.nc 152 116 }}} 153 117 154 155 118 2. control format of land variable, if it is short and your file has float format you will have problems with cdo created missing values, and filling missing values 156 157 119 {{{#!sh 158 120 #convert in float (from short) land variable … … 161 123 162 124 3. control values of your land variable, if it is 1 on earth and 0 on ocean is not good if you are interpolating files for ocean forcing 163 164 125 {{{#!sh 165 126 #convert land=0 on earth, 1 on ocean 166 127 ncap -O -s 'land=1-land' mask.nc mask.nc 167 128 }}} 168 169 129 {{{#!sh 170 130 #rename "land" in "mask" … … 172 132 }}} 173 133 174 175 134 4. control values of calendar's attribute in your file, if it is "NOLEAP" it is better to convert it in a recognized format by nccated (ex. 365_day) 176 177 135 {{{#!sh 178 136 ncatted -a calendar,${variable},m,c,365_day ${file}.nc ${file}_365.nc 179 137 }}} 180 181 182 '''main programm: interpolation_loop.sh ''' 138 139 '''main programm: `interpolation_loop.sh` ''' 183 140 184 141 {{{#!sh … … 258 215 }}} 259 216 260 '''first sub-programm: file create_orca2.sh'''217 '''first sub-programm: `file create_orca2.sh`''' 261 218 {{{#!sh 262 219 #!/bin/bash … … 281 238 }}} 282 239 283 '''Second sub-programm: prepare_mask.sh'''240 '''Second sub-programm: `prepare_mask.sh`''' 284 241 {{{#!sh 285 242 #!/bin/bash … … 313 270 314 271 315 '''Third sub-programm: bicweights.sh'''272 '''Third sub-programm: `bicweights.sh`''' 316 273 {{{#!sh 317 274 #!/bin/bash … … 324 281 325 282 326 '''Forth sub-programm: bicweights.sh'''283 '''Forth sub-programm: `bilweights.sh`''' 327 284 {{{#!sh 328 285 #!/bin/bash