Project

General

Profile

« Previous | Next » 

Revision 525fff70

Added by Benoit Parmentier over 11 years ago

covariates preparation, dealing with projection shift and keeping track of covariates names after screening

View differences:

climate/research/oregon/interpolation/covariates_production_temperatures.R
250 250
  return(reg_outline_obj)
251 251
} 
252 252
  
253
### Assing projection system to raster layer
254
assign_projection_crs <-function(i,list_param){
255
  #assign projection to list of raster
256
  #proj_str: proj4 information
257
  #filename: raster file 
258
  proj_str<-list_param$proj_str
259
  list_filename<-list_param$list_filename
260
  
261
  filename <-list_filename[[i]]
262
  r<-raster(readGDAL(filename))
263
  projection(r)<-proj_str
264
  writeRaster(r,filename=filename,overwrite=TRUE)
265
}
253 266
  
254 267
covariates_production_temperature<-function(list_param){
255 268
  #This functions produce covariates used in the interpolation of temperature.
......
420 433
  names(list_param_mosaic)<-c("j","mosaic_list","out_rastnames","out_path")
421 434
  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
422 435
  
436
  ## Project mosaiced tiles if local projection is provided...
437
  #Modis shapefile tile is slighly shifted: this needs to be resolved...
438
  # +proj=sinu +lon_0=0 +x_0=0 +y_0=0 +a=6370997 +b=6370997 +units=m +no_defs for ref_rast
439
  #"+proj=sinu +lon_0=0 +x_0=0 +y_0=0 +a=6371007.181 +b=6371007.181 +units=m +no_defs" ??
440
  #reassign proj from modis tile to raster? there is a 10m diff in semi-axes...(a and b)
441
  #This is a temporary solution, we will need to find out how 6370997m was assigned as axis
442
  
443
  proj_modis_str <-"+proj=sinu +lon_0=0 +x_0=0 +y_0=0 +a=6371007.181 +b=6371007.181 +units=m +no_defs"
444
  list_param_assign_proj <-list(j,nobs_m_list,proj_modis_str)
445
  names(list_param_assign_proj)<-c("j","list_filename","proj_str")
446
  #assign_projection_crs(1,list_param_assign_proj)
447
  mclapply(1:12, list_param=list_param_assign_proj, assign_projection_crs,mc.preschedule=FALSE,mc.cores = 6) #This is the end bracket from mclapply(...) statement
448
  list_param_assign_proj <-list(j,mean_m_list,proj_modis_str)
449
  names(list_param_assign_proj)<-c("j","list_filename","proj_str")
450
  mclapply(1:12, list_param=list_param_assign_proj, assign_projection_crs,mc.preschedule=FALSE,mc.cores = 6) #This is the end bracket from mclapply(...) statement
451
  
423 452
  #Use this as ref file for now?? Ok for the time being: this will need to change to be a processing tile.
424 453
  if (ref_rast_name==""){
425 454
    #Use one mosaiced modis tile as reference image...We will need to add a function 
426 455
    ref_rast_temp <-raster(mean_m_list[[1]]) 
427 456
    ref_rast <-projectRaster(from=ref_rast_temp,crs=CRS_interp,method="ngb")
428

  
457
    
429 458
    #to define a local reference system and reproject later!!
430 459
    #Assign new projection system here in the argument CRS_interp (!it is used later)
431 460
  }else{
......
433 462
    proj4string(ref_rast) <- CRS_interp #Assign given reference system from master script...
434 463
  }
435 464
  
436
  ## Project mosaiced tiles if local projection is provided...
437 465

  
438 466
  out_suffix_lst <-paste(out_suffix,".tif",sep="")          
439 467
  mean_lst_list_outnames<-change_names_file_list(mean_m_list,out_suffix_lst,"reg_",".tif",out_path=out_path)     
......
456 484
  #  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
457 485
  #}
458 486
  
459
  #ref_rast <-raster("mosaiced_dec_lst_mean_VE_03182013.tif")
460
  #Modis shapefile tile is slighly shifted:
461
  # +proj=sinu +lon_0=0 +x_0=0 +y_0=0 +a=6370997 +b=6370997 +units=m +no_defs for ref_rast
462
  #"+proj=sinu +lon_0=0 +x_0=0 +y_0=0 +a=6371007.181 +b=6371007.181 +units=m +no_defs" ??
463
  #reassign proj from modis tile to raster? there is a 10m diff in semi-axes...(a and b)
464
  
465 487
  ######################################
466 488
  #4) LCC land cover
467 489
  
......
552 574
                 overwrite=TRUE,NAflag=-999,bylayer=FALSE,bandorder="BSQ")
553 575
  #using bil format more efficient??
554 576
  
555
  #return reg_outline!!!
577
  #return reg_outline!!! After screeening the order of the names of covariates has changed!!! We must keep track of this!!
556 578
  covar_obj <-list(raster_name,infile_reg_outline,names(s_raster))
557 579
  names(covar_obj) <-c("infile_covariates","infile_reg_outline","covar_names")
580
  save(covar_obj,file= file.path(out_path,paste("covar_obj_",out_prefix,".RData",sep="")))
558 581
  return(covar_obj)
559 582
}
560 583

  

Also available in: Unified diff