Revision 328528e2
Added by Benoit Parmentier over 12 years ago
climate/research/oregon/interpolation/kriging_reg.R | ||
---|---|---|
21 | 21 |
infile3<-"mean_day244_rescaled.rst" #This image serves as the reference grid for kriging |
22 | 22 |
infile4<- "orcnty24_OR83M.shp" #Vector file defining the study area: Oregon state and its counties. |
23 | 23 |
prop<-0.3 #Propotion of weather stations retained for validation/testing |
24 |
out_prefix<-"_04102012_RMSE" #output name used in the text file result
|
|
24 |
out_prefix<-"_LST_04172012_RMSE" #output name used in the text file result
|
|
25 | 25 |
|
26 | 26 |
###STEP 1 DATA PREPARATION AND PROCESSING##### |
27 | 27 |
|
... | ... | |
66 | 66 |
|
67 | 67 |
for(i in 1:length(dates)){ # start of the for loop #1 |
68 | 68 |
#i<-3 #Date 10 is used to test kriging |
69 |
date<-strptime(dates[i], "%Y%m%d") |
|
70 |
month<-strftime(date, "%m") |
|
71 |
LST_month<-paste("mm_",month,sep="") |
|
72 |
mod <-ghcn.subsets[[i]][,match(LST_month, names(ghcn.subsets[[i]]))] |
|
73 |
ghcn.subsets[[i]]$LST <-mod[[1]] |
|
74 |
|
|
69 | 75 |
n<-nrow(ghcn.subsets[[i]]) |
70 | 76 |
ns<-n-round(n*prop) #Create a sample from the data frame with 70% of the rows |
71 | 77 |
nv<-n-ns #create a sample for validation with prop of the rows |
... | ... | |
88 | 94 |
#Cokriging tmax |
89 | 95 |
g<-gstat(NULL,"tmax", tmax~1, data_s) #This creates a gstat object "g" that acts as container for kriging specifications. |
90 | 96 |
g<-gstat(g, "SRTM_elev",ELEV_SRTM~1,data_s) #Adding variables to gstat object g |
91 |
g<-gstat(g, "Eastness", Eastness~1,data_s) |
|
92 |
g<-gstat(g, "Northness", Northness~1, data_s) |
|
97 |
g<-gstat(g, "LST", LST~1,data_s) |
|
93 | 98 |
|
94 | 99 |
vm_g<-variogram(g) #Visualizing multivariate sample variogram. |
95 | 100 |
vm_g.fit<-fit.lmc(vm_g,g,vgm(2000,"Sph", 100000,1000)) #Fitting variogram for all variables at once. |
... | ... | |
165 | 170 |
# Now turn it into a data.frame... |
166 | 171 |
|
167 | 172 |
results_table<-as.data.frame(results_num) |
168 |
colnames(results_table)<-c("dates","ns","RMSE_gwr1")
|
|
173 |
colnames(results_table)<-c("dates","ns","RMSE") |
|
169 | 174 |
|
170 |
write.csv(results_table, file= paste(path,"/","results_GWR_Assessment",out_prefix,".txt",sep="")) |
|
175 |
write.csv(results_table, file= paste(path,"/","results_Kriging_Assessment",out_prefix,".txt",sep="")) |
Also available in: Unified diff
Kriging, adding LST for co-kriging: task #364