Skip to contents

These functions implement one original methods and acts as a wrapper for other common R smoothing functions. The advantage of using this function for smoothing spectral objects is that it simplifies the user interface and sets, when needed, defaults suitable for spectral data.

Usage

smooth_spct(x, method, strength, wl.range, ...)

# Default S3 method
smooth_spct(x, method, strength, wl.range, ...)

# S3 method for class 'source_spct'
smooth_spct(
  x,
  method = "custom",
  strength = 1,
  wl.range = NULL,
  na.rm = FALSE,
  ...
)

# S3 method for class 'filter_spct'
smooth_spct(
  x,
  method = "custom",
  strength = 1,
  wl.range = NULL,
  na.rm = FALSE,
  ...
)

# S3 method for class 'reflector_spct'
smooth_spct(
  x,
  method = "custom",
  strength = 1,
  wl.range = NULL,
  na.rm = FALSE,
  ...
)

# S3 method for class 'solute_spct'
smooth_spct(
  x,
  method = "custom",
  strength = 1,
  wl.range = NULL,
  na.rm = FALSE,
  ...
)

# S3 method for class 'response_spct'
smooth_spct(
  x,
  method = "custom",
  strength = 1,
  wl.range = NULL,
  na.rm = FALSE,
  ...
)

# S3 method for class 'cps_spct'
smooth_spct(
  x,
  method = "custom",
  strength = 1,
  wl.range = NULL,
  na.rm = FALSE,
  ...
)

# S3 method for class 'generic_mspct'
smooth_spct(
  x,
  method = "custom",
  strength = 1,
  wl.range = NULL,
  na.rm = FALSE,
  ...
)

Arguments

x

an R object.

method

a character string "custom", "lowess", "supsmu" or "skip"..

strength

numeric value to adjust the degree of smoothing. Ignored if method-specific parameters are passed through ....

wl.range

any R object on which applying the method range() yields a vector of two numeric values, describing a range of wavelengths (nm) within which spectral data is to be smoothed. NA is interpreted as the min or max value of x[[w.length]].

...

other parameters passed to the underlying smoothing functions.

na.rm

logical A flag indicating whether NA values should be stripped before the computation proceeds.

Value

A copy of x with spectral data values replaced by smoothed ones.

Methods (by class)

  • smooth_spct(default): Default for generic function

  • smooth_spct(source_spct): Smooth a source spectrum

  • smooth_spct(filter_spct): Smooth a filter spectrum

  • smooth_spct(reflector_spct): Smooth a reflector spectrum

  • smooth_spct(solute_spct): Smooth a solute attenuation spectrum

  • smooth_spct(response_spct): Smooth a response spectrum

  • smooth_spct(cps_spct): Smooth a counts per second spectrum

  • smooth_spct(generic_mspct):

Note

Method "custom" is our home-brewed method which applies strong smoothing to low signal regions of the spectral data, and weaker or no smoothing to the high signal areas. Values very close to zero are set to zero with a limit which depends on the local variation. This method is an ad-hock method suitable for smoothing spectral data obtained with spectrometers. In the cased of methods "lowess" and "supsmu" the current function behaves like a wrapper of the functions of the same names from base R. Method "skip" returns x unchanged.

Examples


my.spct <- clip_wl(sun.spct, c(400, 500))
smooth_spct(my.spct)
#> Object: source_spct [101 x 3]
#> Wavelength range 400-500 nm, step 1 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]
#>  s.q.irrad: Spectral photon irradiance [mol s-1 m-2 nm-1] 
#> --
#> # A tibble: 101 × 3
#>    w.length s.e.irrad  s.q.irrad
#>       <dbl>     <dbl>      <dbl>
#>  1      400     0.608 0.00000203
#>  2      401     0.626 0.00000210
#>  3      402     0.650 0.00000218
#>  4      403     0.621 0.00000209
#>  5      404     0.637 0.00000215
#>  6      405     0.626 0.00000212
#>  7      406     0.600 0.00000204
#>  8      407     0.595 0.00000202
#>  9      408     0.626 0.00000213
#> 10      409     0.662 0.00000226
#> # ℹ 91 more rows
smooth_spct(my.spct, method = "custom", strength = 1)
#> Object: source_spct [101 x 3]
#> Wavelength range 400-500 nm, step 1 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]
#>  s.q.irrad: Spectral photon irradiance [mol s-1 m-2 nm-1] 
#> --
#> # A tibble: 101 × 3
#>    w.length s.e.irrad  s.q.irrad
#>       <dbl>     <dbl>      <dbl>
#>  1      400     0.608 0.00000203
#>  2      401     0.626 0.00000210
#>  3      402     0.650 0.00000218
#>  4      403     0.621 0.00000209
#>  5      404     0.637 0.00000215
#>  6      405     0.626 0.00000212
#>  7      406     0.600 0.00000204
#>  8      407     0.595 0.00000202
#>  9      408     0.626 0.00000213
#> 10      409     0.662 0.00000226
#> # ℹ 91 more rows
smooth_spct(my.spct, method = "custom", strength = 4)
#> Object: source_spct [101 x 3]
#> Wavelength range 400-500 nm, step 1 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]
#>  s.q.irrad: Spectral photon irradiance [mol s-1 m-2 nm-1] 
#> --
#> # A tibble: 101 × 3
#>    w.length s.e.irrad  s.q.irrad
#>       <dbl>     <dbl>      <dbl>
#>  1      400     0.608 0.00000203
#>  2      401     0.626 0.00000210
#>  3      402     0.650 0.00000218
#>  4      403     0.621 0.00000209
#>  5      404     0.637 0.00000215
#>  6      405     0.626 0.00000212
#>  7      406     0.600 0.00000204
#>  8      407     0.595 0.00000202
#>  9      408     0.626 0.00000213
#> 10      409     0.662 0.00000226
#> # ℹ 91 more rows
smooth_spct(my.spct, method = "supsmu", strength = 4)
#> Object: source_spct [101 x 3]
#> Wavelength range 400-500 nm, step 1 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]
#>  s.q.irrad: Spectral photon irradiance [mol s-1 m-2 nm-1] 
#> --
#> # A tibble: 101 × 3
#>    w.length s.e.irrad  s.q.irrad
#>       <dbl>     <dbl>      <dbl>
#>  1      400     0.629 0.00000210
#>  2      401     0.627 0.00000210
#>  3      402     0.625 0.00000210
#>  4      403     0.623 0.00000210
#>  5      404     0.621 0.00000210
#>  6      405     0.627 0.00000212
#>  7      406     0.620 0.00000210
#>  8      407     0.620 0.00000211
#>  9      408     0.626 0.00000213
#> 10      409     0.627 0.00000214
#> # ℹ 91 more rows