Project

General

Profile

« Previous | Next » 

Revision f9b40867

Added by Benoit Parmentier over 11 years ago

results output figures modifications to allow TMIN output figures

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: 03/18/2013                                                                                 
7
#DATE: 04/02/2013                                                                                 
8 8

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

  
......
36 36
out_path<- "/home/parmentier/Data/IPLANT_project/Venezuela_interpolation/Venezuela_01142013/output_data/"
37 37
infile_covar<-"covariates__venezuela_region__VE_01292013.tif" #this is an output from covariate script
38 38
date_selected<-c("20000101") ##This is for year 2000!!!
39
raster_prediction_obj<-"raster_prediction_obj__365d_GAM_fus5_all_lstd_03132013.RData"
39
raster_prediction_obj<-load_obj("raster_prediction_obj_dailyTmin_365d_GAM_fus5_all_lstd_03292013.RData")
40 40
#out_prefix<-"_365d_GAM_fus5_all_lstd_03132013"
41 41
#out_prefix<-"_365d_GAM_fus5_all_lstd_03142013"                #User defined output prefix
42
out_prefix<-"_365d_GAM_fus5_all_lstd_03272013"                #User defined output prefix
43
var<-"TMAX"
42
out_prefix<-"_365d_GAM_fus5_all_lstd_03292013"                #User defined output prefix
43
var<-"TMIN"
44 44
#gam_fus_mod<-load_obj("gam_fus_mod_365d_GAM_fus5_all_lstd_02202013.RData")
45 45
#validation_obj<-load_obj("gam_fus_validation_mod_365d_GAM_fus5_all_lstd_02202013.RData")
46 46
#clim_obj<-load_obj("gamclim_fus_mod_365d_GAM_fus5_all_lstd_02202013.RData")
......
52 52
             "nobs_09","nobs_10","nobs_11","nobs_12")
53 53
covar_names<-c(rnames,lc_names,lst_names)
54 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",
55
list_param_results_analyses<-list(in_path,out_path,script_path,raster_prediction_obj,infile_covar,covar_names,date_selected,var,out_prefix)
56
names(list_param_results_analyses)<-c("in_path","out_path","script_path","raster_prediction_obj",
57 57
                     "infile_covar","covar_names","date_selected","var","out_prefix")
58 58

  
59 59
setwd(in_path)
......
74 74

  
75 75

  
76 76
### PLOTTING RESULTS FROM VENEZUELA INTERPOLATION FOR ANALYSIS
77
#source(file.path(script_path,"results_interpolation_date_output_analyses_03182013.R"))
77
#source(file.path(script_path,"results_interpolation_date_output_analyses_04022013.R"))
78 78
#j=1
79
#plots_assessment_by_date(1,list_param)
79
#plots_assessment_by_date(1,list_param_results_analyses)
80

  
81

  
80 82
plots_assessment_by_date<-function(j,list_param){
81 83
  
82 84
  date_selected<-list_param$date_selected
......
85 87
  #validation_obj<-load_obj("gam_fus_validation_mod_365d_GAM_fus5_all_lstd_02202013.RData")
86 88
  #clim_obj<-load_obj("gamclim_fus_mod_365d_GAM_fus5_all_lstd_02202013.RData")
87 89
  
88
  raster_prediction_obj<-load_obj(list_param$raster_prediction_obj)
89
  #method_mod_obj<-raster_prediction_obj$method_mod_obj
90
  raster_prediction_obj<-list_param$raster_prediction_obj
91
  method_mod_obj<-raster_prediction_obj$method_mod_obj
90 92
  method_mod_obj<-raster_prediction_obj$gam_fus_mod #change later for any model type
91 93
  #validation_obj<-raster_prediction_obj$validation_obj
92 94
  validation_obj<-raster_prediction_obj$gam_fus_validation_mod #change later for any model type
......
94 96
  clim_obj<-raster_prediction_obj$gamclim_fus_mod #change later for any model type
95 97
  
96 98
  if (var=="TMAX"){
97
    y_var_name<-"dailyTmax"                                       
99
    y_var_name<-"dailyTmax"
100
    y_var_month<-"TMax"
98 101
  }
99 102
  if (var=="TMIN"){
100
    y_var_name<-"dailyTmin"                                       
103
    y_var_name<-"dailyTmin"
104
    y_var_month <-"TMin"
101 105
  }
102 106
  
103 107
  ## Read covariate stack...
......
114 118
  LC_mask_rec[is.na(LC_mask_rec)]<-0
115 119
    
116 120
  #determine index position matching date selected
117
  
121
  i_dates<-vector("list",length(date_selected))
118 122
  for (j in 1:length(date_selected)){
119 123
    for (i in 1:length(method_mod_obj)){
120 124
      if(method_mod_obj[[i]]$sampling_dat$date==date_selected[j]){  
......
129 133
  
130 134
  #Get raster stack of interpolated surfaces
131 135
  index<-i_dates[[j]]
132
  pred_temp<-as.character(method_mod_obj[[index]]$dailyTmax) #list of files
136
  pred_temp<-as.character(method_mod_obj[[index]][[y_var_name]]) #list of files
133 137
  rast_pred_temp<-stack(pred_temp) #stack of temperature predictions from models 
134 138
  
135 139
  #Get validation metrics, daily spdf training and testing stations, monthly spdf station input
......
163 167
  rmse<-metrics_v$rmse[nrow(metrics_v)]
164 168
  rmse_f<-metrics_s$rmse[nrow(metrics_s)]  
165 169
  
166
  png(paste("LST_TMax_scatterplot_",sampling_dat$date,"_",sampling_dat$prop,"_",sampling_dat$run_samp,
170
  png(paste("LST_",y_var_month,"_scatterplot_",sampling_dat$date,"_",sampling_dat$prop,"_",sampling_dat$run_samp,
167 171
            out_prefix,".png", sep=""))
168
  plot(data_month$TMax,data_month$LST,xlab="Station mo Tmax",ylab="LST mo Tmax")
169
  title(paste("LST vs TMax for",datelabel,sep=" "))
172
  plot(data_month[[y_var_month]],data_month$LST,xlab=paste("Station mo ",y_var_month,sep=""),ylab=paste("LST mo ",y_var_month,sep=""))
173
  title(paste("LST vs ", y_var_month,"for",datelabel,sep=" "))
170 174
  abline(0,1)
171
  nb_point<-paste("n=",length(data_month$TMax),sep="")
175
  nb_point<-paste("n=",length(data_month[[y_var_month]]),sep="")
172 176
  mean_bias<-paste("Mean LST bias= ",format(mean(data_month$LSTD_bias,na.rm=TRUE),digits=3),sep="")
173 177
  #Add the number of data points on the plot
174 178
  legend("topleft",legend=c(mean_bias,nb_point),bty="n")
......
176 180
  
177 181
  ## Figure 2: Daily_tmax_monthly_TMax_scatterplot, modify for TMin!!
178 182
  
179
  png(paste("Daily_tmax_monthly_TMax_scatterplot_",sampling_dat$date,"_",sampling_dat$prop,"_",sampling_dat$run_samp,
183
  png(paste("Monhth_day_scatterplot_",y_var_name,"_",y_var_month,"_",sampling_dat$date,"_",sampling_dat$prop,"_",sampling_dat$run_samp,
180 184
            out_prefix,".png", sep=""))
181
  plot(dailyTmax~TMax,data=data_s,xlab="Mo Tmax",ylab=paste("Daily for",datelabel),main="across stations in VE")
182
  nb_point<-paste("ns=",length(data_s$TMax),sep="")
183
  nb_point2<-paste("ns_obs=",length(data_s$TMax)-sum(is.na(data_s[[y_var_name]])),sep="")
184
  nb_point3<-paste("n_month=",length(data_month$TMax),sep="")
185
  plot(data_s[[y_var_name]]~data_s[[y_var_month]],xlab=paste("Month") ,ylab=paste("Daily for",datelabel),main="across stations in VE")
186
  nb_point<-paste("ns=",length(data_s[[y_var_month]]),sep="")
187
  nb_point2<-paste("ns_obs=",length(data_s[[y_var_month]])-sum(is.na(data_s[[y_var_name]])),sep="")
188
  nb_point3<-paste("n_month=",length(data_month[[y_var_month]]),sep="")
185 189
  #Add the number of data points on the plot
186 190
  legend("topleft",legend=c(nb_point,nb_point2,nb_point3),bty="n",cex=0.8)
187 191
  dev.off()
......
189 193
  ## Figure 3: Predicted_tmax_versus_observed_scatterplot 
190 194
  
191 195
  #This is for mod_kr!! add other models later...
192
  png(paste("Predicted_tmax_versus_observed_scatterplot_",sampling_dat$date,"_",sampling_dat$prop,"_",sampling_dat$run_samp,
193
            out_prefix,".png", sep=""))
194
  #plot(data_s$mod_kr~data_s[[y_var_name]],xlab=paste("Actual daily for",datelabel),ylab="Pred daily")
196
  model_name<-"mod_kr" #can be looped through models later on...
195 197
  
196
  y_range<-range(c(data_s$mod_kr,data_v$mod_kr),na.rm=T)
198
  png(paste("Predicted_versus_observed_scatterplot_",y_var_name,"_",model_name,"_",sampling_dat$date,"_",sampling_dat$prop,"_",
199
            sampling_dat$run_samp,out_prefix,".png", sep=""))
200
  y_range<-range(c(data_s[[model_name]],data_v[[model_name]]),na.rm=T)
197 201
  x_range<-range(c(data_s[[y_var_name]],data_v[[y_var_name]]),na.rm=T)
198 202
  col_t<- c("black","red")
199 203
  pch_t<- c(1,2)
200
  plot(data_s$mod_kr,data_s[[y_var_name]], 
204
  plot(data_s[[model_name]],data_s[[y_var_name]], 
201 205
       xlab=paste("Actual daily for",datelabel),ylab="Pred daily", 
202 206
       ylim=y_range,xlim=x_range,col=col_t[1],pch=pch_t[1])
203
  points(data_v$mod_kr,data_v[[y_var_name]],col=col_t[2],pch=pch_t[2])
207
  points(data_v[[model_name]],data_v[[y_var_name]],col=col_t[2],pch=pch_t[2])
204 208
  grid(lwd=0.5, col="black")
205
  #plot(data_v$mod_kr~data_v[[y_var_name]],xlab=paste("Actual daily for",datelabel),ylab="Pred daily")
206 209
  abline(0,1)
207 210
  legend("topleft",legend=c("training","testing"),pch=pch_t,col=col_t,bty="n",cex=0.8)
208
  title(paste("Predicted_tmax_versus_observed_scatterplot for",datelabel,sep=" "))
209
  nb_point1<-paste("ns_obs=",length(data_s$TMax)-sum(is.na(data_s[[y_var_name]])),sep="")
211
  title(paste("Predicted_versus_observed_",y_var_name,"_",model_name,"_",datelabel,sep=" "))
212
  nb_point1<-paste("ns_obs=",length(data_s[[y_var_name]])-sum(is.na(data_s[[model_name]])),sep="")
213
  nb_point2<-paste("nv_obs=",length(data_v[[y_var_name]])-sum(is.na(data_v[[model_name]])),sep="")
214

  
210 215
  rmse_str1<-paste("RMSE= ",format(rmse,digits=3),sep="")
211 216
  rmse_str2<-paste("RMSE_f= ",format(rmse_f,digits=3),sep="")
212 217
  
213 218
  #Add the number of data points on the plot
214
  legend("bottomright",legend=c(nb_point1,rmse_str1,rmse_str2),bty="n",cex=0.8)
219
  legend("bottomright",legend=c(nb_point1,nb_point2,rmse_str1,rmse_str2),bty="n",cex=0.8)
215 220
  dev.off()
216 221
  
217
  ## Figure 5: prediction raster images
218
  png(paste("Raster_prediction_",sampling_dat$date,"_",sampling_dat$prop,"_",sampling_dat$run_samp,
222
  ## Figure 4a: prediction raster images
223
  png(paste("Raster_prediction_",y_var_name,"_",sampling_dat$date,"_",sampling_dat$prop,"_",sampling_dat$run_samp,
219 224
            out_prefix,".png", sep=""))
220 225
  #paste(metrics_v$pred_mod,format(metrics_v$rmse,digits=3),sep=":")
221 226
  names(rast_pred_temp)<-paste(metrics_v$pred_mod,format(metrics_v$rmse,digits=3),sep=":")
......
223 228
  levelplot(rast_pred_temp)
224 229
  dev.off()
225 230
  
226
  ## Figure 5b: prediction raster images
231
  ## Figure 4b: prediction raster images
227 232
  png(paste("Raster_prediction_plot",sampling_dat$date,"_",sampling_dat$prop,"_",sampling_dat$run_samp,
228 233
            out_prefix,".png", sep=""))
229 234
  #paste(metrics_v$pred_mod,format(metrics_v$rmse,digits=3),sep=":")
......
232 237
  plot(rast_pred_temp)
233 238
  dev.off()
234 239
  
235
  ## Figure 6: training and testing stations used
236
  png(paste("Training_testing_stations_map_",sampling_dat$date,"_",sampling_dat$prop,"_",sampling_dat$run_samp,
240
  ## Figure 5: training and testing stations used
241
  png(paste("Training_testing_stations_map_",y_var_name,"_",sampling_dat$date,"_",sampling_dat$prop,"_",sampling_dat$run_samp,
237 242
            out_prefix,".png", sep=""))
238 243
  plot(raster(rast_pred_temp,layer=5))
239 244
  plot(data_s,col="black",cex=1.2,pch=2,add=TRUE)
......
243 248
         pch=c(2,1),bty="n")
244 249
  dev.off()
245 250
  
246
  ## Figure 7: monthly stations used
251
  ## Figure 6: monthly stations used
247 252
  
248
  png(paste("Monthly_data_study_area",
253
  png(paste("Monthly_data_study_area_", y_var_name,
249 254
            out_prefix,".png", sep=""))
250 255
  plot(raster(rast_pred_temp,layer=5))
251 256
  plot(data_month,col="black",cex=1.2,pch=4,add=TRUE)
252 257
  title("Monthly ghcn station in Venezuela for January")
253 258
  dev.off()
254 259
  
255
  ## Figure 8: delta surface and bias
260
  ## Figure 7: delta surface and bias
256 261
  
257
  png(paste("Bias_delta_surface_",sampling_dat$date[i],"_",sampling_dat$prop[i],
262
  png(paste("Bias_delta_surface_",y_var_name,"_",sampling_dat$date[i],"_",sampling_dat$prop[i],
258 263
            "_",sampling_dat$run_samp[i],out_prefix,".png", sep=""))
259 264
  
260 265
  bias_rast<-stack(clim_obj[[index]]$bias)

Also available in: Unified diff