Wiki

Wiki

In order to intercompare different models , they must be interpolated from the native grid on which they were calculated to a common output grid. This procedure is known as regridding or remapping .

Fundamentally, regridding consists of two steps :

Different software may do one or the other or both of these steps.

To create the weights file, you must have grid description files for your source and target grids. These files give the latitudes and longitudes of every grid point, along with the corners of the boundary of its surrounding cell. There are several ways to write these files, depending on the software you’re using.

We have tested a number of software packages, and so far, the easiest way we have found to do regridding for structured (Heiko Goelzer) and unstructured triangular (NASA Goddard) grids is using the Climate Data Operators (CDO) .

CDO (Climate Data Operator) claims to run on any POSIX-compatible Unix-type OS, including macOS, most Linux, IBM AIX, HP-UX, Solaris, BSD variants, and even Cygwin. For those systems for which they’re provided, by far the easiest way to install CDO is to use a package manager, since these will also automatically install any other libraries CDO needs (its dependencies). Distributions are available from major package managers, including MacPorts (macOS), APT (Debian and Ubuntu), and RPM (RedHat and Fedora). We have successfully installed CDO on macOS with MacPorts, but have not tested others (reports welcome!). Links to these packages are on the CDO Wiki here. To install via package manager, you will probably need administrator privileges (this is certainly the case with MacPorts). For other systems, CDO may have to be built from source code. Instructions for doing so are also on the CDO website . We haven’t tested this.

At the very least, you will also need the netCDF library from Unidata so that CDO can read and write (classic) netCDF files. If your model files are in netCDF4 or HDF5 you’ll also need the HDF5 library. The package managers should install these automatically if you don’t already have them.

The critical part of remapping with CDO is to create horizontal-grid description files describing both your input and output grids. These files provide the latitude and longitude of every grid point, and of the corners of its surrounding cell boundary.

A CDO grid file for the ISMIP6 standard 5 km polar stereographic grid for the Greenland ice sheet and the 8km polar stereographic grid for the Antarctic ice sheet can be obtained by emailing ismip6-at-gmail-dot-com.

Details of the file format are in section 1.3 (especially 1.3.2.4) and Appendix D of the CDO User’s Guide .

Here is a simple example of a grid that has 6 cells, 3 across and 2 up :

gridtype = curvilinear

Several grid types are available. Curvilinear grids are 2-dimensional, but are not necessarily arranged along latitude and longitude lines. Because the standard polar-stereographic grid is rectangular in p-s x-y space but not lon-lat space, it is curvilinear. gridtype = unstructured is a simple list of grid points, with cells which may or may not be the same size, may be in any order, and may not necessarily be quadrilateral, and need not be adjoining. A Voroni triangulation is represented as an unstructured grid, as is an adaptive mesh. Notice that a curvilinear grid could as easily be described as unstructured, but the output variables would be 1D instead of 2D. For other options see the CDO User’s Guide.

gridsize = 6 Total number of points in the grid. For input files, this MUST match the number of points in the variables. For curvilinear grids, gridsize = xsize * ysize . For unstructured grids, this is just the number of elements in your mesh.

xsize = 3 For curvilinear grids, the number of grid points in the longitude direction. Not used for unstructured grids.

ysize = 2 For curvilinear grids, the number of grid points in the latitude direction. Not used for unstructured grids.

nvertex = 4 Number of corners of the boundary of the cell surrounding each grid point. Optional for curvilinear grids (assumes 4), required for unstructured grids. A triangulation grid would have nvertex = 3 .

xvals = ... The longitude position of every grid cell.

yvals = ... The latitude position of every grid cell.

xbounds = ... The longitudes of the corners of the cell boundary surrounding each grid point. There must be ( nvertex * gridsize ) values. CDO requires that the corners be listed counterclockwise around the grid point.

ybounds = ... The latitudes of the corners of the cell boundary surrounding each grid point. There must be ( nvertex * gridsize ) values.

Grid files may contain comment lines, which begin with “#”, and blank lines. In the example above, the grid point at (61.,302.) is the center of a cell with corners at (60.,302.), (63.,302.), (63.,300.), and (60.,300.).

In the grid files, the keywords must be at the beginnings of their own lines. Something like this is NOT permitted:

ISMIP6 has standardized on First-order Conservative Remapping (Jones, P.W. 1999, Monthly Weather Review, 127, 2204-2210), which does a better job of preserving integrals of the data, like flux, between the source and target grids, although it may have a larger local interpolation error than other methods. The CDO operator remapcon implements this method, and both generates the interpolation weights matrix and applies the weights:

infile.nc is the input netCDF file

outfile.nc is the output netCDF file

-setgrid,ingrid.txt (hyphen required) specifies the input grid description file. Note that this overrides any grid written in the input file. The total number of points (gridsize=) MUST match the number of points in the variables, but the structure (points in the x and y directions) can be different. (Formally, this runs the cdo setgrid operator to apply the grid description in ingrid.txt to infile.nc , before running the remapcon operator.)

remapcon,outgrid.txt says to do the conservative first-order remapping onto the grid described by outgrid.txt .

CDO’s syntax requires that there can be NO spaces following the commas after remapcon or setgrid.

remapcon is described in chapter 2.12 of the CDO User’s Guide . There is further information about conservative remapping including an outline of the mathematical basis in the SCRIP User’s Guide.

By default all variables in the input netCDF file will be remapped. To only do some of them, add the cdo selname operator:

which will select only the variables named var1 and var2 from the input file. You can specify as many as you like. See section 2.3.2 of the CDO User’s Guide for more options. As with -setgrid , there can be no spaces following the commas.

CDO is a suite of tools that enables the regridding of datasets as mentioned above. However, there is also a suite of tools called NCO (netCDF Operators). These tools can help prepare models for submissions by enabling the user to add/remove/change variables, attributes etc.

The easiest way to install the NCO tools is via Homebrew , MacPorts , or Anaconda . If that is not possible, the tools can be built from source via git. For more detailed information, consult the user guide here .

Below are some practical examples of these tools that may be of use to the community:

Note that this is using the remapYcon for the regridding.

This command copies the variables, “y, x, mapping” from: mapping_B03_05.nc to dlithkdt_GIS_BGC_BISICLES3_init_05km.nc

This command operates on the file, file.nc . To this file, it will add an attribute called, grid_mapping to the variable, topg . The value of the attribute, grid_mapping will be mapping . -h means to not add this operation to the history of all operations performed on this file. -a specifies that this is an attribute o specifies that it is to be overwritten, so if there is already an attribute named, grid_mapping , it will be overwritten with the value, mapping .

c Specifies to create the attribute, grid_mapping if it does not exist already.

Removes the variables, “ lat_bnds,lon_bnds,lat,lon” and outputs a new file called, outfile.nc . -C if output file, outfile.nc , doesn’t exist then it will be created -O output to a new file. -x extract all variables from infile.nc and output to outfile.nc , EXCEPT for the variables specified -v controls which variables are being removed

This removes the attribute, history from the variable, global . This operation is performed on the file, file.nc

This command will rename the variable, lat to latitude . It is operating on the file, file.nc .

Assuming the file, infile.nc , has a time variable, and it is an array of years (e.g. 0,1,2,3,4,…). This will multiply the seconds per year by the year number.

This reads in the file, infile.nc , and if it has a variable named, lon it converts the negative longitude to a 0-360 notation.

This command will crop data to just an area around Greenland. ncea still works, but it is being replaced by the command, nces . Note that the file must have variables, latitude and longitude .

This is an example of how to loop through all the variables of a group’s model and do the regridding.

Recommended articles