Binary operation on two spectra, even if the wavelengths values differ
Source:R/oper.spectra.r
oper_spectra.Rd
The wavelength vectors of the two spectra are merged, and the missing spectral values are calculated by interpolation. After this, the two spectral values at each wavelength are added.
Usage
oper_spectra(
w.length1,
w.length2 = NULL,
s.irrad1,
s.irrad2,
trim = "union",
na.rm = FALSE,
bin.oper = NULL,
...
)
Arguments
- w.length1
numeric vector of wavelength (nm)
- w.length2
numeric vector of wavelength (nm)
- s.irrad1
a numeric vector of spectral values
- s.irrad2
a numeric vector of spectral values
- trim
a character string with value "union" or "intersection"
- na.rm
a logical value, if TRUE, not the default, NAs in the input are replaced with zeros
- bin.oper
a function defining a binary operator (for the usual math operators enclose argument in backticks)
- ...
additional arguments (by name) passed to bin.oper
Value
a dataframe with two numeric variables
- w.length
A numeric vector with the wavelengths (nm) obtained by "fusing" w.length1 and w.length2. w.length contains all the unique vales, sorted in ascending order.
- s.irrad
A numeric vector with the sum of the two spectral values at each wavelength.
Details
If trim=="union" spectral values are calculated for the whole range of wavelengths covered by at least one of the input spectra, and missing values are set in each input spectrum to zero before addition. If trim=="intersection" then the range of wavelengths covered by both input spectra is returned, and the non-overlapping regions discarded. If w.length2==NULL, it is assumed that both spectra are measured at the same wavelengths, and a simple addition is used, ensuring fast calculation.
See also
Other low-level functions operating on numeric vectors.:
as_energy()
,
as_quantum_mol()
,
calc_multipliers()
,
div_spectra()
,
energy_irradiance()
,
energy_ratio()
,
insert_hinges()
,
integrate_xy()
,
interpolate_spectrum()
,
irradiance()
,
l_insert_hinges()
,
photon_irradiance()
,
photon_ratio()
,
photons_energy_ratio()
,
prod_spectra()
,
s_e_irrad2rgb()
,
split_energy_irradiance()
,
split_photon_irradiance()
,
subt_spectra()
,
sum_spectra()
,
trim_tails()
,
v_insert_hinges()
,
v_replace_hinges()
Examples
head(sun.data)
#> w.length s.e.irrad s.q.irrad
#> 1 293 2.609665e-06 6.391823e-12
#> 2 294 6.142401e-06 1.509586e-11
#> 3 295 2.176175e-05 5.366463e-11
#> 4 296 6.780119e-05 1.677650e-10
#> 5 297 1.533491e-04 3.807237e-10
#> 6 298 3.669677e-04 9.141478e-10
result.data <-
with(sun.data,
oper_spectra(w.length, w.length, s.e.irrad, s.e.irrad, bin.oper=`+`))
head(result.data)
#> # A tibble: 6 × 2
#> w.length s.irrad
#> <dbl> <dbl>
#> 1 293 0.00000522
#> 2 294 0.0000123
#> 3 295 0.0000435
#> 4 296 0.000136
#> 5 297 0.000307
#> 6 298 0.000734
tail(result.data)
#> # A tibble: 6 × 2
#> w.length s.irrad
#> <dbl> <dbl>
#> 1 795 0.829
#> 2 796 0.816
#> 3 797 0.828
#> 4 798 0.847
#> 5 799 0.837
#> 6 800 0.814
my_fun <- function(e1, e2, k) {return((e1 + e2) / k)}
result.data <-
with(sun.data,
oper_spectra(w.length, w.length, s.e.irrad, s.e.irrad, bin.oper=my_fun, k=2))
head(result.data)
#> # A tibble: 6 × 2
#> w.length s.irrad
#> <dbl> <dbl>
#> 1 293 0.00000261
#> 2 294 0.00000614
#> 3 295 0.0000218
#> 4 296 0.0000678
#> 5 297 0.000153
#> 6 298 0.000367
tail(result.data)
#> # A tibble: 6 × 2
#> w.length s.irrad
#> <dbl> <dbl>
#> 1 795 0.415
#> 2 796 0.408
#> 3 797 0.414
#> 4 798 0.424
#> 5 799 0.419
#> 6 800 0.407