line_finder: Interactive Identification of Emission Lines

View source: R/line_finder.R

line_finderR Documentation

Interactive Identification of Emission Lines

Description

Launches a Shiny app to identify the emission lines of LIBS spectra. Elements are selected on a periodic table, and the strongest lines of their selected ionization stages, from the NIST Atomic Spectra Database, are overlaid on a spectrum in an interactive plotly graph, with one color per ionization stage. The heads of molecular bands can be overlaid too. Lines of a species picked on the spectrum build a Boltzmann plot, whose temperature is fitted again as lines are added or left out.

Usage

line_finder(
  spectra,
  launch_browser = interactive(),
  show_table = TRUE,
  launch.browser = deprecated()
)

Arguments

spectra

Spectra, one per row: a numeric matrix, or a data frame whose wavelength columns are named by their wavelengths (other columns are used as labels).

launch_browser

Passed to shiny::runApp() as launch.browser. Default is TRUE when R is interactive.

show_table

A logical: show the periodic table when the app starts (TRUE, default). The Hide table button of the Elements panel hides or shows it at any time; hiding it gives the spectrum the whole height of the window.

launch.browser

[Deprecated] Use launch_browser.

Details

The app offers:

  • a clickable periodic table; elements without lines in the wavelength range of the spectra are grayed out once queried. It can be hidden (Hide table) to enlarge the spectrum, and the selected elements stay listed in the panel header;

  • the ionization stages to show (I, II, III);

  • the plasma temperature and the number of lines per species, which set the lines kept and the height of their markers (relative intensities in local thermodynamic equilibrium, see libs_lines());

  • molecules whose band heads are marked with dashed lines, at a vibrational temperature (see molecular_bands(); no download needed);

  • the wavelength range, a wavelength shift to correct the calibration of the spectrometer, and the spectrum to show: the mean of all spectra, the mean of a group (from the first character or factor column of spectra), or a single spectrum;

  • a download of the displayed lines as CSV, and buttons to save and reload the lines fetched so far, so that a session can continue offline.

Each species is downloaded from NIST once per R session (see nist_lines()), or once for all sessions with the persistent cache (see download_cache()); later changes of the settings are computed locally. The zoom of the plot is kept when the lines change.

Boltzmann plot. Clicking the dot at the top of a line marker adds the line to the Boltzmann plot of its species, and clicking it again removes it; Add shown lines adds all the lines shown for the species chosen in the Boltzmann plot panel. The intensities are measured on the displayed spectrum with line_intensities(), around the tabulated wavelengths plus the wavelength shift, with the settings of the panel, and the temperature is fitted with boltzmann(). Clicking a point of the plot leaves its line out of the fit or puts it back; lines without a positive intensity are left out. The table under the plot lists the upper-level energy, the signal-to-noise ratio and the residual of each line, Use T sets the temperature of the candidate lines to the fitted one, and Done closes the app and returns the fit to R. The spectra should be corrected for the spectral response of the instrument first (see correct_response()), and the lines should be optically thin (see self_absorption()).

The app needs the shiny, plotly and bslib packages, and an internet connection for the species not yet fetched.

Value

Invisibly, when the app is closed with Done, the boltzmann() fit of the Boltzmann plot, whose lines element holds the measured lines; NULL if the plot has fewer than 3 usable lines. Use libs_lines(), plot_lines(), line_intensities() and boltzmann() for the same results in scripts.

Author(s)

Christian L. Goueguel

See Also

libs_lines(), plot_lines(), nist_lines(), boltzmann()

Examples

if (interactive() && rlang::is_installed(c("shiny", "plotly", "bslib"))) {
  data(forageLIBS)
  fit <- line_finder(forageLIBS[-(1:14)])
  # after a Boltzmann plot closed with Done
  if (!is.null(fit)) plot_boltzmann(fit)
}

specProc documentation built on Nov. 20, 2026, 5:11 p.m.