DiffuseRecord: Diffuse a record.

Description Usage Arguments Details Value Author(s) Examples

View source: R/DiffuseRecord.R

Description

This function diffuses a time series or record with a given depth-dependent diffusion length by convolution with a Gaussian kernel.

Usage

1
DiffuseRecord(rec, sigma, res = 1, debug = FALSE)

Arguments

rec

Numeric vector containing the record that is to be diffused.

sigma

Numeric vector of the diffusion lengths corresponding to the depths at which rec is tabulated. In units of the resolution of rec (typically [cm]).

res

Resolution of rec in the same units as sigma.

debug

if TRUE the values at top and bottom of the diffused record which are potentially affected by the finite record length are set to NA. Defaults to FALSE. See also Details.

Details

This function expects a numeric vector with the depth-dependent diffusion lengths of the same length as rec. To calculate the simple case of a constant diffusion length sigma.const, provide sigma = rep(sigma.const, length(rec)) as input.

The input diffusion length is internally scaled according to the resolution of the record given by res. The convolution integral is then solved by a simple summation over the kernel width set to ~ 10 times the current diffusion length.

For debug = FALSE: To avoid NAs at both ends of the diffused version of rec resulting from the kernel extending beyond the record ends, the kernel is clipped at the upper end to the range below the surface. At the lower end, the record is extended by ~ 10 times the maximum of sigma and filled with the mean average value of rec.

Value

Numeric vector containing the diffused version of rec.

Author(s)

Thomas Münch, modified by Thomas Laepple

Examples

1
2
3
4
5
6
7
8
9
## Diffuse white noise with a linearly increasing diffusion length
rec <- rnorm(n = 1000)
var.sigma <- seq(1, 8, length.out = 1000)
diffused <- proxysnr:::DiffuseRecord(rec = rec, sigma = var.sigma)
plot(rec, type = 'l', las = 1, xlab = "depth in cm", ylab = "data", main = 
     "white noise diffusion with linearly increasing diffusion length")
lines(diffused, col = "red")
legend('topleft', c("original record", "diffused record"),
       lty = 1, col = 1 : 2, bty = "n")

EarthSystemDiagnostics/proxysnr documentation built on Oct. 2, 2021, 3:03 p.m.