Skip to contents

Trim head and tail of a spectrum based on wavelength limits, interpolating the values at the boundaries of the range. Trimming is needed for example to remove short wavelength noise when the measured spectrum extends beyond the known emission spectrum of the measured light source. Occasionally one may want also to expand the wavelength range.

Usage

trim_spct(
  spct,
  range = NULL,
  low.limit = NULL,
  high.limit = NULL,
  use.hinges = TRUE,
  fill = NULL,
  byref = FALSE,
  verbose = getOption("photobiology.verbose")
)

trim_mspct(
  mspct,
  range = NULL,
  low.limit = NULL,
  high.limit = NULL,
  use.hinges = TRUE,
  fill = NULL,
  byref = FALSE,
  verbose = getOption("photobiology.verbose"),
  .parallel = FALSE,
  .paropts = NULL
)

trim2overlap(
  mspct,
  use.hinges = TRUE,
  verbose = getOption("photobiology.verbose"),
  .parallel = FALSE,
  .paropts = NULL
)

extend2extremes(
  mspct,
  use.hinges = TRUE,
  fill = NA,
  verbose = getOption("photobiology.verbose"),
  .parallel = FALSE,
  .paropts = NULL
)

Arguments

spct

an object of class "generic_spct".

range

a numeric vector of length two, or any other object for which method range() will return a numeric vector of length two.

low.limit

shortest wavelength to be kept (defaults to shortest w.length value).

high.limit

longest wavelength to be kept (defaults to longest w.length value).

use.hinges

logical Flag indicating whether to insert "hinges" into the spectral data before integration so as to reduce interpolation errors at the boundaries of the wavebands.

fill

if fill==NULL then tails are deleted, otherwise tails or s.irrad are filled with the value of fill.

byref

logical indicating if new object will be created by reference or by copy of spct.

verbose

logical.

mspct

an object of class "generic_mspct"

.parallel

if TRUE, apply function in parallel, using parallel backend provided by foreach

.paropts

a list of additional options passed into the foreach function when parallel computation is enabled. This is important if (for example) your code relies on external data or packages: use the .export and .packages arguments to supply them so that all cluster nodes have the correct environment set up for computing.

Value

a spectrum object or a collection of spectral objects of the same class as x with wavelength heads and tails clipped or extended.

Note

When expanding a spectrum, if fill==NULL, then expansion is not performed. Range can be "waveband" object, a numeric vector or a list of numeric vectors, or any other user-defined or built-in object for which range() returns a numeric vector of length two, that can be interpreted as wavelengths expressed in nm.

See also

Other trim functions: clip_wl(), trim_waveband(), trim_wl()

Examples

trim_spct(sun.spct, low.limit=300)
#> Object: source_spct [501 x 3]
#> Wavelength range 300-800 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: 501 × 3
#>    w.length s.e.irrad     s.q.irrad
#>       <dbl>     <dbl>         <dbl>
#>  1      300   0.00126 0.00000000317
#>  2      301   0.00262 0.00000000660
#>  3      302   0.00392 0.00000000990
#>  4      303   0.00897 0.0000000227 
#>  5      304   0.0117  0.0000000296 
#>  6      305   0.0180  0.0000000459 
#>  7      306   0.0208  0.0000000531 
#>  8      307   0.0306  0.0000000785 
#>  9      308   0.0400  0.000000103  
#> 10      309   0.0416  0.000000108  
#> # ℹ 491 more rows
trim_spct(sun.spct, low.limit=300, fill=NULL)
#> Object: source_spct [501 x 3]
#> Wavelength range 300-800 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: 501 × 3
#>    w.length s.e.irrad     s.q.irrad
#>       <dbl>     <dbl>         <dbl>
#>  1      300   0.00126 0.00000000317
#>  2      301   0.00262 0.00000000660
#>  3      302   0.00392 0.00000000990
#>  4      303   0.00897 0.0000000227 
#>  5      304   0.0117  0.0000000296 
#>  6      305   0.0180  0.0000000459 
#>  7      306   0.0208  0.0000000531 
#>  8      307   0.0306  0.0000000785 
#>  9      308   0.0400  0.000000103  
#> 10      309   0.0416  0.000000108  
#> # ℹ 491 more rows
trim_spct(sun.spct, low.limit=300, fill=NA)
#> Object: source_spct [523 x 3]
#> Wavelength range 280-800 nm, step 1.023182e-12-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: 523 × 3
#>    w.length s.e.irrad s.q.irrad
#>       <dbl>     <dbl>     <dbl>
#>  1     280         NA        NA
#>  2     281.        NA        NA
#>  3     282.        NA        NA
#>  4     283.        NA        NA
#>  5     284.        NA        NA
#>  6     285.        NA        NA
#>  7     286.        NA        NA
#>  8     286.        NA        NA
#>  9     287.        NA        NA
#> 10     288.        NA        NA
#> # ℹ 513 more rows
trim_spct(sun.spct, low.limit=300, fill=0.0)
#> Object: source_spct [523 x 3]
#> Wavelength range 280-800 nm, step 1.023182e-12-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: 523 × 3
#>    w.length s.e.irrad s.q.irrad
#>       <dbl>     <dbl>     <dbl>
#>  1     280          0         0
#>  2     281.         0         0
#>  3     282.         0         0
#>  4     283.         0         0
#>  5     284.         0         0
#>  6     285.         0         0
#>  7     286.         0         0
#>  8     286.         0         0
#>  9     287.         0         0
#> 10     288.         0         0
#> # ℹ 513 more rows
trim_spct(sun.spct, range = c(300, 400))
#> Object: source_spct [101 x 3]
#> Wavelength range 300-400 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      300   0.00126 0.00000000317
#>  2      301   0.00262 0.00000000660
#>  3      302   0.00392 0.00000000990
#>  4      303   0.00897 0.0000000227 
#>  5      304   0.0117  0.0000000296 
#>  6      305   0.0180  0.0000000459 
#>  7      306   0.0208  0.0000000531 
#>  8      307   0.0306  0.0000000785 
#>  9      308   0.0400  0.000000103  
#> 10      309   0.0416  0.000000108  
#> # ℹ 91 more rows
trim_spct(sun.spct, range = c(300, NA))
#> Object: source_spct [501 x 3]
#> Wavelength range 300-800 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: 501 × 3
#>    w.length s.e.irrad     s.q.irrad
#>       <dbl>     <dbl>         <dbl>
#>  1      300   0.00126 0.00000000317
#>  2      301   0.00262 0.00000000660
#>  3      302   0.00392 0.00000000990
#>  4      303   0.00897 0.0000000227 
#>  5      304   0.0117  0.0000000296 
#>  6      305   0.0180  0.0000000459 
#>  7      306   0.0208  0.0000000531 
#>  8      307   0.0306  0.0000000785 
#>  9      308   0.0400  0.000000103  
#> 10      309   0.0416  0.000000108  
#> # ℹ 491 more rows
trim_spct(sun.spct, range = c(NA, 400))
#> Object: source_spct [122 x 3]
#> Wavelength range 280-400 nm, step 0.9230769-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: 122 × 3
#>    w.length s.e.irrad s.q.irrad
#>       <dbl>     <dbl>     <dbl>
#>  1     280          0         0
#>  2     281.         0         0
#>  3     282.         0         0
#>  4     283.         0         0
#>  5     284.         0         0
#>  6     285.         0         0
#>  7     286.         0         0
#>  8     286.         0         0
#>  9     287.         0         0
#> 10     288.         0         0
#> # ℹ 112 more rows