Build Status

knitr::opts_chunk$set(echo = TRUE)
library(loggercal)

Temperature Logger Calibration

The first step is to load the loggercal package

devtools::install_github("faskally/loggercal")
library(loggercal)

The first thing to do is to set the location of the external and internal calibrations we are looking to compare.

externalCalDir <- "data-raw/External Calibrations/"
internalCalDir <- "data-raw/100214/"

External calibration data

Next we look for the external calibration files from a UKAS calibration. These should all be in one directory. In this case we find two external calibrations. These are read in using the loggercal function readExternalCal

ukas <- readExternalCal(externalCalDir)
str(ukas)

we now fit a model to the external calibration data

externalCalMod <- lapply(ukas $ data, function(x) lm(cal ~ poly(control, 2), data = x[-1,]))

Read in internal calibration data

internalCal <- readInternalCal(internalCalDir)
internalCal

Now it should be checked that the external calibration loggers were included in the experiment

ukas

And here, the last two loggers in the internal calibration are the externally calibrated ones. The next step is to define the start and stop of the calibration. This can be done manually (note that the value startStopSec is in seconds, while the plot axis is in minutes, so you need to multiply by 60 to set limits in secs):

plot(internalCal)
internalCal$startStopSec <- c(100,9900) * 60
plot(internalCal)

Or this can be done using a graphical approach, in a handy function.

internalCal <- findStartSec(internalCal)
internalCal <- findStopSec(internalCal)
plot(internalCal)

run the calibration

The function calibration runs the full calibration method. Here, as we are running an example, we only use 5 simulations to back calculate the logger error. Normally a large number like 99 or 999 should be used, but this can take up to a day to run.

cal <- calibration(internalCal, externalCalMod, n = 5)

Once the calibration simulations have completed, the coefficients from the calibrations are extracted and tabled (e.g. for import into a logger database with calibration functionality).

coefs <- getCoefs(cal)
tabCoefs <- tableCoefs(coefs, cal = internalCal)
tabCoefs

A full analysis script

library(loggercal)

externalCalDir <- "data-raw/External Calibrations/"
internalCalDir <- "data-raw/100214/"

# external calibration -------------------------

# read in external calibrations
ukas <- readExternalCal(externalCalDir)

# fit a model to the external calibration data
externalCalMod <- lapply(ukas $ data, function(x) lm(cal ~ poly(control, 2), data = x[-1,]))

# internal calibration -------------------------

# read in internal calibration experiment
internalCal <- readInternalCal(internalCalDir)

# trim off ends
internalCal$startStopSec <- c(100,9900) * 60

# plot to check
plot(internalCal)

# perform a calibration ------------

cal <- calibration(internalCal, externalCalMod, n = 5)

# convert coefficients to non orthogonal polynomials
coefs <- getCoefs(cal)
tabCoefs <- tableCoefs(coefs, cal = internalCal)

write.csv(file = file.path(file.path(internalCalDir), "coefficients.csv"), tabCoefs, row.names = FALSE)

# Done -----------------


Faskally/loggercal documentation built on Oct. 21, 2020, 10:30 p.m.