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.
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.
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 "
Interpolating data in NetCDF files using "
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):
In the above,
- Where a field appears in the format
<value>must be replaced with the actual values from the "r2c" grid specification.
<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:
Projection" is specified as "
These are the fields used to update the template file (omitting the leading "
:" of the attribute in the above file):
Thus, the "grid_template" fields are assigned or calculated as follows:
And the file is updated with the assigned or calculated values:
gridtype" as "
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 "
Then, use the "
grid_template" file with the "
cdo" command to perform the interpolation:
<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.
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
grid_template" file must be in the same folder were you run "
-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 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.