Project

General

Profile

« Previous | Next » 

Revision 2df5f40f

Added by Benoit Parmentier over 11 years ago

Output analyses and assessment of results, turning script into function

View differences:

climate/research/oregon/interpolation/results_interpolation_date_output_analyses.R
4 4
#Part 1: Script produces plots for every selected date
5 5
#Part 2: Examine 
6 6
#AUTHOR: Benoit Parmentier                                                                       
7
#DATE: 02/22/2013                                                                                 
7
#DATE: 03/18/2013                                                                                 
8 8

  
9 9
#PROJECT: NCEAS INPLANT: Environment and Organisms --TASK#???--   
10 10

  
......
28 28
### Parameters and arguments
29 29

  
30 30
##Paths to inputs and output
31
#Select relevant dates and load R objects created during the interpolation step
32

  
33
##Paths to inputs and output
34
script_path<-"/home/parmentier/Data/IPLANT_project/Venezuela_interpolation/Venezuela_01142013/"
31 35
in_path <- "/home/parmentier/Data/IPLANT_project/Venezuela_interpolation/Venezuela_01142013/input_data/"
32 36
out_path<- "/home/parmentier/Data/IPLANT_project/Venezuela_interpolation/Venezuela_01142013/output_data/"
33
infile3<-"covariates__venezuela_region__VE_01292013.tif" #this is an output from covariate script
37
infile_covar<-"covariates__venezuela_region__VE_01292013.tif" #this is an output from covariate script
38
date_selected<-c("20000101") ##This is for year 2000!!!
39
raster_prediction_obj<-"raster_prediction_obj__365d_GAM_fus5_all_lstd_03132013.RData"
40
#out_prefix<-"_365d_GAM_fus5_all_lstd_03132013"
41
#out_prefix<-"_365d_GAM_fus5_all_lstd_03142013"                #User defined output prefix
42
out_prefix<-"_365d_GAM_fus5_all_lstd_03132013"                #User defined output prefix
43
var<-"TMAX"
44
#gam_fus_mod<-load_obj("gam_fus_mod_365d_GAM_fus5_all_lstd_02202013.RData")
45
#validation_obj<-load_obj("gam_fus_validation_mod_365d_GAM_fus5_all_lstd_02202013.RData")
46
#clim_obj<-load_obj("gamclim_fus_mod_365d_GAM_fus5_all_lstd_02202013.RData")
47

  
48
rnames<-c("x","y","lon","lat","N","E","N_w","E_w","elev","slope","aspect","CANHEIGHT","DISTOC")
49
lc_names<-c("LC1","LC2","LC3","LC4","LC5","LC6","LC7","LC8","LC9","LC10","LC11","LC12")
50
lst_names<-c("mm_01","mm_02","mm_03","mm_04","mm_05","mm_06","mm_07","mm_08","mm_09","mm_10","mm_11","mm_12",
51
             "nobs_01","nobs_02","nobs_03","nobs_04","nobs_05","nobs_06","nobs_07","nobs_08",
52
             "nobs_09","nobs_10","nobs_11","nobs_12")
53
covar_names<-c(rnames,lc_names,lst_names)
54

  
55
list_param<-list(in_path,out_path,script_path,raster_prediction_obj,infile_covar,covar_names,date_selected,var,out_prefix)
56
names(list_param)<-c("in_path","out_path","script_path","raster_prediction_obj",
57
                     "infile_covar","covar_names","date_selected","var","out_prefix")
34 58

  
35 59
setwd(in_path)
36 60

  
61
## make this a script that calls several function:
62
#1) covariate script
63
#2) plots by dates
64
#3) number of data points monthly and daily
65

  
37 66
### Functions used in the script
38 67

  
39 68
load_obj <- function(f) 
......
43 72
  env[[nm]]
44 73
}
45 74

  
46
### PLOTTING RESULTS FROM VENEZUELA INTERPOLATION FOR ANALYSIS
47

  
48
#Select relevant dates and load R objects created during the interpolation step
49

  
50
date_selected<-c("20100103")
51

  
52
gam_fus_mod<-load_obj("gam_fus_mod_365d_GAM_fus5_all_lstd_02202013.RData")
53
validation_obj<-load_obj("gam_fus_validation_mod_365d_GAM_fus5_all_lstd_02202013.RData")
54
clim_obj<-load_obj("gamclim_fus_mod_365d_GAM_fus5_all_lstd_02202013.RData")
55

  
56
## Read covariate stack...
57
rnames <-c("x","y","lon","lat","N","E","N_w","E_w","elev","slope","aspect","CANHEIGHT","DISTOC")
58
lc_names<-c("LC1","LC2","LC3","LC4","LC5","LC6","LC7","LC8","LC9","LC10","LC11","LC12")
59
lst_names<-c("mm_01","mm_02","mm_03","mm_04","mm_05","mm_06","mm_07","mm_08","mm_09","mm_10","mm_11","mm_12",
60
             "nobs_01","nobs_02","nobs_03","nobs_04","nobs_05","nobs_06","nobs_07","nobs_08",
61
             "nobs_09","nobs_10","nobs_11","nobs_12")
62

  
63
covar_names<-c(rnames,lc_names,lst_names)
64

  
65
s_raster<-stack(infile3)                   #read in the data stack
66
names(s_raster)<-covar_names               #Assigning names to the raster layers: making sure it is included in the extraction
67

  
68
## Figure 0: study area based on LC12 (water) mask
69

  
70
LC_mask<-subset(s_raster,"LC12")
71
LC_mask[LC_mask==100]<-NA
72
LC_mask <- LC_mask < 100
73
LC_mask_rec<-LC_mask
74
LC_mask_rec[is.na(LC_mask_rec)]<-0
75

  
76
png(paste("Study_area_",
77
          out_prefix,".png", sep=""))
78
plot(LC_mask_rec,legend=FALSE,col=c("black","red"))
79
legend("topright",legend=c("Outside","Inside"),title="Study area",
80
       pt.cex=0.9,fill=c("black","red"),bty="n")
81
title("Study area")
82
dev.off()
83

  
84
#determine index position matching date selected
75
extract_number_obs<-function(list_param){
76
  
77
  method_mod_obj<-list_param$method_mod_obj
78
  #Change to results_mod_obj[[i]]$data_s to make it less specific
79
  lapply(1:length(method_obj),function(k) nrow(method_mod_obj[[k]]$data_s))
80
  lapply(1:length(method_obj),function(k) nrow(method_mod_obj[[k]]$data_v))
81
  lapply(1:length(clim_obj),function(k) nrow(method_mod_obj[[k]]$data_v))
82
  return()
83
}
85 84

  
86
i_dates<-vector("list",length(date_selected))
87
for (i in 1:length(gam_fus_mod)){
85
### PLOTTING RESULTS FROM VENEZUELA INTERPOLATION FOR ANALYSIS
86
#source(file.path(script_path,"results_interpolation_date_output_analyses_03182013.R"))
87
#j=1
88
#plots_assessment_by_date(1,list_param)
89
plots_assessment_by_date<-function(j,list_param){
90
  
91
  date_selected<-list_param$date_selected
92
  var<-list_param$var
93
  #gam_fus_mod<-load_obj("gam_fus_mod_365d_GAM_fus5_all_lstd_02202013.RData")
94
  #validation_obj<-load_obj("gam_fus_validation_mod_365d_GAM_fus5_all_lstd_02202013.RData")
95
  #clim_obj<-load_obj("gamclim_fus_mod_365d_GAM_fus5_all_lstd_02202013.RData")
96
  
97
  raster_prediction_obj<-load_obj(list_param$raster_prediction_obj)
98
  #method_mod_obj<-raster_prediction_obj$method_mod_obj
99
  method_mod_obj<-raster_prediction_obj$gam_fus_mod #change later for any model type
100
  #validation_obj<-raster_prediction_obj$validation_obj
101
  validation_obj<-raster_prediction_obj$gam_fus_validation_mod #change later for any model type
102
  #clim_obj<-raster_prediction_obj$clim_obj
103
  clim_obj<-raster_prediction_obj$gamclim_fus_mod #change later for any model type
104
  
105
  if (var=="TMAX"){
106
    y_var_name<-"dailyTmax"                                       
107
  }
108
  if (var=="TMIN"){
109
    y_var_name<-"dailyTmin"                                       
110
  }
111
  
112
  ## Read covariate stack...
113
  covar_names<-list_param$covar_names
114
  s_raster<-brick(infile_covar)                   #read in the data stack
115
  names(s_raster)<-covar_names               #Assigning names to the raster layers: making sure it is included in the extraction
116
  
117
  ## Figure 0: study area based on LC12 (water) mask
118
  
119
  LC_mask<-subset(s_raster,"LC12")
120
  LC_mask[LC_mask==100]<-NA
121
  LC_mask <- LC_mask < 100
122
  LC_mask_rec<-LC_mask
123
  LC_mask_rec[is.na(LC_mask_rec)]<-0
124
  
125
  #Add proportion covered by study area+ total of image pixels
126
  tmp_tb<-freq(LC_mask_rec)
127
  tmp_tb[2,2]/sum(tmp_tb[,2])*100
128
  png(paste("Study_area_",
129
            out_prefix,".png", sep=""))
130
  plot(LC_mask_rec,legend=FALSE,col=c("black","red"))
131
  legend("topright",legend=c("Outside","Inside"),title="Study area",
132
         pt.cex=0.9,fill=c("black","red"),bty="n")
133
  title("Study area")
134
  dev.off()
135
  
136
  #determine index position matching date selected
137
  
88 138
  for (j in 1:length(date_selected)){
89
    if(gam_fus_mod[[i]]$sampling_dat$date==date_selected[j]){  
90
      i_dates[[j]]<-i
139
    for (i in 1:length(method_mod_obj)){
140
      if(method_mod_obj[[i]]$sampling_dat$date==date_selected[j]){  
141
        i_dates[[j]]<-i
142
      }
91 143
    }
92 144
  }
145
  #Examine the first select date add loop or function later
146
  #j=1
147
  date<-strptime(date_selected[j], "%Y%m%d")   # interpolation date being processed
148
  month<-strftime(date, "%m")          # current month of the date being processed
149
  
150
  #Get raster stack of interpolated surfaces
151
  index<-i_dates[[j]]
152
  pred_temp<-as.character(method_mod_obj[[index]]$dailyTmax) #list of files
153
  rast_pred_temp<-stack(pred_temp) #stack of temperature predictions from models 
154
  
155
  #Get validation metrics, daily spdf training and testing stations, monthly spdf station input
156
  sampling_dat<-method_mod_obj[[index]]$sampling_dat
157
  metrics_v<-validation_obj[[index]]$metrics_v
158
  metrics_s<-validation_obj[[index]]$metrics_s
159
  data_v<-validation_obj[[index]]$data_v
160
  data_s<-validation_obj[[index]]$data_s
161
  data_month<-clim_obj[[index]]$data_month
162
  formulas<-clim_obj[[index]]$formulas
163
  
164
  #Adding layer LST to the raster stack of covariates
165
  #The names of covariates can be changed...
166
  
167
  LST_month<-paste("mm_",month,sep="") # name of LST month to be matched
168
  pos<-match("LST",layerNames(s_raster)) #Find the position of the layer with name "LST", if not present pos=NA
169
  s_raster<-dropLayer(s_raster,pos)      # If it exists drop layer
170
  pos<-match(LST_month,layerNames(s_raster)) #Find column with the current month for instance mm12
171
  r1<-raster(s_raster,layer=pos)             #Select layer from stack
172
  layerNames(r1)<-"LST"
173
  #Get mask image!!
174
  
175
  date_proc<-strptime(sampling_dat$date, "%Y%m%d")   # interpolation date being processed
176
  mo<-as.integer(strftime(date_proc, "%m"))          # current month of the date being processed
177
  day<-as.integer(strftime(date_proc, "%d"))
178
  year<-as.integer(strftime(date_proc, "%Y"))
179
  datelabel=format(ISOdate(year,mo,day),"%b %d, %Y")
180
  
181
  ## Figure 1: LST_TMax_scatterplot 
182
  
183
  rmse<-metrics_v$rmse[nrow(metrics_v)]
184
  rmse_f<-metrics_s$rmse[nrow(metrics_s)]  
185
  
186
  png(paste("LST_TMax_scatterplot_",sampling_dat$date,"_",sampling_dat$prop,"_",sampling_dat$run_samp,
187
            out_prefix,".png", sep=""))
188
  plot(data_month$TMax,data_month$LST,xlab="Station mo Tmax",ylab="LST mo Tmax")
189
  title(paste("LST vs TMax for",datelabel,sep=" "))
190
  abline(0,1)
191
  nb_point<-paste("n=",length(data_month$TMax),sep="")
192
  mean_bias<-paste("Mean LST bias= ",format(mean(data_month$LSTD_bias,na.rm=TRUE),digits=3),sep="")
193
  #Add the number of data points on the plot
194
  legend("topleft",legend=c(mean_bias,nb_point),bty="n")
195
  dev.off()
196
  
197
  ## Figure 2: Daily_tmax_monthly_TMax_scatterplot, modify for TMin!!
198
  
199
  png(paste("Daily_tmax_monthly_TMax_scatterplot_",sampling_dat$date,"_",sampling_dat$prop,"_",sampling_dat$run_samp,
200
            out_prefix,".png", sep=""))
201
  plot(dailyTmax~TMax,data=data_s,xlab="Mo Tmax",ylab=paste("Daily for",datelabel),main="across stations in VE")
202
  nb_point<-paste("ns=",length(data_s$TMax),sep="")
203
  nb_point2<-paste("ns_obs=",length(data_s$TMax)-sum(is.na(data_s[[y_var_name]])),sep="")
204
  nb_point3<-paste("n_month=",length(data_month$TMax),sep="")
205
  #Add the number of data points on the plot
206
  legend("topleft",legend=c(nb_point,nb_point2,nb_point3),bty="n",cex=0.8)
207
  dev.off()
208
  
209
  ## Figure 3: Predicted_tmax_versus_observed_scatterplot 
210
  
211
  #This is for mod_kr!! add other models later...
212
  png(paste("Predicted_tmax_versus_observed_scatterplot_",sampling_dat$date,"_",sampling_dat$prop,"_",sampling_dat$run_samp,
213
            out_prefix,".png", sep=""))
214
  #plot(data_s$mod_kr~data_s[[y_var_name]],xlab=paste("Actual daily for",datelabel),ylab="Pred daily")
215
  
216
  y_range<-range(c(data_s$mod_kr,data_v$mod_kr),na.rm=T)
217
  x_range<-range(c(data_s[[y_var_name]],data_v[[y_var_name]]),na.rm=T)
218
  col_t<- c("black","red")
219
  pch_t<- c(1,2)
220
  plot(data_s$mod_kr,data_s[[y_var_name]], 
221
       xlab=paste("Actual daily for",datelabel),ylab="Pred daily", 
222
       ylim=y_range,xlim=x_range,col=col_t[1],pch=pch_t[1])
223
  points(data_v$mod_kr,data_v[[y_var_name]],col=col_t[2],pch=pch_t[2])
224
  grid(lwd=0.5, col="black")
225
  #plot(data_v$mod_kr~data_v[[y_var_name]],xlab=paste("Actual daily for",datelabel),ylab="Pred daily")
226
  abline(0,1)
227
  legend("topleft",legend=c("training","testing"),pch=pch_t,col=col_t,bty="n",cex=0.8)
228
  title(paste("Predicted_tmax_versus_observed_scatterplot for",datelabel,sep=" "))
229
  nb_point1<-paste("ns_obs=",length(data_s$TMax)-sum(is.na(data_s[[y_var_name]])),sep="")
230
  rmse_str1<-paste("RMSE= ",format(rmse,digits=3),sep="")
231
  rmse_str2<-paste("RMSE_f= ",format(rmse_f,digits=3),sep="")
232
  
233
  #Add the number of data points on the plot
234
  legend("bottomright",legend=c(nb_point1,rmse_str1,rmse_str2),bty="n",cex=0.8)
235
  dev.off()
236
  
237
  ## Figure 5: prediction raster images
238
  png(paste("Raster_prediction_",sampling_dat$date,"_",sampling_dat$prop,"_",sampling_dat$run_samp,
239
            out_prefix,".png", sep=""))
240
  #paste(metrics_v$pred_mod,format(metrics_v$rmse,digits=3),sep=":")
241
  names(rast_pred_temp)<-paste(metrics_v$pred_mod,format(metrics_v$rmse,digits=3),sep=":")
242
  #plot(rast_pred_temp)
243
  levelplot(rast_pred_temp)
244
  dev.off()
245
  
246
  ## Figure 5b: prediction raster images
247
  png(paste("Raster_prediction_plot",sampling_dat$date,"_",sampling_dat$prop,"_",sampling_dat$run_samp,
248
            out_prefix,".png", sep=""))
249
  #paste(metrics_v$pred_mod,format(metrics_v$rmse,digits=3),sep=":")
250
  names(rast_pred_temp)<-paste(metrics_v$pred_mod,format(metrics_v$rmse,digits=3),sep=":")
251
  #plot(rast_pred_temp)
252
  plot(rast_pred_temp)
253
  dev.off()
254
  
255
  ## Figure 6: training and testing stations used
256
  png(paste("Training_testing_stations_map_",sampling_dat$date,"_",sampling_dat$prop,"_",sampling_dat$run_samp,
257
            out_prefix,".png", sep=""))
258
  plot(raster(rast_pred_temp,layer=5))
259
  plot(data_s,col="black",cex=1.2,pch=2,add=TRUE)
260
  plot(data_v,col="red",cex=1.2,pch=1,add=TRUE)
261
  legend("topleft",legend=c("training stations", "testing stations"), 
262
         cex=1, col=c("black","red"),
263
         pch=c(2,1),bty="n")
264
  dev.off()
265
  
266
  ## Figure 7: monthly stations used
267
  
268
  png(paste("Monthly_data_study_area",
269
            out_prefix,".png", sep=""))
270
  plot(raster(rast_pred_temp,layer=5))
271
  plot(data_month,col="black",cex=1.2,pch=4,add=TRUE)
272
  title("Monthly ghcn station in Venezuela for January")
273
  dev.off()
274
  
275
  ## Figure 8: delta surface and bias
276
  
277
  png(paste("Bias_delta_surface_",sampling_dat$date[i],"_",sampling_dat$prop[i],
278
            "_",sampling_dat$run_samp[i],out_prefix,".png", sep=""))
279
  
280
  bias_rast<-stack(clim_obj[[index]]$bias)
281
  delta_rast<-raster(method_mod_obj[[index]]$delta) #only one delta image!!!
282
  names(delta_rast)<-"delta"
283
  rast_temp_date<-stack(bias_rast,delta_rast)
284
  rast_temp_date<-mask(rast_temp_date,LC_mask,file="test.tif",overwrite=TRUE)
285
  #bias_d_rast<-raster("fusion_bias_LST_20100103_30_1_10d_GAM_fus5_all_lstd_02082013.rst")
286
  plot(rast_temp_date)
287
  
288
  dev.off()
289
  
290
  #Figure 9: histogram for all images...
291
  
292
  #histogram(rast_pred_temp)
293
  list_output_analyses<-list(metrics_s,metrics_v)
294
  return(list_output_analyses)
295
  
93 296
}
94 297

  
95
#Examine the first select date add loop or function later
96
j=1
97

  
98
date<-strptime(date_selected[j], "%Y%m%d")   # interpolation date being processed
99
month<-strftime(date, "%m")          # current month of the date being processed
100

  
101
#Get raster stack of interpolated surfaces
102
index<-i_dates[[j]]
103
pred_temp<-as.character(gam_fus_mod[[index]]$dailyTmax) #list of files
104
rast_pred_temp<-stack(pred_temp) #stack of temperature predictions from models 
105

  
106
#Get validation metrics, daily spdf training and testing stations, monthly spdf station input
107
sampling_dat<-gam_fus_mod[[index]]$sampling_dat
108
metrics_v<-validation_obj[[index]]$metrics_v
109
metrics_s<-validation_obj[[index]]$metrics_s
110
data_v<-validation_obj[[index]]$data_v
111
data_s<-validation_obj[[index]]$data_s
112
data_month<-clim_obj[[index]]$data_month
113
formulas<-clim_obj[[index]]$formulas
114

  
115
#Adding layer LST to the raster stack of covariates
116
#The names of covariates can be changed...
117

  
118
LST_month<-paste("mm_",month,sep="") # name of LST month to be matched
119
pos<-match("LST",layerNames(s_raster)) #Find the position of the layer with name "LST", if not present pos=NA
120
s_raster<-dropLayer(s_raster,pos)      # If it exists drop layer
121
pos<-match(LST_month,layerNames(s_raster)) #Find column with the current month for instance mm12
122
r1<-raster(s_raster,layer=pos)             #Select layer from stack
123
layerNames(r1)<-"LST"
124
#Get mask image!!
125

  
126
date_proc<-strptime(sampling_dat$date, "%Y%m%d")   # interpolation date being processed
127
mo<-as.integer(strftime(date_proc, "%m"))          # current month of the date being processed
128
day<-as.integer(strftime(date_proc, "%d"))
129
year<-as.integer(strftime(date_proc, "%Y"))
130
datelabel=format(ISOdate(year,mo,day),"%b %d, %Y")
131

  
132
## Figure 1: LST_TMax_scatterplot 
133

  
134
rmse<-metrics_v$rmse[nrow(metrics_v)]
135
rmse_f<-metrics_s$rmse[nrow(metrics_s)]  
136

  
137
png(paste("LST_TMax_scatterplot_",sampling_dat$date,"_",sampling_dat$prop,"_",sampling_dat$run_samp,
138
          out_prefix,".png", sep=""))
139
plot(data_month$TMax,data_month$LST,xlab="Station mo Tmax",ylab="LST mo Tmax")
140
title(paste("LST vs TMax for",datelabel,sep=" "))
141
abline(0,1)
142
nb_point<-paste("n=",length(data_month$TMax),sep="")
143
mean_bias<-paste("Mean LST bias= ",format(mean(data_month$LSTD_bias,na.rm=TRUE),digits=3),sep="")
144
#Add the number of data points on the plot
145
legend("topleft",legend=c(mean_bias,nb_point),bty="n")
146
dev.off()
147

  
148
## Figure 2: Daily_tmax_monthly_TMax_scatterplot 
149

  
150
png(paste("Daily_tmax_monthly_TMax_scatterplot_",sampling_dat$date,"_",sampling_dat$prop,"_",sampling_dat$run_samp,
151
          out_prefix,".png", sep=""))
152
plot(dailyTmax~TMax,data=data_s,xlab="Mo Tmax",ylab=paste("Daily for",datelabel),main="across stations in VE")
153
nb_point<-paste("ns=",length(data_s$TMax),sep="")
154
nb_point2<-paste("ns_obs=",length(data_s$TMax)-sum(is.na(data_s[[y_var_name]])),sep="")
155
nb_point3<-paste("n_month=",length(data_month$TMax),sep="")
156
#Add the number of data points on the plot
157
legend("topleft",legend=c(nb_point,nb_point2,nb_point3),bty="n",cex=0.8)
158
dev.off()
159

  
160
## Figure 3: Predicted_tmax_versus_observed_scatterplot 
161

  
162
#This is for mod_kr!! add other models later...
163
png(paste("Predicted_tmax_versus_observed_scatterplot_",sampling_dat$date,"_",sampling_dat$prop,"_",sampling_dat$run_samp,
164
          out_prefix,".png", sep=""))
165
#plot(data_s$mod_kr~data_s[[y_var_name]],xlab=paste("Actual daily for",datelabel),ylab="Pred daily")
166

  
167
y_range<-range(c(data_s$mod_kr,data_v$mod_kr),na.rm=T)
168
x_range<-range(c(data_s[[y_var_name]],data_v[[y_var_name]]),na.rm=T)
169
col_t<- c("black","red")
170
pch_t<- c(1,2)
171
plot(data_s$mod_kr,data_s[[y_var_name]], 
172
     xlab=paste("Actual daily for",datelabel),ylab="Pred daily", 
173
     ylim=y_range,xlim=x_range,col=col_t[1],pch=pch_t[1])
174
points(data_v$mod_kr,data_v[[y_var_name]],col=col_t[2],pch=pch_t[2])
175
grid(lwd=0.5, col="black")
176
#plot(data_v$mod_kr~data_v[[y_var_name]],xlab=paste("Actual daily for",datelabel),ylab="Pred daily")
177
abline(0,1)
178
legend("topleft",legend=c("training","testing"),pch=pch_t,col=col_t,bty="n",cex=0.8)
179
title(paste("Predicted_tmax_versus_observed_scatterplot for",datelabel,sep=" "))
180
nb_point1<-paste("ns_obs=",length(data_s$TMax)-sum(is.na(data_s[[y_var_name]])),sep="")
181
rmse_str1<-paste("RMSE= ",format(rmse,digits=3),sep="")
182
rmse_str2<-paste("RMSE_f= ",format(rmse_f,digits=3),sep="")
183

  
184
#Add the number of data points on the plot
185
legend("bottomright",legend=c(nb_point1,rmse_str1,rmse_str2),bty="n",cex=0.8)
186
dev.off()
187

  
188
## Figure 5: prediction raster images
189
png(paste("Raster_prediction_",sampling_dat$date,"_",sampling_dat$prop,"_",sampling_dat$run_samp,
190
          out_prefix,".png", sep=""))
191
#paste(metrics_v$pred_mod,format(metrics_v$rmse,digits=3),sep=":")
192
names(rast_pred_temp)<-paste(metrics_v$pred_mod,format(metrics_v$rmse,digits=3),sep=":")
193
#plot(rast_pred_temp)
194
levelplot(rast_pred_temp)
195
dev.off()
196

  
197
## Figure 6: training and testing stations used
198
png(paste("Training_testing_stations_map_",sampling_dat$date,"_",sampling_dat$prop,"_",sampling_dat$run_samp,
199
          out_prefix,".png", sep=""))
200
plot(raster(rast_pred_temp,layer=5))
201
plot(data_s,col="black",cex=1.2,pch=2,add=TRUE)
202
plot(data_v,col="red",cex=1.2,pch=1,add=TRUE)
203
legend("topleft",legend=c("training stations", "testing stations"), 
204
       cex=1, col=c("black","red"),
205
       pch=c(2,1),bty="n")
206
dev.off()
207

  
208
## Figure 7: monthly stations used
209

  
210
png(paste("Monthly_data_study_area",
211
          out_prefix,".png", sep=""))
212
plot(raster(rast_pred_temp,layer=5))
213
plot(data_month,col="black",cex=1.2,pch=4,add=TRUE)
214
title("Monthly ghcn station in Venezuela for January")
215
dev.off()
216

  
217
## Figure 8: delta surface and bias
218

  
219
png(paste("Bias_delta_surface_",sampling_dat$date[i],"_",sampling_dat$prop[i],
220
          "_",sampling_dat$run_samp[i],out_prefix,".png", sep=""))
221

  
222
bias_rast<-stack(clim_obj[[index]]$bias)
223
delta_rast<-raster(gam_fus_mod[[index]]$delta) #only one delta image!!!
224
names(delta_rast)<-"delta"
225
rast_temp_date<-stack(bias_rast,delta_rast)
226
rast_temp_date<-mask(rast_temp_date,LC_mask,file="test.tif",overwrite=TRUE)
227
#bias_d_rast<-raster("fusion_bias_LST_20100103_30_1_10d_GAM_fus5_all_lstd_02082013.rst")
228
plot(rast_temp_date)
229

  
230
dev.off()
231

  
232
#Figure 9: histogram for all images...
233 298

  
234
histogram(rast_pred_temp)
235 299

  
236 300
## Summarize information for the day: write out textfile...
237 301

  

Also available in: Unified diff