Revision ef00d3cf
Added by Benoit Parmentier about 8 years ago
climate/research/oregon/interpolation/global_product_assessment_part2.R | ||
---|---|---|
4 | 4 |
#This part 2 of the assessment focuses on graphics to explore the spatial patterns of raster times series as figures and movie |
5 | 5 |
#AUTHOR: Benoit Parmentier |
6 | 6 |
#CREATED ON: 10/03/2016 |
7 |
#MODIFIED ON: 10/21/2016
|
|
7 |
#MODIFIED ON: 10/22/2016
|
|
8 | 8 |
#Version: 1 |
9 | 9 |
#PROJECT: Environmental Layers project |
10 | 10 |
#COMMENTS: Initial commit, script based on part NASA biodiversity conferenc |
... | ... | |
18 | 18 |
#source /nobackupp6/aguzman4/climateLayers/sharedModules2/etc/environ.sh |
19 | 19 |
# |
20 | 20 |
#setfacl -Rm u:aguzman4:rwx /nobackupp6/aguzman4/climateLayers/LST_tempSpline/ |
21 |
#COMMIT: checking missing files for region 5 with check_missing function
|
|
21 |
#COMMIT: generating animation for region 5 with and without range limit
|
|
22 | 22 |
|
23 | 23 |
################################################################################################# |
24 | 24 |
|
... | ... | |
128 | 128 |
#in_dir_mosaic <- "/data/project/layers/commons/NEX_data/climateLayers/out/reg5/mosaic/mosaic" |
129 | 129 |
in_dir <- "/data/project/layers/commons/NEX_data/climateLayers/out/reg5/assessment" |
130 | 130 |
#in_dir_mosaic <- "/data/project/layers/commons/NEX_data/climateLayers/out/reg6/mosaics/mosaic" #predicted mosaic |
131 |
in_dir_mosaic <- "/data/project/layers/commons/NEX_data/climateLayers/out/reg5/mosaics/mosaic"
|
|
131 |
#in_dir_mosaic <- "/data/project/layers/commons/NEX_data/climateLayers/out/reg1/mosaics/mosaic"
|
|
132 | 132 |
in_dir_mosaic <- "/data/project/layers/commons/NEX_data/climateLayers/out/reg5/mosaics/mosaic" |
133 | 133 |
region_name <- c("reg5") #param 6, arg 3 |
134 |
out_suffix <- "global_assessment_reg5_10102016"
|
|
134 |
out_suffix <- "global_assessment_reg5_10222016"
|
|
135 | 135 |
|
136 | 136 |
create_out_dir_param <- TRUE #param 9, arg 6 |
137 | 137 |
|
... | ... | |
171 | 171 |
#dates to plot and analyze |
172 | 172 |
|
173 | 173 |
#l_dates <- c("19990101","19990102","19990103","19990701","19990702","19990703") |
174 |
l_dates <- c("19990101","19990102","19990103","19990104","19990105") |
|
174 |
#l_dates <- c("19990101","19990102","19990103","19990104","19990105")
|
|
175 | 175 |
#df_points_extracted_fname <- "/data/project/layers/commons/NEX_data/climateLayers/out/reg5/mosaic/int_mosaics/data_points_extracted.txt" |
176 | 176 |
df_points_extracted_fname <- NULL #if null extract on the fly |
177 | 177 |
#r_mosaic_fname <- "r_mosaic.RData" |
... | ... | |
230 | 230 |
|
231 | 231 |
#Using default values for parameters exectpt for num_cores=11 instead of 1 |
232 | 232 |
#debug(check_missing) |
233 |
test_missing <- check_missing(lf=lf_raster, |
|
234 |
pattern_str=NULL, |
|
235 |
in_dir=".", #this is not used if lf is given |
|
236 |
date_start="1984101", |
|
237 |
date_end="20141231", |
|
238 |
item_no=13, |
|
239 |
out_suffix="", |
|
240 |
num_cores=num_cores, |
|
241 |
out_dir=".") |
|
233 |
#test_missing <- check_missing(lf=lf_raster,
|
|
234 |
# pattern_str=NULL,
|
|
235 |
# in_dir=".", #this is not used if lf is given
|
|
236 |
# date_start="1984101",
|
|
237 |
# date_end="20141231",
|
|
238 |
# item_no=13,
|
|
239 |
# out_suffix="",
|
|
240 |
# num_cores=num_cores,
|
|
241 |
# out_dir=".")
|
|
242 | 242 |
|
243 | 243 |
##Run this on reg4 and reg5 after |
244 | 244 |
#Add report by year in text file? |
... | ... | |
273 | 273 |
metric_name <- "var_pred" #use RMSE if accuracy |
274 | 274 |
#df_raster <- read.table("df_raster_global_assessment_reg6_10102016.txt",sep=",",header=T) |
275 | 275 |
#plot_figure <- |
276 |
plot_and_animate_raster_time_series(lf_raster=lf_raster, |
|
277 |
NAvalue=NA_flag_val, |
|
278 |
item_no=13, |
|
279 |
region_name=region_name, |
|
280 |
var_name=var_name, |
|
281 |
metric_name=metric_name, |
|
282 |
frame_speed=frame_speed, |
|
283 |
animation_format=animation_format, |
|
284 |
zlim_val=NULL, |
|
285 |
plot_figure=F, |
|
286 |
generate_animation=T, |
|
287 |
num_cores=num_cores, |
|
288 |
out_suffix=out_suffix, |
|
289 |
out_dir=out_dir) |
|
290 |
|
|
291 |
############ Now accuracy |
|
292 |
#### PLOT ACCURACY METRICS: First test #### |
|
293 |
##this will be cleaned up later: |
|
294 |
|
|
295 |
in_dir_mosaic_RMSE <- "/data/project/layers/commons/NEX_data/climateLayers/out/reg6/mosaicsRMSE/mosaic" |
|
296 |
pattern_str <-"*.tif" |
|
297 |
in_dir_mosaic <- in_dir_mosaic_RMSE |
|
298 |
lf_raster_rmse <- list.files(path=in_dir_mosaic,pattern=pattern_str,recursive=F,full.names=T) |
|
299 |
lf_raster <- lf_raster_rmse |
|
300 |
r_stack <- stack(lf_raster,quick=T) #this is very fast now with the quick option! |
|
301 |
#save(r_mosaic,file="r_mosaic.RData") |
|
302 |
|
|
303 |
NAvalue(r_stack) |
|
304 |
plot(r_stack,y=6,zlim=c(0,8000)) #this is not rescaled |
|
305 |
|
|
306 |
lf_mosaic_list <- lf_raster |
|
307 |
list_dates_produced_RMSE <- mclapply(1:2, |
|
308 |
FUN=extract_date, |
|
309 |
x=lf_mosaic_list, |
|
310 |
item_no=15, |
|
311 |
mc.preschedule=FALSE, |
|
312 |
mc.cores = 2) |
|
313 |
item_no <-15 |
|
314 |
list_dates_produced_RMSE <- unlist(mclapply(1:length(lf_raster), |
|
315 |
FUN=extract_date, |
|
316 |
x=lf_raster, |
|
317 |
item_no=item_no, |
|
318 |
mc.preschedule=FALSE, |
|
319 |
mc.cores = num_cores)) |
|
320 |
|
|
321 |
list_dates_produced_date_val <- as.Date(strptime(list_dates_produced_RMSE,"%Y%m%d")) |
|
322 |
month_str <- format(list_dates_produced_date_val, "%b") ## Month, char, abbreviated |
|
323 |
year_str <- format(list_dates_produced_date_val, "%Y") ## Year with century |
|
324 |
day_str <- as.numeric(format(list_dates_produced_date_val, "%d")) ## numeric month |
|
325 |
|
|
326 |
df_raster_rmse <- data.frame(lf=basename(lf_raster), |
|
327 |
date=list_dates_produced_date_val, |
|
328 |
month_str=month_str, |
|
329 |
year=year_str, |
|
330 |
day=day_str, |
|
331 |
dir=dirname(lf_mosaic_list)) |
|
332 |
|
|
333 |
df_raster_fname <- file.path(out_dir,paste0("df_raster_rmse",out_suffix,".txt")) |
|
334 |
write.table(df_raster,file= df_raster_fname,sep=",",row.names = F) |
|
335 |
|
|
336 |
|
|
337 |
r_stack_subset <- subset(r_stack,1:11) |
|
338 |
l_dates <- list_dates_produced_date_val[1:11] |
|
339 |
|
|
340 |
#undebug(plot_raster_mosaic) |
|
341 |
out_suffix_str <- paste0("rmse_",out_suffix) |
|
342 |
|
|
343 |
zlim_val <- NULL |
|
344 |
##Need to add title option!! |
|
345 |
list_param_plot_raster_mosaic <- list(l_dates,r_stack_subset,NA_flag_val,out_dir,out_suffix_str, |
|
346 |
region_name,variable_name, zlim_val) |
|
347 |
names(list_param_plot_raster_mosaic) <- c("l_dates","r_mosaiced_scaled","NA_flag_val_mosaic","out_dir","out_suffix", |
|
348 |
"region_name","variable_name","zlim_val") |
|
349 |
lf_mosaic_plot_fig <- lapply(1:2, |
|
350 |
FUN=plot_raster_mosaic, |
|
351 |
list_param=list_param_plot_raster_mosaic) |
|
352 |
|
|
353 |
### Now run for the full time series |
|
354 |
#13.26 Western time: start |
|
355 |
l_dates <- list_dates_produced_date_val |
|
356 |
r_stack_subset <- r_stack |
|
357 |
zlim_val <- NULL |
|
358 |
list_param_plot_raster_mosaic <- list(l_dates,r_stack_subset,NA_flag_val,out_dir,out_suffix, |
|
359 |
region_name,variable_name, zlim_val) |
|
360 |
names(list_param_plot_raster_mosaic) <- c("l_dates","r_mosaiced_scaled","NA_flag_val_mosaic","out_dir","out_suffix", |
|
361 |
"region_name","variable_name","zlim_val") |
|
362 |
#started at 20.16 on 10/10/2016, finished 22.39 |
|
363 |
lf_mosaic_plot_fig <- mclapply(1:length(l_dates), |
|
364 |
FUN=plot_raster_mosaic, |
|
365 |
list_param=list_param_plot_raster_mosaic, |
|
366 |
mc.preschedule=FALSE, |
|
367 |
mc.cores = num_cores) |
|
368 |
|
|
369 |
|
|
370 |
if(is.null(zlim_val)){ |
|
371 |
out_suffix_movie <- paste("min_max_",out_suffix,sep="") |
|
372 |
}else{ |
|
373 |
zlim_val_str <- paste(zlim_val,sep="_",collapse="_") |
|
374 |
out_suffix_movie <- paste(zlim_val_str,"_",out_suffix,sep="") |
|
375 |
} |
|
376 |
#r_stack_subset <- subset(r_stack,1:11) |
|
377 |
#l_dates <- list_dates_produced_date_val[1:11] |
|
378 |
|
|
379 |
filenames_figures_mosaic_test <- "list_figures_animation_test_reg6.txt" |
|
380 |
|
|
381 |
write.table(unlist(lf_mosaic_plot_fig[1:11]),filenames_figures_mosaic_test,row.names = F,col.names = F,quote = F) |
|
382 |
|
|
383 |
filenames_figures_mosaic <- paste0("list_figures_animation_",out_suffix_movie,".txt") |
|
384 |
|
|
385 |
write.table(unlist(lf_mosaic_plot_fig),filenames_figures_mosaic,row.names = F,col.names = F,quote = F) |
|
386 |
|
|
387 |
#now generate movie with imageMagick |
|
388 |
frame_speed <- 60 |
|
389 |
animation_format <- ".gif" |
|
390 |
out_suffix_str <- out_suffix |
|
391 |
out_suffix_movie <- paste0("rmse_",out_suffix_movie) |
|
392 |
#started: |
|
393 |
|
|
394 |
generate_animation_from_figures_fun(filenames_figures= unlist(lf_mosaic_plot_fig[1:11]), |
|
395 |
frame_speed=frame_speed, |
|
396 |
format_file=animation_format, |
|
397 |
out_suffix=out_suffix_str, |
|
398 |
out_dir=out_dir, |
|
399 |
out_filename_figure_animation="test2_reg6_animation.gif") |
|
400 |
#started 6.43 Western time on Oct 11 and 7.19 |
|
401 |
generate_animation_from_figures_fun(filenames_figures= filenames_figures_mosaic, |
|
402 |
frame_speed=frame_speed, |
|
403 |
format_file=animation_format, |
|
404 |
out_suffix=out_suffix_movie, |
|
405 |
out_dir=out_dir, |
|
406 |
out_filename_figure_animation=NULL) |
|
276 |
debug(plot_and_animate_raster_time_series) |
|
277 |
|
|
278 |
animation_obj <- plot_and_animate_raster_time_series(lf_raster[1:11], |
|
279 |
item_no, |
|
280 |
region_name, |
|
281 |
var_name, |
|
282 |
metric_name, |
|
283 |
NA_flag_val, |
|
284 |
filenames_figures=NULL, |
|
285 |
frame_speed=60, |
|
286 |
animation_format=".gif", |
|
287 |
zlim_val=NULL, |
|
288 |
plot_figure=T, |
|
289 |
generate_animation=T, |
|
290 |
num_cores=num_cores, |
|
291 |
out_suffix="", |
|
292 |
out_dir=".") |
|
293 |
|
|
407 | 294 |
|
408 | 295 |
############################ END OF SCRIPT ################################## |
Also available in: Unified diff
generating animation for region 5 with and without range limit