-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadMe.Rmd
More file actions
144 lines (102 loc) · 3.78 KB
/
Copy pathReadMe.Rmd
File metadata and controls
144 lines (102 loc) · 3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
---
title: "ReadMe"
author: Colin Millar
date: 21th December 2016
output:
md_document:
variant: markdown_github
toc: true
toc_depth: 2
---
[](https://travis-ci.org/Faskally/loggercal)
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(loggercal)
```
# Temperature Logger Calibration
The first step is to load the loggercal package
```{r library, echo=TRUE, eval=FALSE}
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.
```{r input}
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`
```{r read_ukas}
ukas <- readExternalCal(externalCalDir)
str(ukas)
```
we now fit a model to the external calibration data
```{r external_model}
externalCalMod <- lapply(ukas $ data, function(x) lm(cal ~ poly(control, 2), data = x[-1,]))
```
## Read in internal calibration data
```{r internal_calibration}
internalCal <- readInternalCal(internalCalDir)
internalCal
```
Now it should be checked that the external calibration loggers were included in the experiment
```{r check_logger}
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):
```{r trim_manual}
plot(internalCal)
internalCal$startStopSec <- c(100,9900) * 60
plot(internalCal)
```
Or this can be done using a graphical approach, in a handy function.
```{r trim_graphical, eval = FALSE}
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.
```{r run calibration}
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).
```{r table_coefficients}
coefs <- getCoefs(cal)
tabCoefs <- tableCoefs(coefs, cal = internalCal)
tabCoefs
```
## A full analysis script
```{r full_analysis, eval = FALSE}
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 -----------------
```