R package: APRLssb

APRL smoothing splines baseline tool. Implements baseline correction of spectra for aerosols collected on PTFE filters as described by Kuzmiakova, Dillner, and Takahama, Atmos. Meas. Tech., 2016.

More generally, the purpose of this package is to provide a framework for

Subject to substantial modification. Keep up-to-date with git pull.


First, please see installation instructions for APRLspec, on which APRLssb depends.

Install for R (replace {username} and {password} with account for which access to private repository is granted):

> devtools::install_git('https://{username}:{password}@gitlab.com/aprl/APRLssb.git')

After installation, get a copy of example files (templates). To copy them into a new folder called “ssb” in your working directory:

$ cd /path/to/workingdir/
$ R -e "APRLspec::CopyPkgFiles('APRLssb', 'example_files', 'ssb')"
$ cd ssb/

To copy them into an existing working directory (“.” as third argument) - e.g., the current one where you have used baseline correction scripts - you can optionally pass a prefix as the fourth argument to the CopyPkgFiles function:

$ cd /path/to/workingdir/
$ R -e "APRLspec::CopyPkgFiles('APRLssb', 'example_files', '.', 'ssb')"

This will add a prefix to all the example files in this directory to prevent naming conflicts with files from other packages.

To uninstall, run the command in R:

> remove.packages("APRLssb")

Note: The RSQLite package should be modified as described for APRLspec’s README.md.


Fit baselines

Fit baselines (each segment separately) for a sequence of parameters (EDF_T):

$ Rscript main_fits_db.R testcase/userinput.json

Key parameters in .json file:

specfile can be one of .rda, .rds, .csv:


The output is a SQL database which contains baselines generated for each spectra and parameter, and additional parameters if they are estimated internally. Current default implementation of the database is SQLite. You can inspect the contents of the output file using the DB Browser for SQLite.

Visualize fits

$ Rscript plot_fits.R testcase/userinputs.json

Calculate and plot evaluation metrics

Calculate aggregated metrics (blank absorbance, NAF):

$ Rscript eval_fits_db.R testcase/userinputs.json

Key parameters in .json file:


The command for plotting (does not require database) is as follows:

$ Rscript eval_plots.R testcase/userinputs.json

Key parameters in .json file:


Export selected segments

For the time being, export spectra as text files for additional evaluation.

$ Rscript export_selected_as_rds.R testcase/userinput.json example/selected_spectra.json



Plot selected

$ Rscript plot_selected.R testcase/userinput.json

Input files

Configurations primarily defined by a single .json file.

Additional input files referenced by user .json file

“./” indicates that the file is in the same directory as the userinputs; otherwise it is the relative path name to the working directory (from which the script is called).

Segment definitions

Each segment must be provided with a label (name) a function for baseline correction. This comprises the core of the baseline correction task. Endpoints are used for rotation or plotting, but not for baseline correction. Unless provided explicitly by the user, segment definitions used by Kuzmiakova et al. (2016) are used - "segm1" (O-H and C-H stretching region) and "segm2" (carbonyl region).

Future work