Project

General

Profile

« Previous | Next » 

Revision b6f62053

Added by Benoit Parmentier over 11 years ago

covariates script, modification of screening function related to CANHEIGHT and LC

View differences:

climate/research/oregon/interpolation/covariates_production_temperatures.R
11 11
# -24 LST layers: "climatology" produced from MOD11A1, LST (mean and obs) using script in step 1 of workflow
12 12
# 3) The output is a multiband file in tif format with projected covariates for the processing region/tile.             
13 13
#AUTHOR: Benoit Parmentier                                                                       
14
#DATE: 06/20/2013                                                                                 
14
#DATE: 08/05/2013                                                                                 
15 15
#PROJECT: NCEAS INPLANT: Environment and Organisms --TASK#363--   
16 16

  
17 17
##Comments and TODO:
......
167 167
}
168 168

  
169 169
screening_val_r_stack_fun<-function(list_val_range,r_stack){
170
  #Screening values for raster stack
170
  #Screening values for a raster stack by providing a valid range. Values outside the valid
171
  #range are assigned NA. Layers in the stack/brick are only screened if a name valid range is provided.
171 172
  #input: list_val_range: list of character strings comma separated
172 173
  #        e.g.: "mm_12,-15,50","mm_12,-15,50"
173 174
  #               variable name, min value, max value
174
    
175
  #The user must include the name of the variable matching the names in the raster brick/stack.
176
  #Values are assigned NA if they are less than the mini value or greater than the maximum value.
177
  #Output: stack with screened values. Note that the original order of layer names is not preserved!!!
178
  
179
  ## Parameters: parsing
175 180
  
176 181
  tab_range_list<-do.call(rbind,as.list(list_val_range))
177 182

  
......
186 191
  val_rst<-vector("list",nrow(tab_range)) #list of one row data.frame
187 192
  
188 193
  for (k in 1:nrow(tab_range)){
189
    avl<-c(-Inf,tab_range$vmin[k],NA, tab_range$vmax[k],+Inf,NA)   #This creates a input vector...val 1 are -9999, 2 neg, 3 positive
190
    rclmat<-matrix(avl,ncol=3,byrow=TRUE)
194
    #avl<-c(-Inf,tab_range$vmin[k],NA, tab_range$vmax[k],+Inf,NA)   #This creates a input vector...val 1 are -9999, 2 neg, 3 positive
195
    #avl<-c(tab_range$vmin[k],tab_range$vmax[k],NA)   #This creates a input vector...val 1 are -9999, 2 neg, 3 positive
196
    
197
    #rclmat<-matrix(avl,ncol=3,byrow=TRUE)
191 198
    #s_raster_r<-raster(r_stack,match(tab_range$varterm[k],names(r_stack))) #select relevant layer from stack
192 199
    s_raster_r<-raster(r_stack,match(tab_range$varname[k],names(r_stack)))
193
    s_raster_r<-reclassify(s_raster_r,rclmat)  #now reclass values 
200
    #s_raster_r<-reclassify(s_raster_r,rclmat)  #now reclass values 
201
    #s_raster_r<-reclassify(s_raster_r,rclmat,include.lowest=TRUE,right=FALSE)  #now reclass values 
202
    #s_raster_r<-reclassify(s_raster_r,rclmat,include.lowest=FALSE,right=FALSE)  #now reclass values 
203
    #s_raster_r<-reclassify(s_raster_r,rclmat,include.lowest=TRUE,right=TRUE)  #now reclass values
204
    #s_raster_r<-reclassify(s_raster_r,rclmat,include.lowest=FALSE,right=TRUE)  #now reclass values
194 205
    #r_stack<-dropLayer(r_stack,match(tab_range$varname[k],names(r_stack)))
206
    s_raster_r[s_raster_r < tab_range$vmin[k]] <- NA #Assign NA if less than the minimum value in the valid range
207
    s_raster_r[s_raster_r > tab_range$vmax[k]] <- NA #Assign NA if greater than the maxim value in the valid range
208
    
195 209
    names(s_raster_r)<-tab_range$varname[k] #Loss of layer names when using reclass
196 210
    val_rst[[k]]<-s_raster_r
197 211
  }
......
462 476
    proj4string(ref_rast) <- CRS_interp #Assign given reference system from master script...
463 477
  }
464 478
  
465

  
466 479
  out_suffix_lst <-paste(out_suffix,".tif",sep="")          
467 480
  mean_lst_list_outnames<-change_names_file_list(mean_m_list,out_suffix_lst,"reg_",".tif",out_path=out_path)     
468 481
  nobs_lst_list_outnames<-change_names_file_list(nobs_m_list,out_suffix_lst,"reg_",".tif",out_path=out_path)   
......
509 522
  lc_list <- c(infile_elev,infile_canheight,infile_distoc) #, lc_list #15 layers to reproject...
510 523
  out_suffix_l <-paste(out_suffix,".tif",sep="")          
511 524
  lc_list_outnames<-change_names_file_list(lc_list,out_suffix_l,"reg_",".tif",out_path=out_path)    
525
  j<-1
512 526
  list_param_create_region<-list(j,raster_name=lc_list,reg_ref_rast=ref_rast,out_rast_name=lc_list_outnames)
513 527
  list_covar_layers <- mclapply(1:3, list_param=list_param_create_region, create__m_raster_region,mc.preschedule=FALSE,mc.cores = 3) #This is the end bracket from mclapply(...) statement
514 528
  
......
526 540
  r2<-raster(terrain_rast,layer=pos)             #Select layer from stack
527 541
  N<-cos(r1)
528 542
  E<-sin(r1)
529
  Nw<-sin(r2)*cos(r1)   #Adding a variable to the dataframe
530
  Ew<-sin(r2)*sin(r1)   #Adding variable to the dataframe.
543
  Nw<-sin(r2)*cos(r1)   #Calculating Northness weighted by the slope
544
  Ew<-sin(r2)*sin(r1)   #Calculating Eastness weighted by the slope
531 545
  
532 546
  ################################
533 547
  #6) X-Y coordinates and LAT-LONG: do not keep in memory?

Also available in: Unified diff