New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
Users/SetupNewConfiguration/cdo-interpolation (diff) – NEMO

Changes between Version 4 and Version 5 of Users/SetupNewConfiguration/cdo-interpolation


Ignore:
Timestamp:
2017-03-31T21:21:49+02:00 (7 years ago)
Author:
nicolasmartin
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Users/SetupNewConfiguration/cdo-interpolation

    v4 v5  
    33[[PageOutline(2)]] 
    44 
    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  
     5Last 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 
     9To interpolate files you need to do 3 steps: 
     101. have good grid description file (if not you can create it, see instructions 1.) 
     112. prepare files to be interpolated 
     123. remapping on ORCA2 grid 
    1513 
    1614NOTE: This script works with cdo version 1.4.0.1 
    1715 
    18  
    19  
    2016== 1) Prepare grid description file for the ORCA curvilinear grid 
    2117 
    2218You 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  
     19This 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 
     24There is an example of a [http://www.unidata.ucar.edu/software/netcdf/ netCDF] grid description file for the T grid of ORCA2: 
    3125{{{ 
    3226netcdf grid_ORCA2_T { 
     
    4438}}} 
    4539 
    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  
     40There is an example of nco commands to create this file from coordinates.nc (input file used by NEMO for its grid description) 
    4941{{{#!sh 
    5042# select glamt and gphit variables from the coordinates file 
    5143ncks -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 
     46make sure that coordinates variables contains only 2 dimension. Use ncwa -a to remove degenerated dimensions (with a size of 1) for example: 
    5847{{{#!sh 
    5948# remove degenerated dimention time (if existing) 
     
    7261}}} 
    7362 
    74  
    7563== 2) Prepare file to be interpolated 
    7664 
    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  
     65For a curvilinear grid: 
     66- you have to follow above spefication 
     67For 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: 
    8670{{{ 
    8771netcdf etopo5 { 
     
    9882}}} 
    9983 
    100  
    10184== 3) Remapping on ORCA2 
    10285 
    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 
    10888    cdo genbil,grid_ORCA2_T.nc $file bil_orca2_weights.nc 
    10989    cdo remap,grid_ORCA2_T.nc,bil_orca2_weights.nc $file_fill.nc $file_orca2.nc 
    11090}}} 
    11191 
    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  
     92where 
     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 
    12799    cdo genbic,grid_ORCA2_T.nc $file bic_orca2_weights.nc 
    128100    cdo remap,grid_ORCA2_T.nc,bic_orca2_weights.nc $file_fill.nc $file_orca2.nc 
    129101}}} 
    130102 
    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  
     103where 
     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 
     110This 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 
     112NOTE: Before running `interpolation_loop.sh`, you nedd to checks different things: 
     1131. 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: 
    150114{{{ 
    151115cdo invertlat ${file_mask_land}.nc ${file_mask_land}.SN.nc 
    152116}}} 
    153117 
    154  
    1551182. 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  
    157119{{{#!sh 
    158120#convert in float (from short) land variable 
     
    161123 
    1621243. 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  
    164125{{{#!sh 
    165126#convert land=0 on earth, 1 on ocean 
    166127ncap -O -s 'land=1-land' mask.nc mask.nc 
    167128}}} 
    168  
    169129{{{#!sh 
    170130#rename "land" in "mask" 
     
    172132}}} 
    173133 
    174  
    1751344. 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  
    177135{{{#!sh 
    178136ncatted -a calendar,${variable},m,c,365_day ${file}.nc ${file}_365.nc 
    179137}}} 
    180  
    181   
    182 '''main programm: interpolation_loop.sh ''' 
     138  
     139'''main programm: `interpolation_loop.sh` ''' 
    183140 
    184141{{{#!sh 
     
    258215}}} 
    259216 
    260 '''first sub-programm: file create_orca2.sh''' 
     217'''first sub-programm: `file create_orca2.sh`''' 
    261218{{{#!sh 
    262219#!/bin/bash 
     
    281238}}} 
    282239 
    283 '''Second sub-programm: prepare_mask.sh''' 
     240'''Second sub-programm: `prepare_mask.sh`''' 
    284241{{{#!sh 
    285242#!/bin/bash 
     
    313270 
    314271 
    315 '''Third sub-programm: bicweights.sh''' 
     272'''Third sub-programm: `bicweights.sh`''' 
    316273{{{#!sh 
    317274#!/bin/bash 
     
    324281 
    325282 
    326 '''Forth sub-programm: bicweights.sh''' 
     283'''Forth sub-programm: `bilweights.sh`''' 
    327284{{{#!sh 
    328285#!/bin/bash