Project

General

Profile

« Previous | Next » 

Revision 277a0e97

Added by Benoit Parmentier over 11 years ago

testing workflow for Oregon, fixing problems related to automation for covariates production

View differences:

climate/research/oregon/interpolation/covariates_production_temperatures.R
67 67
  #Output: spatial grid data frame of the subset of tiles
68 68
  
69 69
  ## Parse input arguments
70
  raster_name <- list_param$raster_name[j] #list of raster ot project and crop
71
  reg_ref_rast <- list_param$reg_ref_rast 
70
  raster_name <- list_param$raster_name[[j]] #list of raster ot project and crop, this is a list!!
71
  reg_ref_rast <- list_param$reg_ref_rast #This must have a coordinate system defined!!
72 72
  out_rast_name <- list_param$out_rast_name[j]
73 73
  
74 74
  ## Start #
75 75
  layer_rast<-raster(raster_name)
76
  new_proj<-proj4string(layer_rast)                  #Extract coordinates reference system in PROJ4 format
77
  region_temp_projected<-projectExtent(reg_ref_rast,CRS(new_proj))     #Project from current to region coord. system
76
  new_proj<-proj4string(layer_rast)                  #Extract current coordinates reference system in PROJ4 format
77
  region_temp_projected<-projectExtent(reg_ref_rast,CRS(new_proj))     #Project from ref to current region coord. system
78 78
  layer_crop_rast<-crop(layer_rast, region_temp_projected) #crop using the extent from the region tile
79 79
  #layer_projected_rast<-projectRaster(from=layer_crop_rast,crs=proj4string(reg_outline),method="ngb")
80 80
  layer_projected_rast<-projectRaster(from=layer_crop_rast,to=reg_ref_rast,method="ngb")
......
314 314
  ### Now mosaic tiles...Note that function could be improved to use less memory
315 315
  list_param_mosaic<-list(j,mosaic_list_mean,out_rastnames_mean,out_path)
316 316
  names(list_param_mosaic)<-c("j","mosaic_list","out_rastnames","out_path")
317
  mean_m_list <-mclapply(1:12, list_param=list_param_mosaic, mosaic_m_raster_list,mc.preschedule=FALSE,mc.cores = 12) #This is the end bracket from mclapply(...) statement
317
  mean_m_list <-mclapply(1:12, list_param=list_param_mosaic, mosaic_m_raster_list,mc.preschedule=FALSE,mc.cores = 6) #This is the end bracket from mclapply(...) statement
318 318
  
319 319
  list_param_mosaic<-list(j,mosaic_list_nobs,out_rastnames_nobs,out_path)
320 320
  names(list_param_mosaic)<-c("j","mosaic_list","out_rastnames","out_path")
321
  nobs_m_list <-mclapply(1:12, list_param=list_param_mosaic, mosaic_m_raster_list,mc.preschedule=FALSE,mc.cores = 12) #This is the end bracket from mclapply(...) statement
321
  nobs_m_list <-mclapply(1:12, list_param=list_param_mosaic, mosaic_m_raster_list,mc.preschedule=FALSE,mc.cores = 6) #This is the end bracket from mclapply(...) statement
322 322
  
323 323
  #Use this as ref file for now?? Ok for the time being: this will need to change to be a processing tile.
324 324
  if (ref_rast_name==""){
325
    ref_rast<-raster(mean_m_list[[1]])
325
    ref_rast<-raster(mean_m_list[[1]]) 
326
    #Use one mosaiced modis tile as reference image...We will need to add a function 
327
    #to define a local reference system and reproject later!!
328
    #Assign new projection system here in the argument CRS_interp (!it is used later)
326 329
  }else{
327 330
    ref_rast<-raster(ref_rast_name) #This is the reference image used to define the study/processing area
331
    proj4string(ref_rast) <- CRS_interp #Assign given reference system
328 332
  }
329 333
  
330 334
  ## Project mosaiced tiles if local projection is provided...
331 335

  
332 336
  out_suffix_lst <-paste(out_suffix,".tif",sep="")          
333 337
  mean_lst_list_outnames<-change_names_file_list(mean_m_list,out_suffix_lst,"reg_",".tif",out_path=out_path)     
334
  nobs_lst_list_outnames<-change_names_file_list(nobs_m_list,out_suffix_lst,"reg_",".tif",out_path=out_path)    
338
  nobs_lst_list_outnames<-change_names_file_list(nobs_m_list,out_suffix_lst,"reg_",".tif",out_path=out_path)   
335 339
  
340
  # if ref_name!="" need to reproject and clip!!! do this in mclapply for all the list of covar!!!
336 341
  if (ref_rast_name!=""){
337 342
    #list(mean_m_list)
338 343
    list_param_create_region<-list(j,raster_name=mean_m_list,reg_ref_rast=ref_rast,out_rast_name=mean_lst_list_outnames)
344
    #test<-create__m_raster_region(1,list_param_create_region)
339 345
    mean_m_list <-mclapply(1:12, list_param=list_param_create_region, create__m_raster_region,mc.preschedule=FALSE,mc.cores = 6) #This is the end bracket from mclapply(...) statement
340 346
    list_param_create_region<-list(j,raster_name=nobs_m_list,reg_ref_rast=ref_rast,out_rast_name=nobs_lst_list_outnames)
341 347
    nobs_m_list <-mclapply(1:12, list_param=list_param_create_region, create__m_raster_region,mc.preschedule=FALSE,mc.cores = 6) #This is the end bracket from mclapply(...) statement
342 348
  }
343
  # if ref_name!="" need to reproject and clip!!! do this in mclapply for all the list of covar!!!
349

  
344 350
  
345 351
  #ref_rast <-raster("mosaiced_dec_lst_mean_VE_03182013.tif")
346 352
  #Modis shapefile tile is slighly shifted:
climate/research/oregon/interpolation/master_script_temp.R
10 10
#STAGE 5: Output analyses: assessment of results for specific dates...
11 11
#
12 12
#AUTHOR: Benoit Parmentier                                                                       
13
#DATE: 05/30/2013                                                                                 
13
#DATE: 05/31/2013                                                                                 
14 14

  
15 15
#PROJECT: NCEAS INPLANT: Environment and Organisms --TASK#363, TASK$568--   
16 16

  
......
69 69
source(file.path(script_path,"GAM_fusion_function_multisampling_validation_metrics_05062013.R"))
70 70

  
71 71
#stages_to_run<-c(1,2,3,4,5) #May decide on antoher strategy later on...
72
stages_to_run<-c(1,2,3,4,5) #May decide on antoher strategy later on...
72
stages_to_run<-c(0,2,3,4,5) #May decide on antoher strategy later on...
73 73

  
74 74
var<-"TMAX" # variable being interpolated
75
out_prefix<-"_365d_GAM_fus_all_lst_05302013"                #User defined output prefix
76
out_suffix<-"_OR_05302013"
77
out_suffix_modis <-"_05302013"
75
out_prefix<-"_365d_GAM_fus_all_lst_05312013"                #User defined output prefix
76
out_suffix<-"_OR_05312013"
77
out_suffix_modis <-"_05302013" #use tiles produce previously
78 78

  
79 79
#interpolation_method<-c("gam_fusion","gam_CAI") #other otpions to be added later
80 80
#interpolation_method<-c("gam_CAI") #other otpions to be added later

Also available in: Unified diff