Page tree

MESH - A Community Hydrology - Land Surface Model


Skip to end of metadata
Go to start of metadata

This page describes how to interpolate NetCDF data to the grid specified in the "r2c" format in MESH input files using the "cdo" utility. The "cdo" command is used to interpolate to the grid defined in "r2c" inputs, and the output of this process is NetCDF format.

Page contents:

Overview

Point data file formats, such as NetCDF, store point data directly for the point associated with its index of latitude and longitude point locations. In contrast, the grid specification in an EnSim Hydrologic (Green Kenue) rectangular cell "r2c" format file defines points of the grid lines between these points. Thus, the data points should not be derived from the specification found in the header of these files directly.

The rectangular scalar "r2s" file contains a grid specification that corresponds to grid points directly, but this file format is not one of the file formats supported for MESH applications.

Matching point data to the grid specification found in "r2c" format input files

The EnSim Hydrologic (Green Kenue) rectangular cell "r2c" file format defines data where the data points are offset from the grid specification defined in the header of the file. This is the case for single-frame, multi-frame, ASCII and binary formats of this file.

This is not the case in most NetCDF files, where the grid specification defines the location of the data points directly.

Thus, to convert data between these two structures, the points extracted from a NetCDF file to match the grid specified from an "r2c" format file must be offset from the "xOrigin" and "yOrigin" reference by one-half "xDelta" and one-half "yDelta", respectively.

Interpolating data in NetCDF files using "cdo"

The "cdo" command is used to interpolate to the grid defined in "r2c" inputs, but the output of this process is in NetCDF format.
"cdo" can be installed in Ubuntu or may be available on clusters, such as the Compute Canada clusters as a module (e.g., "module load cdo")

Creating the "grid_template" configuration file

The first step is to define the specification of the destination grid as a text file (example template):

grid_template (example file)
gridtype = lonlat
gridsize = <xCount*yCount>
xname = lon
xlongname = Longitude
xunits = degrees_east
yname = lat
ylongname = Latitude
yunits = degrees_north
xsize = <xCount>
ysize = <yCount>
xfirst = <xOrigin + xDelta/2.0>
xinc = <xDelta>
yfirst = <yOrigin + yDelta/2.0>
yinc = <yDelta>

In the above,

  • Where a field appears in the format <value>, <value> must be replaced with the actual values from the "r2c" grid specification.
  • Where <value> appears to be a function, the function should be calculated using the actual values from the "r2c" grid specification, and only the calculated value should <value> in the template.

Consider this "r2c" header:

########################################
:FileType r2c  ASCII  EnSim 1.0         
#                                       
# DataType               2D Rect Cell   
#                                       
:Application             EnSimHydrologic
:Version                 2.1.23         
#                                       
#---------------------------------------
#                                       
#                                       
:Projection         LATLONG   
:Ellipsoid          WGS84     
#                                       
:xOrigin                 -86.923500
:yOrigin                  48.707600
#                                       
:xCount                        5
:yCount                        7
:xDelta                    0.205960
:yDelta                    0.134740
#                                       
:EndHeader                             
The above file specifies a regular latitude-longitude projection, as "Projection" is specified as "LATLONG".

These are the fields used to update the template file (omitting the leading ":" of the attribute in the above file):

FieldValue
xOrigin

-86.9235

yOrigin

48.7076

xCount

5

yCount

7

xDelta

0.20596

yDelta

0.13474

Thus, the "grid_template" fields are assigned or calculated as follows:

TemplateValue

<xCount*yCount>

35

<xCount>

5

<yCount>

7

<xOrigin + xDelta/2.0>

-86.82052

<xDelta>

0.20596

<yOrigin + yDelta/2.0>

48.77497

<yDelta>

0.13474

And the file is updated with the assigned or calculated values:

grid_template (example file)
gridtype = lonlat
gridsize = 35
xname = lon
xlongname = Longitude
xunits = degrees_east
yname = lat
ylongname = Latitude
yunits = degrees_north
xsize = 5
ysize = 7
xfirst = -86.82052
xinc = 0.20596
yfirst = 48.77497
yinc = 0.13474
The above file specifies a regular latitude-longitude projection by specifying the "gridtype" as "lonlat".
Notice the "xfirst" and "yfirst" values are different than the "xOrigin" and "yOrigin" values from the "r2c" file, though the "xinc" and "yinc" are still the same as the "xDelta" and "yDelta" values.

Running "cdo"

Then, use the "grid_template" file with the "cdo" command to perform the interpolation:

cdo -b F32 remapbil,grid_template <input_file> <output_file>
  • <input_file> should be an existing file in NetCDF format. <input_file> is replaced with the full path to the file.
  • <output_file> should be the full path to the file created by this process.
  • "grid_template" specifies the grid specifiction file illustrated above. If the file is named differently, "grid_template" should be replaced.

The "remapbil" option provides bilinear interpolation. For other interpolation techniques, refer to the "Interpolation" section of this quick-reference card: https://code.mpimet.mpg.de/projects/cdo/embedded/cdo_refcard.pdf

The "grid_template" file must be in the same folder were you run "cdo".
The "-b F32" option creates fields as type 'float', which in most cases is equivalent to the Fortran type "REAL(kind = 4)" (i.e., single precision).
The output of this command is another NetCDF file, which can be used with MESH directly (for example, to use NetCDF format driving data, refer to the options of BASINFORCINGFLAG and its overrides).

The resulting NetCDF file is not compressed by default. To save space, you can add "-z zip" or "-z zip_x" to force cdo to compress the output file. The first option will use the default compression level. In the latter case, replace x with a number between 1 .. 9 as the compression level. Compression will reduce file size but will take longer to process. Level 1 is recommended; extra compression takes longer without saving as much space. MESH will run with compressed NetCDF files.