discretize_depth {ConFluxPro} | R Documentation |
Interpolate over depth to layered profile
Description
Interpolate and discretize data into a layered structure.
The output is a data.frame where each profile is separated into layers
that intersect at depths defined in the function call. See
cfp_layered_profile()
.
There are different interpolation methods implemented, which might be more practical for different parameters or tasks.
A
'linear'
interpolation for continuous parameters, (e.g. soil temperature).The
'boundary'
interpolation is only suitable for data that is already layered. It selects the value from the old layer that in which the new layer will lay in.-
A
'linspline'
interpolation fits a linear spline model to the data with knots defined inknots
-
'nearest'
finds the closest value to the new layer. You can define whether the closest value should be nearest to the top1
, or bottom0
of the layer usingint_depth
-
'harmonic'
is similar to a linear interpolation but it uses the harmonic meanharm()
using the distance in depth to each value as weights.
Multiple variables can be discretized at the same time by supplying
multiple column names in param
.
It is also possible to use different method
and controlling
parameters int_depth
and knots
for each param
.
Just provide a list of settings the same length as param
.
If only one value is given, but multiple param
the settings are
reused for each parameter.
Usage
discretize_depth(
df,
param,
method,
depth_target,
boundary_nearest = FALSE,
boundary_average = "none",
int_depth = 0.5,
knots = NULL,
...
)
## S3 method for class 'cfp_profile'
discretize_depth(
df,
param,
method,
depth_target,
boundary_nearest = FALSE,
boundary_average = "none",
int_depth = 0.5,
knots = NULL,
...
)
## S3 method for class 'data.frame'
discretize_depth(
df,
param,
method,
depth_target,
boundary_nearest = FALSE,
boundary_average = "none",
int_depth = 0.5,
knots = NULL,
id_cols = NULL,
...
)
Arguments
df |
(dataframe) The dataframe containing the parameters to be interpolated, as well as the columns "depth", "upper" and "lower". |
param |
(character vector) The column names name of the parameters to be interpolated. |
method |
(character vector) a character (-vector) specifying the methods to be used for interpolation. Must be in the same order as param. One of
|
depth_target |
(numeric vector or data frame) specifying the new layers. Must include n+1 depths for n target layers. If the target layers are different for id_cols, enter a data.frame instead.
This data frame must
have a "depth" column, as well as well as all |
boundary_nearest |
(logical) = TRUE/FALSE if it is TRUE then for target depth steps (partially) outside of the parameter boundaries, the nearest neighbor is returned, else returns NA. Default is FALSE. |
boundary_average |
("character) Defines what happens if the new layer contains multiple old layers. one of
|
int_depth |
(numeric vector) = value between 0 and 1 for 1 = interpolation takes the top of each depth step, 0.5 = middle and 0= bottom. Default = 0.5 |
knots |
(numeric vector) = the depths at which knots for the 'linspline' method are to be placed. If this differs for the parameters, a list of numeric vectors with the same length as "param" can be provided. Cannot differ between id_cols. |
... |
Internal, must be empty. |
id_cols |
Column names in data.frame that uniquely identify each profile. |
Value
A cfp_layered_profile()
data.frame with the variables upper
and lower
defining the layers derived from depth_target.
The column depth
is the middle of each layer. And all variables from
param
See Also
Other soilphys:
check_soilphys()
,
complete_soilphys()
,
soilphys_layered()
Examples
data("soiltemp")
library(dplyr)
dt <- data.frame(
site = rep(c("site_a", "site_b"), each = 12),
depth = c(5, seq(0,-100,-10), 7, seq(0,-100,-10)))
discretize_depth(df = soiltemp,
param = "t",
method = "linear",
depth_target = dt,
id_cols = c(
"site","Date"))