sl.grid.writeCDO: Write Grid for CDO

sl.grid.writeCDOR Documentation

Write Grid for CDO

Description

Write a spheRlab grid to a grid description file that makes unstructured-mesh data readable by the Climate Data Operators (CDO).

Usage

sl.grid.writeCDO(grid, ofile = "~/sl.grid.nc", netcdf = TRUE, netcdf.prec = "double", ascii.digits = Inf, overwrite = FALSE, verbose = TRUE, cell_area = TRUE, node_node_links = TRUE, triag_nodes = TRUE, coast = TRUE, depth = TRUE, ofile.ZAXIS = paste0(ofile,"_zaxis.txt"), fesom2velocities = FALSE, conventions = "original")

Arguments

grid

a spheRlab grid list as returned by sl.grid.readFESOM.

ofile

a character specifying the path and file name of the output file.

netcdf

a logical value indicating whether or not to write directly to NetCDF (default). If FALSE, only the variables lon, lon_bnds, lat, and lat_bnds are written in an ascii format that can be coverted subsequently to NetCDF using CDO. The latter is much slower.

netcdf.prec

a character defining the precision at which the (non-integer) variables are written. Reasonable options are "float" and "double" (default). Used only if netcdf=TRUE.

ascii.digits

a scalar giving the number of digits after which coordinates are truncated (rounded). Used only if netcdf=FALSE.

overwrite

a logical value indicating whether or not to overwrite an already existing file.

verbose

a logical value indicating whether or not print statements shall report on the function progess.

cell_area

a logical value indicating whether or not to add cell (stamp polygon) areas (from grid$cellareas). Used only if netcdf=TRUE.

node_node_links

a logical value indicating whether or not to add node-node links (from grid$neighnodes). Used only if netcdf=TRUE.

triag_nodes

a logical value indicating whether or not to add triangular element triplets (from grid$elem). Used only if netcdf=TRUE.

coast

a logical value indicating whether or not to add coast information (from grid$coast). Used only if netcdf=TRUE.

depth

a logical value indicating whether or not to add a vector with the depth of each grid level (from grid$depth) and a vector that provides the number of active (wet) levels underneath each surface node (from grid$depth.lev). Used only if netcdf=TRUE.

ofile.ZAXIS

a character specifying the z-axis ascii output file. Used only if depth=TRUE. To suppress the generation of a z-axis description file, set ofile.ZAXIS=NULL. Default is paste0(ofile,"_zaxis.txt").

fesom2velocities

a logical value indicating whether or not a grid description for values defined at the centroids of the triangular elements (like horizontal velocities in FESOM2) instead of at the vertices shall be generated. Implemented only for netcdf=TRUE.

conventions

a character influencing the variable, dimension, and unit naming conventions. Set this to "IFS" to generate files readable by ECMWF's 'prepIFS' tool. Default is "original".

Details

This is a special function that is typically used when converting FESOM grid information to a CDO-readable format. To use the resulting file with CDOs, use the operator 'setgrid', e.g., 'CDO setgrid,gridfile.nc ifile.nc ofile.nc', where 'gridfile.nc' is the file generated with sl.grid.writeCDO() and 'ifile.nc' is a FESOM output file.

See also the CDO operator 'setzaxis' to set the z-axis with the also generated z-axis description file (if applicable).

Note that in case of 3D data (including several depth levels), depending on the exact format of the original FESOM output file, it might be necessary to add information directly to the NetCDF file about the order in which the dimensions are stored before 'setgrid' can be applied. For example, if the dimensions in original FESOM2 output are stored in the unusual order time-horizontal-vertical (most tools expect time-vertical-horizontal) and the z-axis is not identifyable by certain attributes, this information must be added to the relevant variables, e.g. with the NCOs as follows:

ncatted -a axis,<varname>,c,c,"T-Z" fesom_output.nc

Author(s)

Helge Goessling

See Also

sl.grid.readFESOM, sl.grid.writeZAXIS

Examples

## Not run: 
# In this example a 'backward rotation' is performed, assuming that the original mesh coordinates are rotated;
# if that's not the case (which is now default), set 'rot=FALSE' or leave it unspecified (default is FALSE).
grid = sl.grid.readFESOM(griddir="PATH-TO-YOUR-FESOM-GRID",rot=TRUE,rot.invert=TRUE,rot.abg=c(50,15,-90))

# Write a grid description that is valid for quantities defined at nodes:
sl.grid.writeCDO(grid,ofile="~/sl.grid.scalars.nc")

# Write a grid description that is valid for quantities defined at element centers (or representative for elements):
sl.grid.writeCDO(grid,ofile="~/sl.grid.vectors.nc",fesom2velocities=TRUE)

## End(Not run)

helgegoessling/spheRlab documentation built on April 8, 2024, 8:34 a.m.