Revision 98deadc2
Added by Benoit Parmentier over 9 years ago
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: 06/16/2015
|
|
8 |
#MODIFIED ON: 06/20/2015
|
|
9 | 9 |
#Version: 4 |
10 | 10 |
#PROJECT: Environmental Layers project |
11 | 11 |
#COMMENTS: analyses run for reg5 for test of mosaicing using 1500x4500km and other tiles |
12 | 12 |
#TODO: |
13 |
#1) Split functions and master script |
|
14 |
#2) Make this is a script/function callable from the shell/bash |
|
15 |
#3) Check image format for tif |
|
16 |
#4) generalize to run dates and region fast |
|
13 |
#1) Make this is a script/function callable from the shell/bash |
|
14 |
#2) generalize to run dates and region fast |
|
17 | 15 |
|
18 | 16 |
################################################################################################# |
19 | 17 |
|
... | ... | |
189 | 187 |
save(mosaic_unweighted_20100831_obj,file=file.path(out_dir,paste(mosaic_method,"_","mosaic_obj_", |
190 | 188 |
"20100831_",out_suffix,".RData",sep=""))) |
191 | 189 |
|
192 |
#r2_unweighted <-raster(mosaic_unweighted_20100901_obj$mean_mosaic) |
|
193 |
#r2_edge <-raster(mosaic_edge_20100901_obj$mean_mosaic) |
|
194 |
|
|
195 |
#r1_unweighted <-raster(mosaic_unweighted_20100831_obj$mean_mosaic) |
|
196 |
#r1_edge <-raster(mosaic_edge_20100831_obj$mean_mosaic) |
|
197 |
#plot(r1_edge) |
|
198 |
|
|
199 | 190 |
##################### |
200 | 191 |
###### PART 2: Analysis and figures for the outputs of mosaic function ##### |
201 | 192 |
|
... | ... | |
219 | 210 |
#plot_mosaic(lf_mean_mosaic1[1],method="edge",out_suffix="20100831") |
220 | 211 |
list_param_plot_mosaic <- list(lf_mosaic=lf_mean_mosaic1,method=c("edge","unweighted"),out_suffix=c("20100831","20100831")) |
221 | 212 |
#l_png_files <- lapply(1:length(lf_mean_mosaic1),FUN=plot_mosaic,list_param= list_param_plot_mosaic) |
213 |
num_cores <- 2 |
|
222 | 214 |
l_png_files <- mclapply(1:length(lf_mean_mosaic1),FUN=plot_mosaic,list_param= list_param_plot_mosaic, |
223 | 215 |
mc.preschedule=FALSE,mc.cores = num_cores) |
224 | 216 |
|
225 |
plot_mosaic <- function(i,list_param){ |
|
226 |
#Plot for mosaic list assess via slope as well |
|
227 |
#Inputs: |
|
228 |
# |
|
229 |
|
|
230 |
method_str <- list_param$method[i] |
|
231 |
f_mosaic <- list_param$lf_mosaic[i] |
|
232 |
out_suffix_str <- list_param$out_suffix[i] |
|
233 |
|
|
234 |
r_mosaic <- raster(f_mosaic) |
|
235 |
|
|
236 |
r_mosaic_terrain <- terrain(r_mosaic,opt=c("slope","aspect"),unit="degrees") |
|
237 |
|
|
238 |
res_pix <- 1200 |
|
239 |
col_mfrow <- 1 |
|
240 |
row_mfrow <- 0.8 |
|
241 |
|
|
242 |
out_file1 <- paste("Figure2_mosaic_mean_",method_str,"_",out_suffix_str,".png",sep="") |
|
243 |
png(filename= out_file1, |
|
244 |
width=col_mfrow*res_pix,height=row_mfrow*res_pix) |
|
245 |
|
|
246 |
plot(r_mosaic,main=paste("mosaic mean ",method_str,sep="")) |
|
247 |
|
|
248 |
dev.off() |
|
249 |
|
|
250 |
#### plot terrain to emphasize possible edges.. |
|
251 |
res_pix <- 1200 |
|
252 |
col_mfrow <- 1 |
|
253 |
row_mfrow <- 0.8 |
|
254 |
|
|
255 |
out_file2 <- paste("Figure2_slope_mean_",method_str,"_",out_suffix_str,".png",sep="") |
|
256 |
png(filename= out_file2, |
|
257 |
width=col_mfrow*res_pix,height=row_mfrow*res_pix) |
|
258 |
|
|
259 |
plot(r_mosaic_terrain,y=1,main=paste("slope mosaic mean ",method_str,sep="")) |
|
260 |
|
|
261 |
dev.off() |
|
262 |
|
|
263 |
out_file3 <- paste("Figure2_aspect_mean_",method_str,"_",out_suffix_str,".png",sep="") |
|
264 |
png(filename= out_file3, |
|
265 |
width=col_mfrow*res_pix,height=row_mfrow*res_pix) |
|
266 |
|
|
267 |
plot(r_mosaic_terrain,y=2,main=paste("aspect mean ",method_str,sep="")) |
|
268 |
|
|
269 |
dev.off() |
|
270 |
|
|
271 |
l_out_files <- list(out_file1,out_file2,out_file3) |
|
272 |
return(l_out_files) |
|
273 |
} |
|
274 |
|
|
275 | 217 |
#################### |
276 | 218 |
#### Now difference figures... |
277 |
r_m_edge_weighted_mean <- raster(list_mosaiced_files2[1])#edge |
|
278 |
r_m_linear_weighted_mean <- raster(list_mosaiced_files2[2])#linear |
|
279 |
r_m_sine_weighted_mean <- raster(list_mosaiced_files2[3])#sine |
|
280 |
r_m_unweighted_mean <- raster(list_mosaiced_files2[4])#unweighted |
|
281 | 219 |
|
282 |
r_diff_linear_sine_weighted_mean <- r_m_linear_weighted_mean - r_m_sine_weighted_mean |
|
220 |
lf_obj2 <- list.files(path=out_dir,pattern="*edge_.*.RData") |
|
221 |
lf_obj1 <- list.files(path=out_dir,pattern="*unweighted.*.RData") |
|
283 | 222 |
|
284 |
res_pix <- 1200 |
|
285 |
col_mfrow <- 1 |
|
286 |
row_mfrow <- 0.8 |
|
223 |
lf1 <- unlist(lapply(lf_mosaic_obj2,function(x){load_obj(x)[["mean_mosaic"]]})) |
|
224 |
lf2 <- unlist(lapply(lf_mosaic_obj1,function(x){load_obj(x)[["mean_mosaic"]]})) |
|
287 | 225 |
|
288 |
png(filename=paste("Figure2_diff_linear_sine_weigthed_mean_for_region_",region_name,"_",out_suffix,".png",sep=""), |
|
289 |
width=col_mfrow*res_pix,height=row_mfrow*res_pix) |
|
290 |
|
|
291 |
plot(r_diff_linear_sine_weighted_mean) |
|
292 |
|
|
293 |
dev.off() |
|
294 |
|
|
295 |
r_diff_linear_edge_weighted_mean <- r_m_linear_weighted_mean - r_m_edge_weighted_mean |
|
296 |
|
|
297 |
png(filename=paste("Figure2_diff_linear_edge_weigthed_mean_for_region_",region_name,"_",out_suffix,".png",sep=""), |
|
298 |
width=col_mfrow*res_pix,height=row_mfrow*res_pix) |
|
299 |
|
|
300 |
plot(r_diff_linear_edge_weighted_mean) |
|
301 |
|
|
302 |
dev.off() |
|
303 |
|
|
304 |
|
|
305 |
#r_diff_linear_edge_weighted_mean <- r_m_linear_weighted_mean - r_m_edge_weighted_mean |
|
306 |
r_diff_edge_sine_weighted_mean <- r_m_edge_weighted_mean - r_m_sine_weighted_mean |
|
226 |
list_param_plot_diff <- list(lf1=lf1,lf2=lf2,out_suffix=c("20100831","20100901")) |
|
227 |
#l_png_files <- lapply(1:length(lf_mean_mosaic1),FUN=plot_mosaic,list_param= list_param_plot_mosaic) |
|
228 |
num_cores <- 2 |
|
307 | 229 |
|
308 |
png(filename=paste("Figure2_diff_edge_sine_weigthed_mean_for_region_",region_name,"_",out_suffix,".png",sep=""),
|
|
309 |
width=col_mfrow*res_pix,height=row_mfrow*res_pix)
|
|
230 |
#debug(plot_diff_raster)
|
|
231 |
#plot_diff_raster(1,list_param=list_param_plot_diff)
|
|
310 | 232 |
|
311 |
plot(r_diff_edge_sine_weighted_mean) |
|
233 |
num_cores <- 2 |
|
234 |
l_diff_png_files <- mclapply(1:length(lf1),FUN=plot_diff_raster,list_param= list_param_plot_diff, |
|
235 |
mc.preschedule=FALSE,mc.cores = num_cores) |
|
312 | 236 |
|
313 |
dev.off() |
|
314 | 237 |
|
315 | 238 |
############### |
316 | 239 |
##### Now compare to unweighted values |
317 | 240 |
|
318 |
r_diff_unweighted_linear_weighted_mean <- r_m_mean - r_m_linear_weighted_mean |
|
319 |
r_diff_unweighted_sine_weighted_mean <- r_m_mean - r_m_sine_weighted_mean |
|
320 |
r_diff_unweighted_edge_weighted_mean <- r_m_mean - r_m_edge_weighted_mean |
|
321 |
|
|
322 |
png(filename=paste("Figure2_diff_unweighted_edge_weigthed_mean_for_region_",region_name,"_",out_suffix,".png",sep=""), |
|
323 |
width=col_mfrow*res_pix,height=row_mfrow*res_pix) |
|
324 |
|
|
325 |
plot(r_diff_unweighted_edge_weighted_mean) |
|
326 |
|
|
327 |
dev.off() |
|
328 |
|
|
329 |
png(filename=paste("Figure2_diff_unweighted_linear_weighted_mean_for_region_",region_name,"_",out_suffix,".png",sep=""), |
|
330 |
width=col_mfrow*res_pix,height=row_mfrow*res_pix) |
|
331 |
|
|
332 |
plot(r_diff_unweighted_linear_weighted_mean) |
|
333 |
|
|
334 |
dev.off() |
|
335 |
|
|
336 |
png(filename=paste("Figure2_diff_unweighted_sine_weigthed_mean_for_region_",region_name,"_",out_suffix,".png",sep=""), |
|
337 |
width=col_mfrow*res_pix,height=row_mfrow*res_pix) |
|
338 |
|
|
339 |
plot(r_diff_unweighted_sine_weighted_mean) |
|
340 |
|
|
341 |
dev.off() |
|
342 | 241 |
|
343 | 242 |
##################### END OF SCRIPT ###################### |
344 | 243 |
|
Also available in: Unified diff
plot function figure in mosaic test script