-
Notifications
You must be signed in to change notification settings - Fork 0
/
hw_tmax_montly_average_fromdailydata.R
167 lines (97 loc) · 3.51 KB
/
hw_tmax_montly_average_fromdailydata.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
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
setwd("/Work/Data_Model_Obs/Obs_Data/INMET_sao_paulo_precip")
names <- vector('list',1)
names[[1]] <- 'ARAGARCAS_GO_83368'
data <- vector('list',1)
data[[1]] <- read.csv('ARAGARCAS_GO_83368.csv', stringsAsFactors = FALSE)
data_cat <- data[[1]]
DD <- data_cat[,2]
MM <- data_cat[,3]
YYYY <- data_cat[,4]
FRACYR <- ((MM-1)*(365/12)+DD)/365
YR <- YYYY+FRACYR
yrmax <- max(data_cat[,4])
yrmin <- min(data_cat[,4])
yeartot <- yrmax - yrmin + 1
yrlist <- c(yrmin:yrmax)
data_cat[,2] <- as.POSIXct(data_cat[,2], format = "%d/%m/%Y")
data_cat[,2]
names(data_cat)[1] <- "station"
names(data_cat)[2] <- "date"
names(data_cat)[3] <- "hour"
names(data_cat)[4] <- "prcp"
names(data_cat)[5] <- "tmax"
names(data_cat)[6] <- "tmin"
# library(data.table)
# out <- setDT(data_cat)[, .(MontlyMeans = (mean(tmax), na.rm = TRUE)), by = .(year(date), month(date))]
#plot(out$year, out$MontlyMeans)
library(dplyr)
library(lubridate)
data_cat$date = ymd(data_cat$date)
data_cat %>%
group_by(Year=year(date), Month=month(date)) %>%
summarise(meanDailyMax=(mean(data_cat$tmax),
meanDailyMinn=mean(data_cat$tmin))
Year Month meanDailyMin meanDailyMean
1 1949 1 11.095 11.71928
###############
library(dplyr)
library(lubridate)
data_cat$date = ymd(data_cat$date)
data_cat %>%
group_by(Year=year(date), Month=month(date)) %>%
summarise(meanDailyMax=mean(tmax),
meanDailyMin=mean(tmin))
??summarise()
Year Month meanDailyMin meanDailyMean
1 1949 1 11.095 11.71928
head(data_cat)
prcp <- as.numeric(data_cat[,6], na.rm=TRUE)
tmax <- as.numeric(data_cat[,7], na.rm=TRUE)
tmin <- as.numeric(data_cat[,8], na.rm=TRUE)
library(data.table)
formatted <- data.frame(data_cat[,4],data_cat[,5])
summary(data_cat[,7])
summary(data_cat)
str(data_cat)
setDT(data_cat)[, .(MontlyMeans = mean(data_cat[,7])), by = .(year(data_cat[,4]), month(data_cat[,3]))]
# year month MontlyMeans
# 1: 1949 1 11.71928
setDT
II<- which(is.finite(tmax))
ann_tmax <- rep(0,yeartot)
ann_tmax_anom <- rep(0,yeartot)
for (NY in yrmin:yrmax){
nsamp <- 0
for (mo in 1:12){ #all months
II <- which((YYYY==NY)&(MM==mo))
if (length(tmax[II])>0) {
ann_tmax[NY-yrmin+1] <- ann_tmax[NY-yrmin+1] + tmax[II]
nsamp <- nsamp + 1
}
}
ann_tmax[NY-yrmin+1] <- (1/nsamp)*ann_tmax[NY-yrmin+1]
}
ann_tmax_anom <- ann_tmax - mean(ann_tmax, na.rm=T)
summary(data_cat[,7])
towrite <- cbind(yrlist, ann_tmax)
plot(towrite[,1], towrite[,2])
write.csv(towrite, file="text.csv", eol = "\r", na = "NA", row.names = FALSE)
??write.csv()
read.csv(text.csv)
summary(ann_tmax)
length(ann_tmax)
length(YR)
plot(x=yrlist, y=ann_tmax, sub = "ARAGARCAS GO", ylab = "tmax", xlab = "")
summary(ann_tmin_anom)
#Box Plot for both variables
boxplot(ann_tmax_anom, ann_tmax_anom main="Boxplot", ylab ="temperature", xlab ="",las= 2, cex.axis=0.7, col = c("gery","lightgreen"), at = c(1,2), names = c("tmax","tmin"))
dev.off()
grid.arrange(plotmax, plotmin,ncol=2)
#png(filename = "82596_lus_mn_hist.png", width = 2000, height = 2400, res = 250)
grid.arrange(l2pn,l3pn, l4pn, l5pn, l6pn, l7pn, l8pn, l9pn, l10pn, l11pn, l12pn, l13pn, ncol=2)
#dev.off()
# column heads: # Estacao - station # Data date: sub divided into day, month and year
# Hora - hour # Precipitacao - precipitation # TempMaxima - Tmax # TempMinima - Tmin
# Insolacao - ??????/ # Evaporacao Piche - ?????
# Temp Comp Media - Average temperature??? # Umidade Relativa Media - mean Rh
# Velocidade do Vento Media - Average wind speed