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:
|
testing workflow for Oregon, fixing problems related to automation for covariates production