Project

General

Profile

« Previous | Next » 

Revision 48de039c

Added by Benoit Parmentier about 8 years ago

script 2 product assessment, modification of figures

View differences:

climate/research/oregon/interpolation/global_product_assessment_part2.R
65 65

  
66 66
#Mosaic related on NEX
67 67
#script_path <- "/home/parmentier/Data/IPLANT_project/env_layers_scripts"
68
function_mosaicing_functions <- "global_run_scalingup_mosaicing_function_08232016.R" #Functions used to mosaic predicted tiles
69
function_mosaicing <-"global_run_scalingup_mosaicing_08222016.R" #main scripts for mosaicing predicted tiles
68
function_mosaicing_functions <- "global_run_scalingup_mosaicing_function_09282016.R" #Functions used to mosaic predicted tiles
69
function_mosaicing <-"global_run_scalingup_mosaicing_09282016.R" #main scripts for mosaicing predicted tiles
70 70

  
71 71
source(file.path(script_path,function_mosaicing)) #source all functions used in this script 
72 72
source(file.path(script_path,function_mosaicing_functions)) #source all functions used in this script 
......
87 87
#Product assessment
88 88
function_product_assessment_part1_functions <- "global_product_assessment_part1_functions_09192016b.R"
89 89
source(file.path(script_path,function_product_assessment_part1_functions)) #source all functions used in this script 
90
function_product_assessment_part2_functions <- "global_product_assessment_part2_functions_10032016b.R"
91
source(file.path(script_path,function_product_assessment_part2_functions)) #source all functions used in this script 
90 92

  
91 93
###############################
92 94
####### Parameters, constants and arguments ###
......
191 193
  setwd(out_dir) #use previoulsy defined directory
192 194
}
193 195

  
194
setwd(out_dir)
196
#setwd(out_dir)
195 197

  
196 198
###########  ####################
197 199

  
......
211 213
  r_stack <- stack(lf_raster,quick=T) #this is very fast now with the quick option!
212 214
}
213 215

  
216
NAvalue(r_stack)
217
plot(r_stack,y=6,zlim=c(-10000,10000)) #this is not rescaled
218
plot(r_stack,zlim=c(-50,50),col=matlab.like(255))
219

  
220
#plot(r_mosaic_scaled,y=6,zlim=c(-50,50))
221
#plot(r_mosaic_scaled,zlim=c(-50,50),col=matlab.like(255))
222

  
223
#debug(extract_date)
224
#test <- extract_date(6431,lf_mosaic_list,12) #extract item number 12 from the name of files to get the data
225
#list_dates_produced <- unlist(mclapply(1:length(lf_raster),FUN=extract_date,x=lf_raster,item_no=13,mc.preschedule=FALSE,mc.cores = num_cores))                         
226
lf_mosaic_list <- lf_raster
227
list_dates_produced <-  mclapply(1:2,
228
                                 FUN=extract_date,
229
                                 x=lf_mosaic_list,
230
                                 item_no=13,
231
                                 mc.preschedule=FALSE,
232
                                 mc.cores = 2)  
233
item_no <-13
234
list_dates_produced <- unlist(mclapply(1:length(lf_raster),
235
                                       FUN=extract_date,
236
                                       x=lf_raster,
237
                                       item_no=item_no,
238
                                       mc.preschedule=FALSE,
239
                                       mc.cores = num_cores))                         
240

  
241
list_dates_produced_date_val <- as.Date(strptime(list_dates_produced,"%Y%m%d"))
242
month_str <- format(list_dates_produced_date_val, "%b") ## Month, char, abbreviated
243
year_str <- format(list_dates_produced_date_val, "%Y") ## Year with century
244
day_str <- as.numeric(format(list_dates_produced_date_val, "%d")) ## numeric month
245

  
246
df_raster <- data.frame(lf=basename(lf_raster),
247
                          date=list_dates_produced_date_val,
248
                          month_str=month_str,
249
                          year=year_str,
250
                          day=day_str,
251
                          dir=dirname(lf_mosaic_list))
252

  
253
df_raster_fname <- file.path(out_dir,paste0("df_raster_",out_suffix,".txt"))
254
write.table(df_raster,file= df_raster_fname,sep=",",row.names = F) 
214 255

  
215 256
############### PART5: Make raster stack and display maps #############
216 257
#### Extract corresponding raster for given dates and plot stations used
......
240 281
##################################### PART 5  ######
241 282
##### Plotting specific days for the mosaics
242 283

  
243
r_mosaic_scaled <- stack(lf_mosaic_scaled)
244
NAvalue(r_mosaic_scaled)<- -3399999901438340239948148078125514752.000
245
plot(r_mosaic_scaled,y=6,zlim=c(-50,50))
246
plot(r_mosaic_scaled,zlim=c(-50,50),col=matlab.like(255))
284
function_product_assessment_part2_functions <- "global_product_assessment_part2_functions_10032016b.R"
285
source(file.path(script_path,function_product_assessment_part2_functions)) #source all functions used in this script 
247 286

  
248
#layout_m<-c(1,3) #one row two columns
249
#levelplot(r_mosaic_scaled,zlim=c(-50,50),col.regions=matlab.like(255))
250
#levelplot(r_mosaic_scaled,zlim=c(-50,50),col.regions=matlab.like(255))
287
#NA_flag_val_mosaic <- -3399999901438340239948148078125514752.000
288
r_stack_subset <- subset(r_stack,1:11)
289
l_dates <- list_dates_produced_date_val[1:11]
251 290

  
252
#png(paste("Figure7a__spatial_pattern_tmax_prediction_levelplot_",date_selected,out_prefix,".png", sep=""),
253
#    height=480*layout_m[1],width=480*layout_m[2])
254
#plot(r_pred,col=temp.colors(255),zlim=c(-3500,4500))
255
#plot(r_pred,col=matlab.like(255),zlim=c(-40,50))
256
#paste(raster_name[1:7],collapse="_")
257
#add filename option later
291
#undebug(plot_raster_mosaic)
292
zlim_val <- NULL
293
list_param_plot_raster_mosaic <- list(l_dates,r_stack_subset,NA_flag_val,out_dir,out_suffix,
294
                                      region_name,variable_name, zlim_val)
295
names(list_param_plot_raster_mosaic) <- c("l_dates","r_mosaiced_scaled","NA_flag_val_mosaic","out_dir","out_suffix",
296
                                          "region_name","variable_name","zlim_val")
258 297

  
259
#NA_flag_val_mosaic <- -3399999901438340239948148078125514752.000
298
lf_mosaic_plot_fig <- lapply(1:2,
299
                               FUN=plot_raster_mosaic,
300
                               list_param=list_param_plot_raster_mosaic)         
301

  
302
lf_mosaic_plot_fig <- mclapply(1:length(l_dates),
303
                               FUN=plot_raster_mosaic,
304
                               list_param=list_param_plot_raster_mosaic,
305
                               mc.preschedule=FALSE,
306
                               mc.cores = num_cores)         
260 307

  
261
list_param_plot_raster_mosaic <- list(l_dates,r_mosaic_scaled,NA_flag_val_mosaic,out_dir,out_suffix,
262
                                      region_name,variable_name)
263
names(list_param_plot_raster_mosaic) <- c("l_dates","r_mosaic_scaled","NA_flag_val_mosaic","out_dir","out_suffix",
264
                                          "region_name","variable_name")
265 308

  
266
lf_mosaic_plot_fig <- mclapply(1:length(lf_mosaic_scaled),FUN=plot_raster_mosaic,list_param=list_param_plot_raster_mosaic,mc.preschedule=FALSE,mc.cores = num_cores)                         
267 309

  
268 310
#### PLOT ACCURACY METRICS: First test ####
269 311
##this will be cleaned up later:

Also available in: Unified diff