Measures the intensity of emission lines in spectra: for each line, the
peak is searched near its tabulated wavelength, and its area or height is
measured. The result feeds boltzmann(), saha_boltzmann(),
cf_libs() and calibration_curve().
Usage
line_intensities(
spectra,
lines,
half_width = 0.15,
search = 0.2,
method = "area",
baseline = FALSE,
fit_width = 3 * half_width,
limit = NULL,
min_snr = 3
)Arguments
- spectra
The spectra: a numeric vector named by wavelength (one spectrum), or a matrix or data frame with one spectrum per row and the wavelengths as column names. Other columns of a data frame (such as sample names) are kept in the result.
- lines
The lines: a numeric vector of wavelengths (nm), whose names are used as labels, or a data frame with a
wavelengthcolumn, such as returned bynist_lines(), whose columns are kept in the result.- half_width
The half-width of the integration window around the peak, in nm. Default is 0.15.
- search
The half-width of the window in which the peak is searched around the tabulated wavelength, in nm. Default is 0.2.
- method
"area"(default),"height"or"voigt".- baseline
A logical: subtract a linear baseline under each line (
FALSE, default).- fit_width
The half-width of the window of the Voigt fit, in nm. Default is 3 times
half_width.- limit
The saturation limit of the detector, in counts, or
NULL(default) not to check saturation.- min_snr
The signal-to-noise ratio above which a line is detected. Default is 3.
Value
A tibble with one row per spectrum and line: the other columns
of spectra (or spectrum, the row number), the columns of lines
(or line and wavelength), and peak_wavelength, shift (nm),
height, intensity, intensity_se, snr, detected and
saturated (which replace the columns of lines of the same name,
such as the relative intensity listed by nist_lines()). For a single
spectrum, it has one row per line, like lines, with the measured
intensity.
Details
For each spectrum and line, the peak is the channel of highest intensity
within search nm of the tabulated wavelength, which absorbs small
errors of the wavelength calibration. The intensity is then measured on
the channels within half_width nm of the peak:
method = "area"(default): the integrated intensity (trapezoidal rule), in intensity units times nm;method = "height": the peak intensity;method = "voigt": the area of a Voigt profile fitted withpeak_fit()to the channels withinfit_widthnm of the peak. It separates the line from a flat background and is less sensitive to the window, but it is slower and needs a line well sampled by the detector.
With baseline = TRUE, a straight line through the intensities at both
ends of the window is subtracted before the area or height is measured
(the Voigt fit always includes a constant background).
Each line is also checked:
snr: the height above the baseline divided by the noise of the spectrum, estimated robustly from its channel-to-channel differences;detectedissnr >= min_snr.saturated: withlimit, whether a channel of the window reaches the saturation limit of the detector (seesaturation_summary()).
intensity_se is the standard error of the intensity due to the noise
of the spectrum: the noise (as for snr) propagated through the
integration and the baseline subtraction, or, for the Voigt method, the
standard error of the fitted area. The noise is taken as white and the
same in every channel, so this is a lower bound: it leaves out the
shot-to-shot fluctuations of the plasma, which usually dominate in LIBS.
These are better estimated from replicate spectra, as the standard
deviation of the intensities of the replicates divided by the square
root of their number. plasma_uncertainty() propagates intensity_se
to the temperature and the composition.
Examples
data(forageLIBS)
spectra <- forageLIBS[1:8, -(1:14)]
k <- c(`K I 404.41` = 404.414, `K I 404.72` = 404.721, `Mg I 518.36` = 518.360)
line_intensities(spectra, k, baseline = TRUE)
#> # A tibble: 24 × 11
#> spectrum line wavelength peak_wavelength shift height intensity
#> <int> <chr> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 1 K I 404.41 404. 404. -0.0512 1979. 166.
#> 2 1 K I 404.72 405. 405. -0.0233 898. 75.2
#> 3 1 Mg I 518.36 518. 518. -0.0560 5399 453.
#> 4 2 K I 404.41 404. 404. -0.0512 1688. 141.
#> 5 2 K I 404.72 405. 405. -0.0233 550. 46.0
#> 6 2 Mg I 518.36 518. 518. -0.0560 3484 293.
#> 7 3 K I 404.41 404. 404. -0.0512 2238. 187.
#> 8 3 K I 404.72 405. 405. -0.0233 1003. 84.0
#> 9 3 Mg I 518.36 518. 518. -0.0560 4444. 373.
#> 10 4 K I 404.41 404. 404. -0.0512 2071. 173.
#> # ℹ 14 more rows
#> # ℹ 4 more variables: intensity_se <dbl>, snr <dbl>, detected <lgl>,
#> # saturated <lgl>
# one spectrum and a table of lines, ready for a Boltzmann plot
lines <- data.frame(wavelength = c(428.30, 430.25, 443.50, 445.48),
Aki = c(4.34e7, 1.36e8, 6.70e7, 8.70e7), gk = c(5, 5, 5, 7),
Ek = c(4.78, 4.78, 4.68, 4.68))
mean_spectrum <- colMeans(forageLIBS[-(1:14)])
line_intensities(mean_spectrum, lines, baseline = TRUE)
#> # A tibble: 4 × 12
#> wavelength Aki gk Ek peak_wavelength shift height intensity
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 428. 43400000 5 4.78 428. -0.0487 4471. 376.
#> 2 430. 136000000 5 4.78 430. -0.0429 9200. 781.
#> 3 444. 67000000 5 4.68 443. -0.0721 4175. 349.
#> 4 445. 87000000 7 4.68 445. -0.0898 7780. 656.
#> # ℹ 4 more variables: intensity_se <dbl>, snr <dbl>, detected <lgl>,
#> # saturated <lgl>
