Skip to contents

Functions implementing fitting of peaks in a class-agnostic way. The fitting refines the location of peaks and value of peaks based on the location of maxima and minima supplied. This function is to be used together with find_peaks() or find_valleys().

Usage

fit_peaks(
  x,
  peaks.idx,
  span,
  x.col.name = NULL,
  y.col.name,
  method,
  max.span = 5L,
  maximum = TRUE,
  keep.cols = NULL
)

fit_valleys(
  x,
  valleys.idx,
  span,
  x.col.name = NULL,
  y.col.name,
  method,
  max.span = 5L,
  maximum = FALSE,
  keep.cols = NULL
)

Arguments

x

generic_spct or data.frame object.

peaks.idx, valleys.idx

logical or integer Indexes into x selecting global or local extremes.

span

odd integer The span used when refining the location of maxima or minima of x.

x.col.name, y.col.name

character Name of the column of x on which to operate.

method

character The method to use for the fit.

max.span

odd integer The maximum number of data points used when when refining the location of maxima and minima.

maximum

logical A flag indicating whether to search for maxima or minima.

keep.cols

logical Keep unrecognized columns in data frames

Value

An R object of the same class as x containing the fitted values for the peaks, and optionally the values for at peaks.idx or valleys.idx for other retained columns.

Note

These functions are not meant for everyday use. Use option refine.wl = TRUE of methods peaks() and valleys() instead.

Examples


peaks <- find_peaks(sun.spct[["s.e.irrad"]], span = 31)
fit_peaks(sun.spct, peaks, span = 31,
          y.col.name = "s.e.irrad", method = "spline")
#> Object: source_spct [11 x 2]
#> Wavelength range 378.0001-770.66484 nm, step 19.77647-85.83807 nm 
#> Label: sunlight, simulated 
#> Measured on 2010-06-22 09:51:00 UTC 
#> Measured at 60.20911 N, 24.96474 E; Kumpula, Helsinki, FI 
#> Variables:
#>  w.length: Wavelength [nm]
#>  s.e.irrad: Spectral energy irradiance [W m-2 nm-1] 
#> --
#> # A tibble: 11 × 2
#>    w.length s.e.irrad
#>       <dbl>     <dbl>
#>  1     378.     0.497
#>  2     412.     0.679
#>  3     451.     0.821
#>  4     475.     0.775
#>  5     495.     0.791
#>  6     529.     0.736
#>  7     582.     0.687
#>  8     605.     0.662
#>  9     662.     0.600
#> 10     748.     0.503
#> 11     771.     0.470