Project

General

Profile

« Previous | Next » 

Revision b9eed150

Added by Benoit Parmentier about 9 years ago

assessment part1 adding extraction of daily stations for later analyses and mosacing

View differences:

climate/research/oregon/interpolation/global_run_scalingup_assessment_part1.R
5 5
#Part 1 create summary tables and inputs files for figure in part 2 and part 3.
6 6
#AUTHOR: Benoit Parmentier 
7 7
#CREATED ON: 03/23/2014  
8
#MODIFIED ON: 12/07/2015            
8
#MODIFIED ON: 12/11/2015            
9 9
#Version: 4
10 10
#PROJECT: Environmental Layers project  
11 11
#TO DO:
......
171 171
lf_covar_obj <- lapply(in_dir_list,FUN=function(x){list.files(path=x,pattern="covar_obj.*.RData",full.names=T)})
172 172
lf_covar_tif <- lapply(in_dir_list,FUN=function(x){list.files(path=x,pattern="covar.*.tif",full.names=T)})
173 173

  
174
#sub_sampling_obj_daily_gam_CAI_10.0_-75.0.RData
175
#sub_sampling_obj_gam_CAI_10.0_-75.0.RData
176

  
177
lf_sub_sampling_obj_files <- lapply(in_dir_list,FUN=function(x){list.files(path=x,pattern=paste("^sub_sampling_obj_",interpolation_method,".*.RData",sep=""),full.names=T)})
178
lf_sub_sampling_obj_daily_files <- lapply(in_dir_list,FUN=function(x){list.files(path=x,pattern="^sub_sampling_obj_daily.*.RData",full.names=T)})
179

  
174 180
## This will be part of the raster_obj function
175 181
#debug(create_raster_prediction_obj)
176 182
#out_prefix_str <- paste(basename(in_dir_list),out_prefix,sep="_") 
......
267 273
write.table((tb_diagnostic_v_NA),
268 274
            file=file.path(out_dir,paste("tb_diagnostic_v_NA","_",out_prefix,".txt",sep="")),sep=",")
269 275

  
270
##Take where shutdown took place after pathcing
271
#summary_metrics_v_NA <- read.table(file=file.path(out_dir,paste("summary_metrics_v2_NA_",out_prefix,".txt",sep="")),sep=",")
272
#fname <- file.path(out_dir,paste("summary_metrics_v2_NA_",out_suffix,".txt",sep=""))
273
#tb_diagnostic_v_NA <- read.table(file=file.path(out_dir,paste("tb_diagnostic_v_NA","_",out_prefix,".txt",sep="")),sep=",")
274
#tb_diagnostic_s_NA_run10_global_analyses_11302014.txt
275
#tb_s <- read.table(file=file.path(out_dir,paste("tb_diagnostic_s_NA","_",out_suffix,".txt",sep="")),sep=",")
276

  
277
#tb_month_s <- read.table(file=file.path(out_dir,paste("tb_month_diagnostic_s_NA","_",out_suffix,".txt",sep="")),sep=",")
278
#pred_data_month_info <- read.table(file=file.path(out_dir,paste("pred_data_month_info_",out_suffix,".txt",sep="")),sep=",")
279
#pred_data_day_info <- read.table(file=file.path(out_dir,paste("pred_data_day_info_",out_suffix,".txt",sep="")),sep=",")
280
#df_tile_processed <- read.table(file=file.path(out_dir,paste("df_tile_processed_",out_suffix,".txt",sep="")),sep=",")
281

  
282 276
#################
283 277
###Table 3: monthly fit/training accuracy information for all tiles
284 278

  
......
369 363
names(data_day_v_list) <- list_names_tile_id
370 364

  
371 365
data_day_s_tmp <- remove_from_list_fun(data_day_s_list)$list
366
data_day_v_tmp <- remove_from_list_fun(data_day_v_list)$list
367

  
372 368
#df_tile_processed$metrics_v <- remove_from_list_fun(data_month_s_list)$valid
373 369

  
374 370
tile_id <- lapply(1:length(data_day_s_tmp),
375 371
                  FUN=function(i,x){rep(names(x)[i],nrow(x[[i]]))},x=data_day_s_tmp)
376
data_day_s_NAM <- do.call(rbind.fill,data_day_tmp) #combined data_month for "NAM" North America
372
data_day_s_NAM <- do.call(rbind.fill,data_day_s_tmp) #combined data_month for "NAM" North America
377 373
data_day_s_NAM$tile_id <- unlist(tile_id)
378 374

  
375
tile_id <- lapply(1:length(data_day_v_tmp),
376
                  FUN=function(i,x){rep(names(x)[i],nrow(x[[i]]))},x=data_day_v_tmp)
377
data_day_v_NAM <- do.call(rbind.fill,data_day_v_tmp) #combined data_month for "NAM" North America
378
data_day_v_NAM$tile_id <- unlist(tile_id)
379

  
379 380
write.table((data_day_s_NAM),
380 381
            file=file.path(out_dir,paste("data_day_s_NAM","_",out_prefix,".txt",sep="")),sep=",")
382
write.table((data_day_v_NAM),
383
            file=file.path(out_dir,paste("data_day_v_NAM","_",out_prefix,".txt",sep="")),sep=",")
384

  
385
#### Recover subsampling data
386
#For tiles with many stations, there is a subsampling done in terms of distance (spatial pruning) and 
387
#in terms of station numbers if there are still too many stations to consider. This is done at the 
388
#daily and monthly stages.
389

  
390
#lf_sub_sampling_obj_files <- lapply(in_dir_list,FUN=function(x){list.files(path=x,pattern=paste("^sub_sampling_obj_",interpolation_method,".*.RData",sep=""),full.names=T)})
391
#lf_sub_sampling_obj_daily_files <- lapply(in_dir_list,FUN=function(x){list.files(path=x,pattern="^sub_sampling_obj_daily.*.RData",full.names=T)})
392
#sub_sampling_obj <- try(load_obj(lf_sub_sampling_obj_files[[3]])) #This is an example tile
393
#data_removed contains the validation data...
394
#this data can be used for validation of the product. Note that it may be missing for some tiles
395
#as no stations are removed if there are too enough stations in the tile
396
#this will need to be checked later on...
397

  
398
data_month_v_subsampling_list <- mclapply(lf_sub_sampling_obj_files,FUN=function(x){try(x<-load_obj(x));try(extract_from_list_obj(x$validation_mod_month_obj,"data_removed"))},mc.preschedule=FALSE,mc.cores = 6)                           
399
#test <- mclapply(list_raster_obj_files[1:6],FUN=function(x){try(x<-load_obj(x));try(extract_from_list_obj(x$validation_mod_month_obj,"data_s"))},mc.preschedule=FALSE,mc.cores = 6)                           
381 400

  
401
names(data_month_v_subsampling_list) <- list_names_tile_id
402

  
403
data_month_v_subsampling_tmp <- remove_from_list_fun(data_month_v_subsampling_list)$list
404
#df_tile_processed$metrics_v <- remove_from_list_fun(data_month_s_list)$valid
405
#if no stations have been removed then there are no validation stations !!!
406
if(length(data_month_v_subsampling_tmp)!=0){
407
  
408
  tile_id <- lapply(1:length(data_month_v_subsampling_tmp),
409
                  FUN=function(i,x){try(rep(names(x)[i],nrow(x[[i]])))},x=data_month_v_subsampling_tmp)
410
  data_month_v_subsmapling_NAM <- do.call(rbind.fill,ddata_month_v_subsampling_tmp) #combined data_month for "NAM" North America
411
  data_month_v_subsampling_NAM$tile_id <- unlist(tile_id)
412

  
413
  write.table((data_month_v_subsampling_NAM),
414
            file=file.path(out_dir,paste("data_month_v_subsampling_NAM","_",out_prefix,".txt",sep="")),sep=",")
415

  
416
}
417

  
418
## Do the same for daily...
419
## End of potential function started in line 317...this section will be cut down for simplicity
382 420

  
383 421
######################################################
384 422
####### PART 3: EXAMINE STATIONS AND MODEL FITTING ###
......
597 635

  
598 636

  
599 637
########### LAST PART: COPY SOME DATA BACK TO ATLAS #####
638

  
639
#This will be a separate script?? or function?
600 640
#this part cannot be automated...
601 641

  
602 642
### This assumes the tree structure has been replicated on Atlas:
......
605 645
#output_atlas_dir <- "/data/project/layers/commons/NEX_data/output_run5_global_analyses_08252014/output20Deg"
606 646
output_atlas_dir <- file.path("/data/project/layers/commons/NEX_data/",out_dir)
607 647

  
608
output_run10_1500x4500_global_analyses_pred_1992_10052015
648
#output_run10_1500x4500_global_analyses_pred_1992_10052015
609 649
#Make directories on ATLAS
610 650
#for (i in 1:length(df_tile_processed$tile_coord)){
611 651
#  create_dir_fun(file.path(output_atlas_dir,as.character(df_tile_processed$tile_coord[i])),out_suffix=NULL)
......
627 667
#cmd_str <- paste("ssh ",Atlas_hostname,"mkdir",Atlas_dir_mosaic, sep=" ")
628 668

  
629 669
#Atlas_dir_shapefiles <- file.path("/data/project/layers/commons/NEX_data/",basename(out_dir),"shapefiles")
630
#Atlas_hostname <- "parmentier@atlas.nceas.ucsb.edu"
670
Atlas_hostname <- "parmentier@atlas.nceas.ucsb.edu"
631 671
#cmd_str <- paste("ssh ",Atlas_hostname,"mkdir",Atlas_dir_shapefiles, sep=" ")
632 672

  
633 673
#locally on NEX
......
635 675
cmd_str <- paste(" mkdir ",out_dir,"/{mosaic,tiles}", sep="") #create both dir 
636 676
system(cmd_str)
637 677

  
638
#remotely on Atlas
639
cmd_str <- paste("ssh ",Atlas_hostname," mkdir ",Atlas_dir,"/{mosaic,shapefiles,tiles}", sep="")
678
#create remotely on Atlas
679
cmd_str <- paste("ssh ",Atlas_hostname," mkdir ",Atlas_dir,"/{/,mosaic,shapefiles,tiles}", sep="")
640 680
system(cmd_str)
641 681

  
642 682
#Copy summary textfiles back to atlas

Also available in: Unified diff