knitr::opts_chunk$set(
  collapse = TRUE,
  fig.path = "inst/images/README-"
)
library(ggplot2)
theme_set(theme_bw(base_size = 12, base_family = "Open Sans"))

cdom Travis-CI Build Status AppVeyor Build Status Package-License CRAN Downloads

The cdom package implements various functions used to model and calculate metrics from absorption spectra of chromophotic dissolved organic matter (CDOM).

This package provides:

  1. Simple wrappers to calculate common metrics found in the literature.

    • The spectral curve [@Loiselle2009].
    • The slope ratio (Sr) [@Helms2008].
    • The spectral slope (S) [@Jerlov1968; @Lundgren1976; @Bricaud1981].
  2. The function to use the Gaussian decomposition approach proposed in Massicotte and Markager, (2015).

The package can be installed using the following command.

devtools::install_github("PMassicotte/cdom")

Please note that this is a developing version of the package for testing only. Please fill an issue when you find bugs.

All functions from the package start with the cdom_ prefix.

library(cdom)
ls("package:cdom")

Examples

The spectral slope (S)

The cdom_fit_exponential() function fits an exponential curve to CDOM data using the simple model proposed by @Jerlov1968, @Lundgren1976, @Bricaud1981.

a(\lambda) = a(\lambda0)e^{-S(\lambda - \lambda0)} + K
library(ggplot2)
library(cdom)
data("spectra")

fit <- cdom_exponential(wl = spectra$wavelength,
                       absorbance = spectra$spc3,
                       wl0 = 350,
                       startwl = 190,
                       endwl = 900)

coef(fit)

p <- plot(fit)
p

The slope ratio (SR)

The cdom_slope_ratio() function calculates the slope ratio (SR) which is defined as: S275-295/S350-400. See @Helms2008 for detailed information.

library(cdom)
data("spectra")

cdom_slope_ratio(spectra$wavelength, spectra$spc1)

The spectral curve

The cdom_spectral_curve() function generates the spectral curve using the slope of the linear regression between the natural log absorption spectrum and wavelengths over a sliding window of 21 nm interval (default) at 1 nm resolution. See @Loiselle2009 for detailed information.

library(cdom)
data("spectra")

res <-  cdom_spectral_curve(wl = spectra$wavelength,
                       absorbance = spectra$spc10,
                       interval = 21,
                       r2threshold = 0.98) # Maybe to restrictive...

ggplot(res, aes(x = wl, y = s)) +
  geom_point() +
  geom_line() +
  xlab("Wavelength (nm)") +
  ylab(expression(paste("Spectral slope (", nm ^ {-1}, ")")))

Using the pipe operator

library(dplyr)
library(tidyr)

data(spectra)

spectra <- spectra %>% 
  gather(sample, absorption, starts_with("spc")) %>% 
  group_by(sample) %>% 
  nest() %>% 
  mutate(model = purrr::map(data, ~cdom_exponential(.$wavelength, .$absorption, wl0 = 350, startwl = 190, endwl = 900)))


#spectra %>% unnest(model %>% purrr::map(~.$data$.fitted))

Data

A total 25 absorption spectra are provided in the package.

library(ggplot2)
library(tidyr)
data("spectra")

spectra <- gather(spectra, sample, absorption, -wavelength)

ggplot(spectra, aes(x = wavelength, y = absorption, group = sample)) +
  geom_line(size = 0.1) +
  xlab("Wavelength (nm)") +
  ylab(expression(paste("Absorption (", m ^ {-1}, ")")))

How to cite the package

citation("cdom")

References



PMassicotte/cdom documentation built on April 14, 2020, 4:38 p.m.