-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathturbidity_read.R
More file actions
75 lines (65 loc) · 2.25 KB
/
turbidity_read.R
File metadata and controls
75 lines (65 loc) · 2.25 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
# To organize the sensor data from Jacques
library(readr)
library(dplyr)
library(lubridate)
library(parallel)
library(doParallel)
library(ggplot2)
im <- list.files("/Users/davidkahler/Downloads/Turbidity/",
pattern = "*.txt$",
full.names = TRUE,
recursive = TRUE,
ignore.case=TRUE,
include.dirs = TRUE)
registerDoParallel(detectCores())
x <- foreach (i = 1:length(im), .combine = 'rbind') %dopar% { # parallel computing loop: this changes how data are transferred back from each operation.
y <- read_csv(im[i], skip = 3, col_names = FALSE)
if (length(y) > 0) {
z <- y %>%
mutate(dt = force_tz(as_datetime(X1), tz = "Africa/Johannesburg"), temp = X3, Sensor = X4) %>%
select(dt, temp, Sensor) %>%
mutate(d = as_date(dt)) %>%
group_by(d) %>%
summarize(t = mean(temp, rm.na = TRUE), s = mean(Sensor, rm.na = TRUE), c = length(Sensor)) %>%
mutate(dn = as.numeric(d))
print(z)
}
}
n <- max(x$dn) - min(x$dn) + 1
y <- array(NA, dim = n)
count <- min(x$dn) - 1 # so that we add first.
for (i in 1:n) {
count <- count + 1
y[i] <- count
}
z <- foreach (i = 1:n, .combine = 'rbind') %dopar% {
look <- y[i]
tem <- 0
sig <- 0
num <- 0
for (j in 1:nrow(x)) {
if (x$dn[j] == look) {
tem <- tem + (x$t[j] * x$c[j])
sig <- sig + (x$s[j] * x$c[j])
num <- num + x$c[j]
}
}
print(c(look, tem, sig, num))
}
z <- data.frame(z)
z <- z %>%
mutate(d = as_date(X1)) %>%
mutate(temperature = X2/X4) %>%
mutate(turbidity = X3/X4) %>%
select(d, temperature, turbidity)
z <- z %>% rename(date = d)
write_csv(z, "balule_turbidity_csv", append = TRUE)
z <- z %>% mutate(dt = as_datetime(d))
ggplot(z) +
geom_point(aes(x = dt, y = turbidity)) +
scale_x_datetime() +
xlab("Date") +
ylab("Turbidity Signal (uncalibrated)") +
theme(panel.background = element_rect(fill = "white", colour = "black")) +
theme(aspect.ratio = 1/1.618) +
theme(axis.text = element_text(face = "plain", size = 12), axis.title = element_text(face = "plain", size = 14))