match_spec: Match spectra with reference library

View source: R/match_spec.R

match_specR Documentation

Match spectra with reference library

Description

match_spec() will compare a spectrum to a spectral library formatted with the Open Specy standard and report the best match using the Pearson correlation coefficient. find_spec() makes it easy to retrieve single spectra and metadata from the Open Specy reference library.

Usage

match_spec(x, ...)

## S3 method for class 'formula'
match_spec(formula, data = NULL, ...)

## S3 method for class 'data.frame'
match_spec(x, ...)

## Default S3 method:
match_spec(
  x,
  y,
  library,
  which = NULL,
  type = "full",
  range = seq(0, 6000, 0.1),
  top_n = 100,
  ...
)

find_spec(
  subset,
  library,
  which = NULL,
  type = "metadata",
  cols = c("spectrum_identity", "organization", "contact_info", "spectrum_type",
    "instrument_used", "instrument_accessories", "instrument_mode", "laser_light_used",
    "total_acquisition_time_s", "number_of_accumulations",
    "level_of_confidence_in_identification", "cas_number", "material_producer",
    "material_purity", "material_form", "material_quality", "spectral_resolution",
    "data_processing_procedure", "other_information", "sample_name", "wavenumber",
    "intensity", "group"),
  ...
)

Arguments

x

a numeric vector containing the spectral wavenumbers; alternatively a data frame containing spectral data as "wavenumber" and "intensity" can be supplied.

formula

an object of class 'formula' of the form intensity ~ wavenumber.

data

a data frame containing the variables in formula.

y

a numeric vector containing the spectral intensities.

library

reference library you want to compare against.

which

a character string specifying which library to match, "raman" or "ftir".

type

a character string specifying whether the "full" spectrum should be matched or spectrum "peaks" only. "metadata" is needed to browser spectra with find_spec().

range

this should be all possible wavenumber values from your spectral library.

top_n

number of top matches that you want to be returned.

subset

logical expression indicating elements or rows to search for; see subset() for details.

cols

columns to retrieve from the Open Specy reference library; columns containing no or missing values are automatically removed.

...

further arguments passed to the submethods.

Details

This routine will match the spectrum you want to identify to the wavenumbers present in the spectral library. Once the spectra are aligned, it computes the Pearson correlation coefficient between the spectrum you want to identify and all spectra in the library (see cor). The function returns a table with the Pearson correlation coefficient values and all metadata for the top spectral matches. If using the Open Specy library, all intensity values are in absorbance, so your spectra should also be in absorbance units. If you need to convert your spectrum, use adj_intens().

Value

match_spec() returns a data frame with the top_n material matches, their Pearson's r value, and the organization they were provided by. find_spec() returns a data frame with the spectral raw data or metadata of a specific reference spectrum.

Author(s)

Win Cowger, Zacharias Steinmetz

See Also

adj_intens() converts spectra; get_lib() retrieves the Open Specy reference library; load_lib() loads the Open Specy reference library into an R object of choice

Examples

## Not run: 
data("raman_hdpe")

get_lib("raman")
spec_lib <- load_lib("raman")

match_spec(raman_proc, library = spec_lib, which = "raman")

find_spec(sample_name == 5381, library = spec_lib, which = "raman")

## End(Not run)


OpenSpecy documentation built on July 6, 2022, 5:07 p.m.