forked from qedsoftware/phenospex-analysis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.R
48 lines (38 loc) · 1.77 KB
/
main.R
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
# load libraries
library(dplyr)
library(MESS)
library(mgcv)
library(grofit)
# source other R scripts
source("data_cleaning.R")
source("data_analysis.R")
# input information
datafile <- "Rep1_planteye 1108.csv"
properties <- c("Height")
startingtime <- as.POSIXct(strptime("10/25/2019 00:00", "%m/%d/%Y %H:%M"))
endingtime <- as.POSIXct(strptime("11/09/2019 00:00", "%m/%d/%Y %H:%M"))
# read in data
planteye_data <- read.csv(datafile)
# keep the measurements between 10/25/2019 and 11/09/2019
planteye_data$timestamp_orig <- planteye_data$timestamp
planteye_data$timestamp <- as.POSIXct(strptime(planteye_data$timestamp, "%m/%d/%Y %H:%M"))
planteye_data <- filter(planteye_data, timestamp >= startingtime & timestamp <= endingtime)
# keep units with 30 to 48 measurements
unit_count <- planteye_data %>% group_by(unit) %>% summarize(n = n(), mindate = as.Date(min(timestamp)), maxdate = as.Date(max(timestamp)))
unit_keep <- as.data.frame(unit_count %>% filter(n >= 30 & n <= 48) %>% dplyr::select(unit))
planteye_data <- filter(planteye_data, unit %in% unit_keep[, 1])
# order the data
planteye_data <- arrange(planteye_data, unit, timestamp)
# start the analysis
for (property in properties) {
# data cleaning
planteye_data_cleaned <- data_cleaning(planteye_data, property)
# time range for the growth curve
time_range <- planteye_data_cleaned %>% group_by(unit) %>% summarize(mintime = min(timestamp), maxtime = max(timestamp))
mintime <- as.numeric(max(time_range$mintime))
maxtime <- as.numeric(min(time_range$maxtime))
lentime <- (maxtime - mintime) / 3600 # in Hours
# auc estimation
auc_data <- GetPhenospexAUC(planteye_data_cleaned, property, mintime, maxtime, TRUE)
write.csv(auc_data, paste("auc_", property, ".csv", sep = ""), row.names = FALSE)
}