Learn R Programming

photobiology (version 0.11.3)

compare_spct: Coarse-grained comparison of two spectra

Description

Compare two spectra using a specified summary function pre-applied to wavelength intervals.

Usage

compare_spct(
  x,
  w.band = 10,
  .summary.fun = NULL,
  ...,
  .comparison.fun = `/`,
  returned.value = "spectrum",
  use.hinges = FALSE,
  short.names = TRUE
)

Value

A generic_spct, tagged or not with the wavebdans, or a

data.frame object containing the summary values per waveband for each spectrum and the result of applying the comparison function to these summaries.

Arguments

x

A collection of two spectral objects of the same type.

w.band

waveband object or a numeric stepsize in nanometres.

.summary.fun

function. The summary function to use. It must be a method accepting object x as first argument.

...

additional named arguments passed down to .summary.fun.

.comparison.fun

function. The comparison function to use.

returned.value

character One of "data.frame", "spectrum", "tagged.spectrum".

use.hinges

logical Flag indicating whether to insert "hinges" into the returned spectrum when tagging it.

short.names

logical Flag indicating whether to use short or long names for wavebands when tagging.

Details

Summaries are computed for each of the wavebands in w.band by applying function .summary.fun separately to each spectrum, after trimming them to the overlapping wavelength region. Next the matching summaries are compared by means of .comparison.fun. Both the summaries and the result of the comparison are returned. Columns containing summary values are named by concatenating the name each member spectrum with the name of the argument passed to .summary.fun.

Tagging is useful for plotting using wavelength based colours, or when names for wavebands are used as annotations. When tagging is requested, the spectrum is passed to method tag with use.hinges and short.names as additional arguments.

Examples

Run this code

compare_spct(source_mspct(list(sun1 = sun.spct, sun2 = sun.spct * 2)))
compare_spct(source_mspct(list(sun1 = sun.spct, sun2 = sun.spct * 2)),
             w.band = NULL)
compare_spct(source_mspct(list(sun1 = sun.spct, sun2 = sun.spct * 2)),
             w.band = list(waveband(c(640, 650)), waveband(c(720, 740))))

compare_spct(filter_mspct(list(pet = polyester.spct,
                               yllw = yellow_gel.spct)),
             w.band = 50,
             .comparison.fun = `<`)

head(
  compare_spct(source_mspct(list(sun1 = sun.spct, sun2 = sun.spct * 2)),
               returned.value = "data.frame")
)
compare_spct(source_mspct(list(sun1 = sun.spct, sun2 = sun.spct * 2)),
             returned.value = "tagged.spectrum")
compare_spct(source_mspct(list(sun1 = sun.spct, sun2 = sun.spct * 2)),
             returned.value = "tagged.spectrum",
             use.hinges = TRUE)

Run the code above in your browser using DataLab