-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathproc_microdata.R
More file actions
71 lines (61 loc) · 2.33 KB
/
Copy pathproc_microdata.R
File metadata and controls
71 lines (61 loc) · 2.33 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
#################################################################################
# proc_microdata.r
# Microclimate data input and processing for Athens Mosquito Microclimate project
# written by Mike Wimberly, University of Oklahoma
#################################################################################
library(tidyverse)
library(lubridate)
# Read in the raw data from the Google Drive archive
raw_data_path <- "c:/Users/wimb0002/Google Drive/DataLoggerData/2018_rawdata/"
# Function to read in the microclimate logger files
my_read_csv <- function(x) {
#out <- read_csv(x, col_types = cols(.default = "c"))
out <- read_csv(x)
if ( nrow(out) >= 1 ) {
site <- substr(x, str_length(x) - 7, str_length(x) - 4)
cbind(Site=site, out)
}
}
# Read all logger files into a single R object
micro_in <-
list.files(path = raw_data_path,
pattern = "*.csv",
recursive = TRUE,
full.names = T) %>%
map_df(~my_read_csv(.)) %>%
separate(Time, into = c("Date", "Time"), sep = " ") %>%
mutate(Date = mdy(Date))
names(micro_in)[c(4, 7)] <- c("temp", "rh")
# Remote bad sites
# R3A2, S1A4, and U34 have malfunctioning loggers
# other values are bad site names
allsites <- unique(micro_in$Site)
badsites <- c("R3A2", "S1A4", "U3A4", "2A12", "6UNK", "0820")
goodsites <- allsites[!allsites %in% badsites]
# Generate daily summaries of mean, min, and max RH and temp values
micro_daily <- micro_in %>%
group_by(Date, Site) %>%
filter(Site %in% goodsites) %>%
summarise(num_temp = sum(!is.na(temp)),
num_rh = sum(!is.na(rh)),
mean_temp = mean(temp),
min_temp = mean(temp[temp <= quantile(temp, 0.04)]),
max_temp = mean(temp[temp >= quantile(temp, 0.96)]),
mean_rh = mean(rh),
min_rh = mean(rh[rh <= quantile(rh, 0.04)]),
max_rh = mean(rh[rh >= quantile(rh, 0.96)])) %>%
ungroup() %>%
arrange(Date, Site)
# Crosstabulate sites by date
micro_xtab <- micro_daily %>%
dplyr::select(Date, Site, num_temp) %>%
spread(Site, num_temp)
# Save data
# Raw data
write_csv(micro_in, "./outdata/athens_2018_rawdata.csv")
# Summarized daily data
write_csv(micro_daily, "./outdata/micro_2018_daily.csv")
# Cross-tabulation of daily data by logger
write_csv(micro_xtab, "./outdata/micro_2018_xtab.csv")
# Remote temporary objects
rm(list = ls())