Project

General

Profile

« Previous | Next » 

Revision 43a74df2

Added by Benoit Parmentier about 9 years ago

testing mask and python path on Atlas

View differences:

climate/research/oregon/interpolation/global_run_scalingup_mosaicing.R
5 5
#Analyses, figures, tables and data are also produced in the script.
6 6
#AUTHOR: Benoit Parmentier 
7 7
#CREATED ON: 04/14/2015  
8
#MODIFIED ON: 10/23/2015            
8
#MODIFIED ON: 10/26/2015            
9 9
#Version: 5
10 10
#PROJECT: Environmental Layers project     
11 11
#COMMENTS: analyses run for reg4 1992 for test of mosaicing using 1500x4500km and other tiles
......
95 95

  
96 96
infile_mask <- "/data/project/layers/commons/NEX_data/output_run10_1500x4500_global_analyses_pred_1992_10052015/r_mask_reg4.tif"
97 97

  
98
#tb_accuracy_name <- file.path(in_dir,paste("tb_diagnostic_v_NA","_",out_suffix_str,".txt",sep=""))
99
tb_accuracy_name <- "/data/project/layers/commons/NEX_data/output_run10_1500x4500_global_analyses_pred_1992_10052015/tb_diagnostic_v_NA_run10_1500x4500_global_analyses_pred_1992_10052015.txt"
100

  
98 101
########################## START SCRIPT ##############################
99 102

  
100 103

  
......
112 115
setwd(out_dir)
113 116

  
114 117

  
115
tb <- read.table(file=file.path(in_dir,paste("tb_diagnostic_v_NA","_",out_suffix_str,".txt",sep="")),sep=",")
116

  
117

  
118
lf_mosaic1 <-list.files(path=file.path(in_dir_tiles),    
119
           pattern=paste(".*.",day_to_mosaic[1],".*.tif$",sep=""),full.names=T) #choosing date 2...20100901
120

  
121
lf_mosaic2 <-list.files(path=file.path(in_dir_tiles),    
122
           pattern=paste(".*.",day_to_mosaic[2],".*.tif$",sep=""),full.names=T) #choosing date 2...20100901
123

  
118
tb <- read.table(file=tb_accuracy_name,sep=",")
124 119

  
120
#list all files to mosaic for a list of day
121
lf_mosaic <- lapply(1:length(day_to_mosaic),FUN=function(i){list.files(path=file.path(in_dir_tiles),    
122
           pattern=paste(".*.",day_to_mosaic[i],".*.tif$",sep=""),full.names=T)})
123
       
125 124
##################### PART 2: produce the mosaic ##################
126 125

  
127 126
##########################
128 127
#### First generate rmse images for each date and tile for the region
129 128

  
130
lf <- lf_mosaic1 #list of files to mosaic for date 1, there a 28 files for reg4, South America
129
#lf <- lf_mosaic1 #list of files to mosaic for date 1, there a 28 files for reg4, South America
130
lf <- lf_mosaic #list of files to mosaic for date 1, there a 28 files for reg4, South America
131 131

  
132 132
#tb <- list_param$tb #fitting or validation table with all days
133 133
#metric_name <- "rmse" #RMSE, MAE etc.
......
140 140
out_dir_str <- out_dir
141 141
out_suffix_str <- out_suffix
142 142

  
143
#Improve by adding multicores option
143 144
list_param_accuracy_metric_raster <- list(lf,tb,metric_name,pred_mod_name,y_var_name,interpolation_method,
144 145
                    days_to_process,NA_flag_val,file_format,out_dir_str,out_suffix_str) 
145

  
146 146
names(list_param_accuracy_metric_raster) <- c("lf","tb","metric_name","pred_mod_name","y_var_name","interpolation_method",
147 147
                       "days_to_process","NA_flag_val","file_format","out_dir_str","out_suffix_str") 
148
list_raster_created_obj <- lapply(1:length(day_to_mosaic),FUN=create_accuracy_metric_raster,
149
                                  list_param=list_param_accuracy_metric_raster)
148 150
#debug(create_accuracy_metric_raster)
149
raster_created_obj <- create_accuracy_metric_raster(1, list_param_accuracy_metric_raster)
151
#list_raster_created_obj <- lapply(1:1,FUN=create_accuracy_metric_raster,
152
#                                  list_param=list_param_accuracy_metric_raster)
153

  
154
#raster_created_obj <- create_accuracy_metric_raster(1, list_param_accuracy_metric_raster)
150 155

  
151 156
#Extract list of files for rmse and date 1 (19920101), there should be 28 raster images
152
lf_accuracy_raster <- unlist(raster_created_obj$list_raster_name) 
157
lf_accuracy_raster <- lapply(1:length(list_raster_created_obj),FUN=function(i){unlist(list_raster_created_obj[[i]]$list_raster_name)}) 
153 158

  
154 159
#Plot as quick check
155
r1 <- raster(lf_mosaic1[1]) 
160
r1 <- raster(lf_mosaic[[1]][1]) 
156 161
#r2 <- raster(lf_mosaic2[2]) 
157 162

  
158 163
plot(r1)
159 164
#plot(r2)
160
r1_ac <- raster(lf_accuracy_raster[1]) 
165
r1_ac <- raster(lf_accuracy_raster[[1]][1]) 
161 166
plot(r1_ac)
162 167

  
163 168
#################################
164 169
#### Second mosaic tiles for the variable and accuracy metrid
165 170

  
166

  
167 171
#methods availbable:use_sine_weights,use_edge,use_linear_weights
168 172
#only use edge method for now
169 173
#loop to dates..., make this a function...
......
171 175
for(i in 1:length(day_to_mosaic)){
172 176
  
173 177
  mosaic_method <- "use_edge_weights" #this is distance from edge
174
  out_suffix_str <- paste(interpolation_method,y_var_name,day_to_mosaic[i],out_suffix,sep="_")
178
  out_suffix_tmp <- paste(interpolation_method,y_var_name,day_to_mosaic[i],out_suffix,sep="_")
175 179
  #debug(mosaicFiles)
176 180
  #can also loop through methods!!!
177 181
  python_bin <- "/usr/bin/" #python gdal bin, this may change on NEX!
178
  mosaic_edge_obj_prediction <- mosaicFiles(lf_mosaic1,
182
  mosaic_edge_obj_prediction <- mosaicFiles(lf_mosaic[[i]],
179 183
                                        mosaic_method="use_edge_weights",
180 184
                                        num_cores=num_cores,
181 185
                                        r_mask_raster_name=infile_mask,
182 186
                                        python_bin=python_bin,
183 187
                                        df_points=NULL,NA_flag=NA_flag_val,
184
                                        file_format=file_format,out_suffix=out_suffix_str,
188
                                        file_format=file_format,out_suffix=out_suffix_tmp,
185 189
                                        out_dir=out_dir)
186 190
  
187 191
  mosaic_method <- "use_edge_weights" #this is distance from edge
188
  out_suffix_str <- paste(interpolation_method,metric_name,day_to_mosaic[i],out_suffix,sep="_")
192
  out_suffix_tmp <- paste(interpolation_method,metric_name,day_to_mosaic[i],out_suffix,sep="_")
189 193

  
190 194
  #debug(mosaicFiles)
191 195
  #can also loop through methods!!!
192
  mosaic_edge_obj_accuracy <- mosaicFiles(lf_accuracy_raster,
196
  mosaic_edge_obj_accuracy <- mosaicFiles(lf_accuracy_raster[[i]],
193 197
                                        mosaic_method="use_edge_weights",
194 198
                                        num_cores=num_cores,
195 199
                                        r_mask_raster_name=infile_mask,
196 200
                                        python_bin=python_bin,
197 201
                                        df_points=NULL,NA_flag=NA_flag_val,
198
                                        file_format=file_format,out_suffix=out_suffix_str,
202
                                        file_format=file_format,out_suffix=out_suffix_tmp,
199 203
                                        out_dir=out_dir)
200 204
  
201 205
  list_mosaic_obj[[i]] <- list(prediction=mosaic_edge_obj_prediction,accuracy=mosaic_edge_obj_accuracy)

Also available in: Unified diff