sl.contours: Compute Contours

sl.contoursR Documentation

Compute Contours

Description

Compute contour lines of a 2-dimensional field on an unstructured triangular mesh on a sphere.

Usage

sl.contours(var = NULL, var.nc = NULL, varid = NULL, levels = 0, grd = NULL, na.treatment = "none",
          return.edge.info = FALSE, verbose = FALSE, neighmat = NULL, lat = NULL, lon = NULL, elem = NULL)

Arguments

var

a numeric vector of length N resembling a 2-dimensional field on an unstructured mesh on a sphere.

var.nc

a character providing the system location of a NetCDF file containing the field to be analysed. Used only if var is not specified.

varid

a character providing the name of the variable in var.nc to be used. Used only if var is not specified.

levels

a vector providing the values for which contour lines shall be computed.

grd

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

na.treatment

a character specifying how to handle NA values. One of 'none' (can result in errors), 'fill' (it is attempted to fill NA values using adjacent grid points, iteratively where required, using sl.field.fillNA, or 'cut' (NA values are excluded from the grid using sl.grid.reduce, which can slow down the function by a factor 2 or more).

return.edge.info

a logical value specifiying whether information on end points of, and relative positions on, the edges corresponding to each point of the contour(s) shall be returned. Default is FALSE.

verbose

a logical value specifiying whether additional statements shall be printed to document progress. Default is FALSE.

neighmat

an NxM matrix providing the neighbour nodes of each node (point) in var (or var.nc). If not provided (and not provided as 'grd$neighnodes'), this matrix is computed using sl.findneighbours based on elem. This argument is used (or computed) only if 'grd$neighnodes' is not provided.

lat

a numeric vector of length N providing the latitudes of each node (point) in var (or var.nc). Only used if 'grd$lat' is not provided.

lon

a numeric vector of length N providing the latitudes of each node (point) in var (or var.nc). Only used if 'grd$lon' is not provided.

elem

an Nex3 matrix providing the vertex indices of each triangular element spanned by the nodes (points) in var (or var.nc). Note that Ne ~= 2xN. Only used if 'grd$elem' is not provided.

Details

The algorithm implemented here does not work element-wise, but builds up contiguous contour segments step by step. Note that a linear evolution of the field on the elements (triangles) between the nodes is assumed.

Value

A list with one element for each level. Each of these is another list with the following elements:

level

a scalar giving the level of the contour.

segments

a list of lists for each segment with elements lat (vector with latitudes of the Ns points forming the segment), lon (vector with longitudes of the Ns points forming the segment), and length (scalar giving the length of the segment). If return.edge.info=TRUE, the additional elements edge.endpoints (Nsx2 integer matrix providing the end points of the edges corresponding to each point on the contour) and edge.relpos (vector giving the relative positions of the Ns contour points on the respective edge) are included.

length

a scalar giving the length of the contour, summing all segments.

Note

It is planned to extend this algorithm such that it works with any unstructured mesh based on polygons with any number of vertices. One simple way to achieve this would be to add a step at the beginning where any polygon with more than 3 vertices is decomposed into triangles, e.g. with a central reference point based on the polygon centroid.

Author(s)

Helge Goessling

Examples

## Example to be provided ...

helgegoessling/spheRlab documentation built on March 8, 2024, 7:54 p.m.