Trim head and tail of a spectrum based on wavelength limits, with interpolation at range boundaries used by default. Expansion is also possible.
Usage
trim_wl(x, range, use.hinges, fill, ...)
# Default S3 method
trim_wl(x, range, use.hinges, fill, ...)
# S3 method for class 'generic_spct'
trim_wl(x, range = NULL, use.hinges = TRUE, fill = NULL, ...)
# S3 method for class 'generic_mspct'
trim_wl(
x,
range = NULL,
use.hinges = TRUE,
fill = NULL,
...,
.parallel = FALSE,
.paropts = NULL
)
# S3 method for class 'waveband'
trim_wl(
x,
range = NULL,
use.hinges = TRUE,
fill = NULL,
trim = getOption("photobiology.waveband.trim", default = TRUE),
...
)
# S3 method for class 'list'
trim_wl(
x,
range = NULL,
use.hinges = TRUE,
fill = NULL,
trim = getOption("photobiology.waveband.trim", default = TRUE),
...
)Arguments
- x
an R object.
- range
a numeric vector of length two, or any other object for which function range() will return two.
- 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 == NULLthen tails are deleted, otherwise tails are filled with the value of fill.- ...
ignored (possibly used by derived methods).
- .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.
- trim
logical (default is TRUE which trims the wavebands at the boundary, while FALSE discards wavebands that are partly off-boundary).
Value
A copy of x, usually trimmed or expanded to a different
length, either shorter or longer. Possibly with some of the original
spectral data values replaced with fill.
Note
By default the w.length values for the first and last rows
in the returned object are the values supplied as range.
trim_wl when applied to waveband objects always inserts hinges when trimming.
trim_wl when applied to waveband objects always inserts hinges when trimming.
See also
Other trim functions:
clip_wl(),
trim_spct(),
trim_waveband()
Examples
trim_wl(sun.spct, range = c(400, 500))
#> 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
trim_wl(sun.spct, range = c(NA, 500))
#> Object: source_spct [222 x 3]
#> Wavelength range 280-500 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: 222 × 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
#> # ℹ 212 more rows
trim_wl(sun.spct, range = c(400, NA))
#> Object: source_spct [401 x 3]
#> Wavelength range 400-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: 401 × 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
#> # ℹ 391 more rows
trim_wl(sun_evening.spct)
#> Object: source_spct [7,965 x 3]
#> containing 5 spectra in long form
#> Wavelength range 290-1000 nm, step 0.34-0.47 nm
#> Label: cosine.hour.9
#> time.01 measured on 2023-06-12 18:38:00.379657 UTC
#> time.02 measured on 2023-06-12 18:39:00.797266 UTC
#> time.03 measured on 2023-06-12 18:40:00.714554 UTC
#> time.04 measured on 2023-06-12 18:41:00.768459 UTC
#> time.05 measured on 2023-06-12 18:42:00.769065 UTC
#> Measured at 60.227 N, 24.018 E; Viikki, Helsinki, FI
#> Variables:
#> w.length: Wavelength [nm]
#> s.e.irrad: Spectral energy irradiance [W m-2 nm-1]
#> --
#> # A tibble: 7,965 × 3
#> w.length s.e.irrad spct.idx
#> <dbl> <dbl> <fct>
#> 1 290 0 time.01
#> 2 290. 0 time.01
#> 3 291. 0 time.01
#> 4 291. 0 time.01
#> 5 292. 0 time.01
#> 6 292. 0 time.01
#> 7 293. 0 time.01
#> 8 293. 0 time.01
#> 9 294. 0 time.01
#> 10 294. 0 time.01
#> # ℹ 7,955 more rows
trim_wl(sun_evening.mspct)
#> Object: source_mspct [5 x 1]
#> --- Member: time.01 ---
#> Object: source_spct [1,593 x 2]
#> Wavelength range 290-1000 nm, step 0.34-0.47 nm
#> Label: cosine.hour.9
#> Measured on 2023-06-12 18:38:00.379657 UTC
#> Measured at 60.227 N, 24.018 E; Viikki, Helsinki, FI
#> Variables:
#> w.length: Wavelength [nm]
#> s.e.irrad: Spectral energy irradiance [W m-2 nm-1]
#> --
#> # A tibble: 1,593 × 2
#> w.length s.e.irrad
#> <dbl> <dbl>
#> 1 290 0
#> 2 290. 0
#> 3 291. 0
#> 4 291. 0
#> 5 292. 0
#> 6 292. 0
#> 7 293. 0
#> 8 293. 0
#> 9 294. 0
#> 10 294. 0
#> # ℹ 1,583 more rows
#> --- Member: time.02 ---
#> Object: source_spct [1,593 x 2]
#> Wavelength range 290-1000 nm, step 0.34-0.47 nm
#> Label: cosine.hour.9
#> Measured on 2023-06-12 18:39:00.797266 UTC
#> Measured at 60.227 N, 24.018 E; Viikki, Helsinki, FI
#> Variables:
#> w.length: Wavelength [nm]
#> s.e.irrad: Spectral energy irradiance [W m-2 nm-1]
#> --
#> # A tibble: 1,593 × 2
#> w.length s.e.irrad
#> <dbl> <dbl>
#> 1 290 0
#> 2 290. 0
#> 3 291. 0
#> 4 291. 0
#> 5 292. 0
#> 6 292. 0
#> 7 293. 0
#> 8 293. 0
#> 9 294. 0
#> 10 294. 0
#> # ℹ 1,583 more rows
#> --- Member: time.03 ---
#> Object: source_spct [1,593 x 2]
#> Wavelength range 290-1000 nm, step 0.34-0.47 nm
#> Label: cosine.hour.9
#> Measured on 2023-06-12 18:40:00.714554 UTC
#> Measured at 60.227 N, 24.018 E; Viikki, Helsinki, FI
#> Variables:
#> w.length: Wavelength [nm]
#> s.e.irrad: Spectral energy irradiance [W m-2 nm-1]
#> --
#> # A tibble: 1,593 × 2
#> w.length s.e.irrad
#> <dbl> <dbl>
#> 1 290 0
#> 2 290. 0
#> 3 291. 0
#> 4 291. 0
#> 5 292. 0
#> 6 292. 0
#> 7 293. 0
#> 8 293. 0
#> 9 294. 0
#> 10 294. 0
#> # ℹ 1,583 more rows
#> --- Member: time.04 ---
#> Object: source_spct [1,593 x 2]
#> Wavelength range 290-1000 nm, step 0.34-0.47 nm
#> Label: cosine.hour.9
#> Measured on 2023-06-12 18:41:00.768459 UTC
#> Measured at 60.227 N, 24.018 E; Viikki, Helsinki, FI
#> Variables:
#> w.length: Wavelength [nm]
#> s.e.irrad: Spectral energy irradiance [W m-2 nm-1]
#> --
#> # A tibble: 1,593 × 2
#> w.length s.e.irrad
#> <dbl> <dbl>
#> 1 290 0
#> 2 290. 0
#> 3 291. 0
#> 4 291. 0
#> 5 292. 0
#> 6 292. 0
#> 7 293. 0
#> 8 293. 0
#> 9 294. 0
#> 10 294. 0
#> # ℹ 1,583 more rows
#> --- Member: time.05 ---
#> Object: source_spct [1,593 x 2]
#> Wavelength range 290-1000 nm, step 0.34-0.47 nm
#> Label: cosine.hour.9
#> Measured on 2023-06-12 18:42:00.769065 UTC
#> Measured at 60.227 N, 24.018 E; Viikki, Helsinki, FI
#> Variables:
#> w.length: Wavelength [nm]
#> s.e.irrad: Spectral energy irradiance [W m-2 nm-1]
#> --
#> # A tibble: 1,593 × 2
#> w.length s.e.irrad
#> <dbl> <dbl>
#> 1 290 0
#> 2 290. 0
#> 3 291. 0
#> 4 291. 0
#> 5 292. 0
#> 6 292. 0
#> 7 293. 0
#> 8 293. 0
#> 9 294. 0
#> 10 294. 0
#> # ℹ 1,583 more rows
#>
#> --- END ---
