View source: R/functions_netCDF.R
convert_xyspace | R Documentation |
Expand/collapse between separate and combined x and y dimensions
convert_xyspace(
grid,
data,
locations,
locations_crs = sf::st_crs(locations),
data_str = c("xyzt", "xyt", "xyz", "xy"),
direction = c("expand", "collapse")
)
grid |
An object that describes a gridded xy-space. Regular, rectangular grids are the only currently supported type. This can be
The crs of the grid coordinate values must match the one of the data locations. |
data |
A numeric array or vector (optional). A vector is converted to a one-column matrix. |
locations |
An object from which x and y coordinate values
can be extracted that describe the xy locations of each |
locations_crs |
An object which is a crs or
from which one can be derived
that describes the crs of |
data_str |
A character string describing the dimensions of |
direction |
A character string. The direction of the operation. |
A copy of data
with one dimension added/removed.
The expanding direction expects that the first dimension of data
matches the first dimension of locations
.
In this case, locations
and locations_crs
will be passed to
as_points
.
The use of data_str
currently refers to the "expanded" state
unlike how the argument is used by other functions. This may change
in future versions of this function.
tmp_nc <- create_example_netCDFs(tempdir(), "xyt", "timeseries")
data_xyt <- read_netCDF(tmp_nc[["xyt"]], "array", xy_names = c("x", "y"))
# Collapse x-y-t into xy-t format
res_collapsed <- convert_xyspace(
grid = data_xyt[["xyspace"]],
data = data_xyt[["data"]],
locations = expand.grid(data_xyt[["xyspace"]][c("x", "y")]),
data_str = "xyt",
direction = "collapse"
)
# Expand xy-t into x-y-t format
res_expanded <- convert_xyspace(
grid = data_xyt[["xyspace"]],
data = res_collapsed,
locations = expand.grid(data_xyt[["xyspace"]][c("x", "y")]),
data_str = "xyt",
direction = "expand"
)
# Round trip (using all grid locations) recovers data (but not names)
all.equal(data_xyt[["data"]], res_expanded, check.attributes = FALSE)
# Clean up
unlink(unlist(tmp_nc))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.