sl.grid.curvilin2unstr | R Documentation |
Convert a curvilinear grid, where fields are provided in matrices and lat-lon coordinates are provided either in matrices (general) or vectors (only for lat-lon meshes), into an identical unstructured grid. The conversion allows to apply all the unstructured-grid algorithms also to curvilinear-grid data, without remapping.
sl.grid.curvilin2unstr(lon = NULL, lat = NULL, Nx = NULL, Ny = NULL, vars = NULL, neighnodes = TRUE, neighelems = TRUE, quad2triag = TRUE, quad2triag.mode = "zigzag", transpose = FALSE, cut.top = 0, cut.bottom = 0, cut.left = 0, cut.right = 0, close.sides = FALSE, close.top = FALSE, close.bottom = FALSE, close.topbottom.skip = "none")
lon |
an Nx X Ny matrix or an Nx vector providing the longitudes of the curvilinear grid, or |
lat |
an Nx X Ny matrix or an Ny vector providing the latitudes of the curvilinear grid, or |
Nx |
an integer specifying the number of longitudes. Default is |
Ny |
an integer specifying the number of latitudes. Default is |
vars |
a list of variables defined on the curvilinear grid. If the list elements are matrices, they are converted to vectors before they are returned. |
neighnodes |
a logical value specifying whether to return a matrix with the neighbour nodes for each node. Default is |
neighelems |
a logical value specifying whether to return a matrix with the neighbour elements for each node. Default is |
quad2triag |
a logical value specifying whether to cut rectangles into triangles. Default is |
quad2triag.mode |
a character specifying how to cut rectangles into triangles (if |
transpose |
a logical value specifying whether to transpose the input matrices. This will affect the order of nodes in the output mesh and which sides of the matrix are considered as 'sides', 'top', and 'bottom', which is relevant for boundary cut-offs and closure (see further arguments). Default is |
cut.top |
an integer specifying how many rows at the top (first rows) are removed. Default is |
cut.bottom |
an integer specifying how many rows at the bottom (last rows) are removed. Default is |
cut.left |
an integer specifying how many columns at the left (first columns) are removed. Default is |
cut.right |
an integer specifying how many columns at the right (last columns) are removed. Default is |
close.sides |
a logical value specifying whether to close the gap at the sides by connecting the first and last columns (or rows if |
close.top |
a logical value specifying whether to close the 'pole hole' at the top by connecting the first row (or column if |
close.bottom |
a logical value specifying whether to close the 'pole hole' at the bottom by connecting the last row (or column if |
close.topbottom.skip |
a character, one of |
To remove land points from the grid, use sl.grid.reduce
, see the example below.
Closing the top and/or bottom boundaries works only with an even number of columns.
If the input is based on matrices (rather than lon/lat vectors), the returned element curvilin2unstr.fun
is a function that can be used to convert data from the original curvilinear grid to the unstructured grid.
a list with the elements lon
, lat
, elem
, coast
, openbound
, neighnodes
, neighelems
, vars
, and curvilin2unstr.fun
. Some of these may be NULL
, depending on the input arguments and on which options have already been implemented.
Helge Goessling
sl.grid.reduce
# generate an example curvilinear grid
lon.0 = seq(-60,60,5)
lat.0 = seq(-30,30,5)
grd.0 = sl.grid.curvilin2unstr(lon = lon.0, lat = lat.0)
abg = sl.lonlatrot2abg(c(5,-20,0))
rot.lonlat = sl.rot(lon = grd.0$lon, lat = grd.0$lat, alpha = abg[1], beta = abg[2], gamma = abg[3])
grd = grd.0
grd$lon = rot.lonlat$lon
grd$lat = rot.lonlat$lat
# generate corresponding example data and insert NAs that define a land mask (arbitrary,
# not matching true land coordinates)
dat = exp(-((sl.gc.dist(lon = c(180,grd$lon), lat = c(85,grd$lat), sequential = FALSE)/0.4)^2))
dat.orig = dat
dat[c(7,140,250)] = NA
for (i in 1:2) {
for (j in which(is.na(dat))) {
dat[grd$neighnodes[j,]] = NA
}
}
# remove land nodes from the grid
grd.reduced = sl.grid.reduce(grd = grd, remove.points = is.na(dat), return.info = TRUE)
# compute the 0.15-contour on the reduced grid
cont = sl.contours(var = dat[grd.reduced$reduce.kept$nodes], elem = grd.reduced$elem, levels = 0.15, neighmat = grd.reduced$neighnodes, lon = grd.reduced$lon, lat = grd.reduced$lat)
# plot
pir = sl.plot.init(projection = "polar", do.init.device = FALSE, col.background = "lightgrey")
cb1 = sl.plot.field.elem(pir, dat.orig, lon = grd$lon, lat=grd$lat, elem=grd$elem,
colbar = sl.colbar(cols=c("red","yellow")))
cb2 = sl.plot.field.elem(pir, dat[grd.reduced$reduce.kept$nodes], lon = grd.reduced$lon,
lat = grd.reduced$lat, elem = grd.reduced$elem, colbar = sl.colbar(cols=c("darkblue","white")))
cont = sl.contours(var = dat[grd.reduced$reduce.kept$nodes], elem = grd.reduced$elem,
levels = 0.15, neighmat = grd.reduced$neighnodes, lon = grd.reduced$lon, lat = grd.reduced$lat)
sl.plot.contours(pir, cont, col = "white", lwd = 2)
sl.plot.end(pir, do.close.device = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.