Project

General

Profile

« Previous | Next » 

Revision 661e6ef0

Added by Benoit Parmentier over 11 years ago

covariates preparation script, modifications to handle LST inputs and output directory

View differences:

climate/research/oregon/interpolation/covariates_production_temperatures.R
10 10
# -MODIS LST: mean and obs
11 11
#3) The output is a multiband file in tif format with projected covariates for the processing region/tile.             
12 12
#AUTHOR: Benoit Parmentier                                                                       
13
#DATE: 03/21/2013                                                                                 
13
#DATE: 05/14/2013                                                                                 
14 14
#PROJECT: NCEAS INPLANT: Environment and Organisms --TASK#363--   
15 15

  
16 16
##Comments and TODO:
......
48 48
}
49 49

  
50 50
create_raster_region <-function(raster_name,reg_ref_rast){
51
  #This functions returns a subset of tiles from the modis grdi.
51
  #This functions returns a subset of tiles from the modis grdid.
52 52
  #Arguments: raster name of the file,reference file with
53 53
  #Output: spatial grid data frame of the subset of tiles
54 54
  
......
90 90
covariates_production_temperature<-function(list_param){
91 91
  #This functions produce covariates used in the interpolation of temperature.
92 92
  #It requires 15 arguments:
93
  #
93
  #1)  var : interpolated variable: TMIN, TMAX, (PRCP?)
94
  #2)  out_path : output directory 
95
  #3)  lc_path 
96
  #4)  infile_modis_grid 
97
  #5)  infile_elev : this is the global file: replace later with the input produced by the DEM team
98
  #6)  infile_canheight : Canopy height
99
  #7)  list_tiles_modis : tile for Venezuela and surrounding area
100
  #8)  infile_reg_outline : input region outline defined by polygon
101
  #9)  CRS_interp : local projection system
102
  #10) CRS_locs_WGS84 : CRS_locs_WGS84 #
103
  #11) out_region_name : generated on the fly
104
  #12) out_suffix : added to the covariates stack/brick 
105
  #13) ref_rast_name: local raster name defining resolution, exent, local projection--. set on the fly??
106
  #14) hdfdir: directory where the LST averages are stored...
107
  #15) out_suffix_modis : suffix used in producing LST climatology 
108
  #16) covar_names : names of covariates
94 109
  #
95 110
  #
96 111
  
......
127 142
  out_region_name<-list_param$out_region_name  #generated on the fly
128 143
  out_suffix<-list_param$out_suffix 
129 144
  ref_rast_name<-list_param$ref_rast_name #local raster name defining resolution, exent, local projection--. set on the fly??
145
  hdfdir <- list_param$hdfdir
146
  out_suffix_modis <- list_param$out_suffix_modis
130 147
  covar_names<-list_param$covar_names 
131 148
  
132 149
  ##### SET UP STUDY AREA ####
133 150
  
134
  setwd(in_path)
151
  #setwd(in_path)
152
  setwd(out_path)
153
  
154
  list_tiles_modis <- unlist(strsplit(list_tiles_modis,","))  # transform string into separate element in char vector
155
  
156
  filename<-sub(".shp","",basename(infile_modis_grid))       #Removing path and the extension from file name.
157
  #modis_grid<-readOGR(".", filename)     #Reading shape file using rgdal library
158
  modis_grid<-readOGR(dsn=dirname(infile_modis_grid), filename)     #Reading shape file using rgdal library
135 159
  
136
  filename<-sub(".shp","",infile_modis_grid)       #Removing the extension from file.
137
  modis_grid<-readOGR(".", filename)     #Reading shape file using rgdal library
138 160
  #filename<-sub(".shp","",infile1)       #Removing the extension from file.
139 161
  #world_countries<-readOGR(".", filename)     #Reading shape file using rgdal library
162
  #outfile1<-file.path(out_path,paste("stations","_",out_prefix,".shp",sep=""))
163
  #writeOGR(stat_reg,dsn= dirname(outfile1),layer= sub(".shp","",basename(outfile1)), driver="ESRI Shapefile",overwrite_layer=TRUE)
140 164
  
141 165
  if (infile_reg_outline!=""){
142
    filename<-sub(".shp","",infile_reg_outline)   #Removing the extension from file.
143
    reg_outline<-readOGR(".", filename)
166
    filename<-sub(".shp","",basename(infile_reg_outline))   #Removing path and the extension from file name.
167
    reg_outline<-readOGR(dsn=dirname(infile_reg_outline), filename)
144 168
  }
145 169
  
146 170
  if (infile_reg_outline==""){
147 171
    reg_outline<-create_modis_tiles_region(modis_grid,list_tiles_modis) #problem...this does not 
148 172
    #align with extent of modis LST!!!
149
    writeOGR(reg_outline,dsn= ".",layer= paste("outline",out_region_name,"_",out_suffix,sep=""), 
173
    writeOGR(reg_outline,dsn= out_path,layer= paste("outline",out_region_name,"_",out_suffix,sep=""), 
150 174
             driver="ESRI Shapefile",overwrite_layer="TRUE")
151 175
  }
152 176
  
......
166 190
    lst_pat<-"LST_Night_1km"
167 191
  }
168 192
  if (var=="TMAX"){
169
    lst_pat<-"" #for the time being change at later stage...
170
    #day_pat<-"LST_Day_1km"
193
    lst_pat<-"LST_Day_1km" #for the time being change at later stage...
171 194
  }
172 195
  
173 196
  #Get list of files containing the LST averages
174
  pat_str2 <- glob2rx(paste("nobs","*",lst_pat,"*.tif",sep=""))
175
  tmp_str2<- mixedsort(list.files(pattern=pat_str2))
176
  pat_str1 <- glob2rx(paste("mean","*",lst_pat,"*.tif",sep=""))
177
  tmp_str1<- mixedsort(list.files(pattern=pat_str1))
197
  #pat_str2 <- glob2rx(paste("nobs","*",lst_pat,"*.tif",sep=""))
198
  pat_str2 <- glob2rx(paste("nobs","*",lst_pat,"*",out_suffix_modis,"*.tif",sep=""))
199
  #mixedsort(list.files(path=hdfdir,pattern=".*tif"))
200
  tmp_str2 <- mixedsort(list.files(path=hdfdir,pattern=pat_str2)) #note that this assumes the LST averages are stored in hdfdir
201
  #pat_str1 <- glob2rx(paste("mean","*",lst_pat,"*.tif",sep=""))
202
  pat_str1 <- glob2rx(paste("mean","*",lst_pat,"*",out_suffix_modis,"*.tif",sep=""))
203
  tmp_str1 <- mixedsort(list.files(path=hdfdir,pattern=pat_str1))
178 204
  #add lines using grep to select tiles...
179 205
 
180 206
  #Format list for mosaicing: mosaic for every month the relevant number of files

Also available in: Unified diff