-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mean_Rainfall_Obs.R
140 lines (117 loc) · 8.55 KB
/
Mean_Rainfall_Obs.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
# Calculates ANN and Monthly mean rainfall from Frazier 2016 dataset from years 1990-2009
## This is hacked together and could be written 100% better but just need job done
library(raster)
library(dplyr)
library(stars)
rm(list=ls())
Obs.data<-"D:/HI_Data/OBS/RFMonthYr_Rasters_State_mm_1920_2012/Month_Rasters_State_mm/"
#Annual
names<-list.dirs(path = paste0(Obs.data,"Annual/"), full.names = TRUE, recursive = F) # 72-91 are years 1990-2009
ANN_mean<-mean(raster(names[72]),raster(names[73]),raster(names[74]),raster(names[75]),raster(names[76]),raster(names[77]),
raster(names[78]),raster(names[79]),raster(names[80]),raster(names[81]),raster(names[82]),raster(names[83]),
raster(names[84]),raster(names[85]),raster(names[86]),raster(names[87]),raster(names[88]),raster(names[89]),
raster(names[90]),raster(names[91]))
plot(ANN_mean)
writeRaster(ANN_mean, paste0(Obs.data,"/ANN_mean_1990-2009"), format = "GTiff")
#Jan
names<-list.dirs(path = paste0(Obs.data,"State_01Jan/"), full.names = TRUE, recursive = F) # 72-91 are years 1990-2009
JAN_mean<-mean(raster(names[72]),raster(names[73]),raster(names[74]),raster(names[75]),raster(names[76]),raster(names[77]),
raster(names[78]),raster(names[79]),raster(names[80]),raster(names[81]),raster(names[82]),raster(names[83]),
raster(names[84]),raster(names[85]),raster(names[86]),raster(names[87]),raster(names[88]),raster(names[89]),
raster(names[90]),raster(names[91]))
plot(JAN_mean)
writeRaster(JAN_mean, paste0(Obs.data,"/JAN_mean_1990-2009"), format = "GTiff")
#Feb
names<-list.dirs(path = paste0(Obs.data,"State_02Feb/"), full.names = TRUE, recursive = F) # 72-91 are years 1990-2009
JAN_mean<-mean(raster(names[72]),raster(names[73]),raster(names[74]),raster(names[75]),raster(names[76]),raster(names[77]),
raster(names[78]),raster(names[79]),raster(names[80]),raster(names[81]),raster(names[82]),raster(names[83]),
raster(names[84]),raster(names[85]),raster(names[86]),raster(names[87]),raster(names[88]),raster(names[89]),
raster(names[90]),raster(names[91]))
plot(JAN_mean)
writeRaster(JAN_mean, paste0(Obs.data,"/FEB_mean_1990-2009"), format = "GTiff")
#Mar
names<-list.dirs(path = paste0(Obs.data,"State_03Mar/"), full.names = TRUE, recursive = F) # 72-91 are years 1990-2009
JAN_mean<-mean(raster(names[72]),raster(names[73]),raster(names[74]),raster(names[75]),raster(names[76]),raster(names[77]),
raster(names[78]),raster(names[79]),raster(names[80]),raster(names[81]),raster(names[82]),raster(names[83]),
raster(names[84]),raster(names[85]),raster(names[86]),raster(names[87]),raster(names[88]),raster(names[89]),
raster(names[90]),raster(names[91]))
plot(JAN_mean)
writeRaster(JAN_mean, paste0(Obs.data,"/MAR_mean_1990-2009"), format = "GTiff")
#Apr
names<-list.dirs(path = paste0(Obs.data,"State_04Apr/"), full.names = TRUE, recursive = F) # 72-91 are years 1990-2009
JAN_mean<-mean(raster(names[72]),raster(names[73]),raster(names[74]),raster(names[75]),raster(names[76]),raster(names[77]),
raster(names[78]),raster(names[79]),raster(names[80]),raster(names[81]),raster(names[82]),raster(names[83]),
raster(names[84]),raster(names[85]),raster(names[86]),raster(names[87]),raster(names[88]),raster(names[89]),
raster(names[90]),raster(names[91]))
plot(JAN_mean)
writeRaster(JAN_mean, paste0(Obs.data,"/APR_mean_1990-2009"), format = "GTiff")
#May
names<-list.dirs(path = paste0(Obs.data,"State_05May/"), full.names = TRUE, recursive = F) # 72-91 are years 1990-2009
JAN_mean<-mean(raster(names[72]),raster(names[73]),raster(names[74]),raster(names[75]),raster(names[76]),raster(names[77]),
raster(names[78]),raster(names[79]),raster(names[80]),raster(names[81]),raster(names[82]),raster(names[83]),
raster(names[84]),raster(names[85]),raster(names[86]),raster(names[87]),raster(names[88]),raster(names[89]),
raster(names[90]),raster(names[91]))
plot(JAN_mean)
writeRaster(JAN_mean, paste0(Obs.data,"/MAY_mean_1990-2009"), format = "GTiff")
#Jun
names<-list.dirs(path = paste0(Obs.data,"State_06Jun/"), full.names = TRUE, recursive = F) # 72-91 are years 1990-2009
JAN_mean<-mean(raster(names[72]),raster(names[73]),raster(names[74]),raster(names[75]),raster(names[76]),raster(names[77]),
raster(names[78]),raster(names[79]),raster(names[80]),raster(names[81]),raster(names[82]),raster(names[83]),
raster(names[84]),raster(names[85]),raster(names[86]),raster(names[87]),raster(names[88]),raster(names[89]),
raster(names[90]),raster(names[91]))
plot(JAN_mean)
writeRaster(JAN_mean, paste0(Obs.data,"/JUN_mean_1990-2009"), format = "GTiff")
#Jul
names<-list.dirs(path = paste0(Obs.data,"State_07Jul/"), full.names = TRUE, recursive = F) # 72-91 are years 1990-2009
names[1]
JAN_mean<-mean(raster(names[72]),raster(names[73]),raster(names[74]),raster(names[75]),raster(names[76]),raster(names[77]),
raster(names[78]),raster(names[79]),raster(names[80]),raster(names[81]),raster(names[82]),raster(names[83]),
raster(names[84]),raster(names[85]),raster(names[86]),raster(names[87]),raster(names[88]),raster(names[89]),
raster(names[90]),raster(names[91]))
plot(JAN_mean)
writeRaster(JAN_mean, paste0(Obs.data,"/JUL_mean_1990-2009"), format = "GTiff")
#Aug
names<-list.dirs(path = paste0(Obs.data,"State_08Aug/"), full.names = TRUE, recursive = F) # 72-91 are years 1990-2009
names[1]
JAN_mean<-mean(raster(names[72]),raster(names[73]),raster(names[74]),raster(names[75]),raster(names[76]),raster(names[77]),
raster(names[78]),raster(names[79]),raster(names[80]),raster(names[81]),raster(names[82]),raster(names[83]),
raster(names[84]),raster(names[85]),raster(names[86]),raster(names[87]),raster(names[88]),raster(names[89]),
raster(names[90]),raster(names[91]))
plot(JAN_mean)
writeRaster(JAN_mean, paste0(Obs.data,"/AUG_mean_1990-2009"), format = "GTiff")
#Sep
names<-list.dirs(path = paste0(Obs.data,"State_09Sep/"), full.names = TRUE, recursive = F) # 72-91 are years 1990-2009
names[1]
JAN_mean<-mean(raster(names[72]),raster(names[73]),raster(names[74]),raster(names[75]),raster(names[76]),raster(names[77]),
raster(names[78]),raster(names[79]),raster(names[80]),raster(names[81]),raster(names[82]),raster(names[83]),
raster(names[84]),raster(names[85]),raster(names[86]),raster(names[87]),raster(names[88]),raster(names[89]),
raster(names[90]),raster(names[91]))
plot(JAN_mean)
writeRaster(JAN_mean, paste0(Obs.data,"/SEP_mean_1990-2009"), format = "GTiff")
#Oct
names<-list.dirs(path = paste0(Obs.data,"State_10Oct/"), full.names = TRUE, recursive = F) # 72-91 are years 1990-2009
names[1]
JAN_mean<-mean(raster(names[72]),raster(names[73]),raster(names[74]),raster(names[75]),raster(names[76]),raster(names[77]),
raster(names[78]),raster(names[79]),raster(names[80]),raster(names[81]),raster(names[82]),raster(names[83]),
raster(names[84]),raster(names[85]),raster(names[86]),raster(names[87]),raster(names[88]),raster(names[89]),
raster(names[90]),raster(names[91]))
plot(JAN_mean)
writeRaster(JAN_mean, paste0(Obs.data,"/OCT_mean_1990-2009"), format = "GTiff")
#Nov
names<-list.dirs(path = paste0(Obs.data,"State_11Nov/"), full.names = TRUE, recursive = F) # 72-91 are years 1990-2009
names[1]
JAN_mean<-mean(raster(names[72]),raster(names[73]),raster(names[74]),raster(names[75]),raster(names[76]),raster(names[77]),
raster(names[78]),raster(names[79]),raster(names[80]),raster(names[81]),raster(names[82]),raster(names[83]),
raster(names[84]),raster(names[85]),raster(names[86]),raster(names[87]),raster(names[88]),raster(names[89]),
raster(names[90]),raster(names[91]))
plot(JAN_mean)
writeRaster(JAN_mean, paste0(Obs.data,"/NOV_mean_1990-2009"), format = "GTiff")
#Dec
names<-list.dirs(path = paste0(Obs.data,"State_12Dec/"), full.names = TRUE, recursive = F) # 72-91 are years 1990-2009
names[1]
JAN_mean<-mean(raster(names[72]),raster(names[73]),raster(names[74]),raster(names[75]),raster(names[76]),raster(names[77]),
raster(names[78]),raster(names[79]),raster(names[80]),raster(names[81]),raster(names[82]),raster(names[83]),
raster(names[84]),raster(names[85]),raster(names[86]),raster(names[87]),raster(names[88]),raster(names[89]),
raster(names[90]),raster(names[91]))
plot(JAN_mean)
writeRaster(JAN_mean, paste0(Obs.data,"/DEC_mean_1990-2009"), format = "GTiff")