/
9-verify.R
87 lines (75 loc) · 3.18 KB
/
9-verify.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
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
######################################################################################################################
#--------------------------------------------------------------------------------------------------------------------
# Author : A. John Woodill
# Date : 8/16/2016
# Filename : verify.R
# Code : Verification code to check degree days, time, and weather data
#
#--------------------------------------------------------------------------------------------------------------------
######################################################################################################################
library(parallel)
library(dplyr)
library(data.table)
library(tidyr)
library(ggplot2)
# Aggregate NCDC Data
files <- list.files("/home/johnw/Projects/Fine-Scale-Weather-Interpolation/Data/NCDC/rds/")
comp <- function(x){
dat <- readRDS(paste0("/home/johnw/Projects/Fine-Scale-Weather-Interpolation/Data/NCDC/rds/",x))
dat <- dat %>%
group_by(element, year) %>%
summarise(value = mean(value, na.rm = TRUE))
saveRDS(dat, paste0("/home/johnw/Projects/Fine-Scale-Weather-Interpolation/Data/Verify/NCDC/", x))
}
cl <- makeCluster(16)
i <- files
clusterCall(cl, function() library(dplyr))
parLapply(cl, X = i, fun = comp)
stopCluster(cl)
# Aggregate PRISM Data
files <- list.files("/home/johnw/Projects/Fine-Scale-Weather-Interpolation/Data/PRISM/gridNumber/")
comp <- function(x){
dat <- readRDS(paste0("/home/johnw/Projects/Fine-Scale-Weather-Interpolation/Data/PRISM/gridNumber/",x))
dat <- dat %>%
group_by(element, year) %>%
summarise(mean = mean(mean, na.rm = TRUE))
saveRDS(dat, paste0("/home/johnw/Projects/Fine-Scale-Weather-Interpolation/Data/Verify/PRISM/", x))
}
cl <- makeCluster(16)
i <- files
clusterCall(cl, function() library(dplyr))
parLapply(cl, X = i, fun = comp)
stopCluster(cl)
# bind together
ncdc_s <- list.files("/home/johnw/Projects/Fine-Scale-Weather-Interpolation/Data/Verify/NCDC/", full.names = TRUE)
ncdc <- rbindlist(lapply(ncdc_s, readRDS))
ncdc <- filter(ncdc, element != "PRCP")
ncdc <- ncdc %>%
group_by(element, year) %>%
summarise(mean = mean(value, na.rm = TRUE))
ncdc <- spread(ncdc, element, mean)
ncdc$tavg <- (ncdc$TMAX + ncdc$TMIN)/2
ncdc$type <- "NCDC"
names(ncdc) <- tolower(names(ncdc))
prism_list <- list.files("/home/johnw/Projects/Fine-Scale-Weather-Interpolation/Data/Verify/PRISM/", full.names = TRUE)
prism <- rbindlist(lapply(prism_list, readRDS))
prism <- filter(prism, element != "ppt")
prism2 <- prism %>%
group_by(element, year) %>%
summarise(mean = mean(mean, na.rm = TRUE))
prism2 <- spread(prism2, element, mean)
prism2$tavg <- (prism2$tmax + prism2$tmin)/2
prism2$type <- "PRISM"
# Get degree days interpolated
base <- readRDS("/home/johnw/Projects/Fine-Scale-Weather-Interpolation/Data/fips_degree_days_1900-2013.rds")
base <- select(base, year, tmax, tmin, tavg)
base <- gather(base, element, value, -year)
base <- base %>%
group_by(element, year) %>%
summarise(mean = mean(value, na.rm = TRUE))
base <- spread(base, element, mean)
base$type <- "BASE"
dat <- rbind(base, ncdc, prism2)
dat$type <- as.factor(dat$type)
dat$year <- as.numeric(dat$year)
ggplot(dat, aes(year, tmin, color = type)) + geom_smooth()