Skip to contents

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
)

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.

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.

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


compare_spct(source_mspct(list(sun1 = sun.spct, sun2 = sun.spct * 2)))
#> Object: generic_spct [52 x 6]
#> Wavelength range 285-795 nm, step 10 nm 
#> Variables:
#>   
#> --
#> # A tibble: 52 × 6
#>    w.length wl.min wl.max sun1.irrad sun2.irrad comparison.result
#>       <dbl>  <dbl>  <dbl>      <dbl>      <dbl>             <dbl>
#>  1      285    280    290    0          0                     NaN
#>  2      295    290    300    0.00204    0.00407                 2
#>  3      305    300    310    0.203      0.406                   2
#>  4      315    310    320    1.13       2.26                    2
#>  5      325    320    330    2.33       4.66                    2
#>  6      335    330    340    2.96       5.91                    2
#>  7      345    340    350    3.11       6.22                    2
#>  8      355    350    360    3.28       6.55                    2
#>  9      365    360    370    3.83       7.65                    2
#> 10      375    370    380    3.95       7.91                    2
#> # ℹ 42 more rows
compare_spct(source_mspct(list(sun1 = sun.spct, sun2 = sun.spct * 2)),
             w.band = NULL)
#> Object: generic_spct [1 x 6]
#> Wavelength range 540-540 nm, step NA nm 
#> Variables:
#>   
#> --
#> # A tibble: 1 × 6
#>   w.length wl.min wl.max sun1.irrad sun2.irrad comparison.result
#>      <dbl>  <dbl>  <dbl>      <dbl>      <dbl>             <dbl>
#> 1      540    280    800       269.       538.                 2
compare_spct(source_mspct(list(sun1 = sun.spct, sun2 = sun.spct * 2)),
             w.band = list(waveband(c(640, 650)), waveband(c(720, 740))))
#> Object: generic_spct [2 x 6]
#> Wavelength range 645-730 nm, step 85 nm 
#> Variables:
#>   
#> --
#> # A tibble: 2 × 6
#>   w.length wl.min wl.max sun1.irrad sun2.irrad comparison.result
#>      <dbl>  <dbl>  <dbl>      <dbl>      <dbl>             <dbl>
#> 1      645    640    650       5.86       11.7                 2
#> 2      730    720    740       8.39       16.8                 2

compare_spct(filter_mspct(list(pet = polyester.spct,
                               yllw = yellow_gel.spct)),
             w.band = 50,
             .comparison.fun = `<`)
#> Object: generic_spct [11 x 6]
#> Wavelength range 265-765 nm, step 50 nm 
#> Variables:
#>   
#> --
#> # A tibble: 11 × 6
#>    w.length wl.min wl.max pet.transmittance yllw.transmittance comparison.result
#>       <dbl>  <dbl>  <dbl>             <dbl>              <dbl> <lgl>            
#>  1      265    240    290           0.00385          0.0000100 TRUE             
#>  2      315    290    340           0.292            0.00219   TRUE             
#>  3      365    340    390           0.861            0.000821  TRUE             
#>  4      415    390    440           0.918            0.0000100 TRUE             
#>  5      465    440    490           0.925            0.0192    TRUE             
#>  6      515    490    540           0.924            0.526     TRUE             
#>  7      565    540    590           0.921            0.874     TRUE             
#>  8      615    590    640           0.918            0.896     TRUE             
#>  9      665    640    690           0.915            0.898     TRUE             
#> 10      715    690    740           0.913            0.900     TRUE             
#> 11      765    740    790           0.910            0.901     TRUE             

head(
  compare_spct(source_mspct(list(sun1 = sun.spct, sun2 = sun.spct * 2)),
               returned.value = "data.frame")
)
#>     w.length wl.min wl.max  sun1.irrad  sun2.irrad comparison.result
#> wb1      285    280    290 0.000000000 0.000000000               NaN
#> wb2      295    290    300 0.002035452 0.004070904                 2
#> wb3      305    300    310 0.203126713 0.406253425                 2
#> wb4      315    310    320 1.132016702 2.264033404                 2
#> wb5      325    320    330 2.332461209 4.664922418                 2
#> wb6      335    330    340 2.957299194 5.914598387                 2
compare_spct(source_mspct(list(sun1 = sun.spct, sun2 = sun.spct * 2)),
             returned.value = "tagged.spectrum")
#> Object: generic_spct [52 x 7]
#> Wavelength range 285-795 nm, step 10 nm 
#> Variables:
#>   
#> --
#> # A tibble: 52 × 7
#>    w.length sun1.irrad sun2.irrad comparison.result wl.color wb.color wb.f 
#>       <dbl>      <dbl>      <dbl>             <dbl> <chr>    <chr>    <fct>
#>  1      285    0          0                     NaN #000000  #000000  wb1  
#>  2      295    0.00204    0.00407                 2 #000000  black    wb2  
#>  3      305    0.203      0.406                   2 #000000  black    wb3  
#>  4      315    1.13       2.26                    2 #000000  black    wb4  
#>  5      325    2.33       4.66                    2 #000000  black    wb5  
#>  6      335    2.96       5.91                    2 #000000  black    wb6  
#>  7      345    3.11       6.22                    2 #000000  black    wb7  
#>  8      355    3.28       6.55                    2 #000000  black    wb8  
#>  9      365    3.83       7.65                    2 #000000  black    wb9  
#> 10      375    3.95       7.91                    2 #000000  black    wb10 
#> # ℹ 42 more rows
compare_spct(source_mspct(list(sun1 = sun.spct, sun2 = sun.spct * 2)),
             returned.value = "tagged.spectrum",
             use.hinges = TRUE)
#> Object: generic_spct [155 x 7]
#> Wavelength range 285-795 nm, step 1.023182e-12-5 nm 
#> Variables:
#>   
#> --
#> # A tibble: 155 × 7
#>    w.length sun1.irrad sun2.irrad comparison.result wl.color wb.color wb.f 
#>       <dbl>      <dbl>      <dbl>             <dbl> <chr>    <chr>    <fct>
#>  1     285     0          0                     NaN #000000  #000000  wb1  
#>  2     290.    0.00102    0.00204               NaN #000000  #000000  wb1  
#>  3     290     0.00102    0.00204               NaN #000000  black    wb2  
#>  4     295     0.00204    0.00407                 2 #000000  black    wb2  
#>  5     300.    0.103      0.205                   2 #000000  black    wb2  
#>  6     300     0.103      0.205                   2 #000000  black    wb3  
#>  7     305     0.203      0.406                   2 #000000  black    wb3  
#>  8     310.    0.668      1.34                    2 #000000  black    wb3  
#>  9     310     0.668      1.34                    2 #000000  black    wb4  
#> 10     315     1.13       2.26                    2 #000000  black    wb4  
#> # ℹ 145 more rows