Revision ced27a42
Added by Benoit Parmentier over 8 years ago
climate/research/oregon/interpolation/NASA2016_conference_temperature_predictions.R | ||
---|---|---|
198 | 198 |
#python_bin <- "/nobackupp6/aguzman4/climateLayers/sharedModules2/bin" #PARAM 30 |
199 | 199 |
python_bin <- "/usr/bin" #PARAM 30 |
200 | 200 |
|
201 |
day_start <- "19990101" #PARAM 12 arg 12
|
|
202 |
day_end <- "19990103" #PARAM 13 arg 13
|
|
201 |
day_start <- "19840101" #PARAM 12 arg 12
|
|
202 |
day_end <- "20021231" #PARAM 13 arg 13
|
|
203 | 203 |
|
204 | 204 |
#infile_mask <- "/nobackupp8/bparmen1/NEX_data/regions_input_files/r_mask_LST_reg4.tif" |
205 | 205 |
infile_mask <- "/data/project/layers/commons/NEX_data/regions_input_files/r_mask_LST_reg4.tif" |
... | ... | |
220 | 220 |
#l_dates <- c("19990101","19990102","19990103","19990701","19990702","19990703") |
221 | 221 |
l_dates <- c("19920101","19920102","19920103","19920701","19920702","19990703") |
222 | 222 |
|
223 |
df_points_extracted_fname <- "/data/project/layers/commons/NEX_data/climateLayers/out/reg4/mosaic/int_mosaics/data_points_extracted.txt" |
|
224 |
|
|
223 | 225 |
##################### START SCRIPT ################# |
224 | 226 |
|
225 | 227 |
####### PART 1: Read in data ######## |
... | ... | |
270 | 272 |
#paste(raster_name[1:7],collapse="_") |
271 | 273 |
#add filename option later |
272 | 274 |
|
273 |
for (i in 1:length(nlayers(r_mosaic_scaled))){ |
|
275 |
NA_flag_val_mosaic <- -3399999901438340239948148078125514752.000 |
|
276 |
|
|
277 |
list_param_plot_raster_mosaic <- list(l_dates,r_mosaic_scaled,NA_flag_val_mosaic,out_dir,out_suffix, |
|
278 |
region_name,variable_name) |
|
279 |
names(list_param_plot_raster_mosaic) <- c("l_dates","r_mosaic_scaled","NA_flag_val_mosaic","out_dir","out_suffix", |
|
280 |
"region_name","variable_name") |
|
281 |
|
|
282 |
lf_mosaic_plot_fig <- mclapply(1:length(lf_mosaic_scaled),FUN=plot_raster_mosaic,list_param=list_param_plot_raster_mosaic,mc.preschedule=FALSE,mc.cores = num_cores) |
|
283 |
|
|
284 |
plot_raster_mosaic <- function(i,list_param){ |
|
285 |
#Function to plot mosaic for poster |
|
286 |
# |
|
287 |
l_dates <- list_param$l_dates |
|
288 |
r_mosaiced_scaled <- list_param$r_mosaiced_scaled |
|
289 |
NA_flag_val <- list_param$NA_flag_val |
|
290 |
out_dir <- list_param$out_dir |
|
291 |
out_suffix <- list_param$out_suffix |
|
292 |
region_name <- list_param$region_name |
|
293 |
variable_name <- list_param$variable_name |
|
294 |
|
|
295 |
#for (i in 1:length(nlayers(r_mosaic_scaled))){ |
|
274 | 296 |
|
275 | 297 |
date_proc <- l_dates[i] |
276 | 298 |
r_pred <- subset(r_mosaic_scaled,i) |
277 |
NAvalue(r_pred)<- -3399999901438340239948148078125514752.000
|
|
299 |
NAvalue(r_pred)<- NA_flag_val
|
|
278 | 300 |
|
279 | 301 |
date_proc <- l_dates[i] |
280 | 302 |
date_val <- as.Date(strptime(date_proc,"%Y%m%d")) |
... | ... | |
283 | 305 |
year_str <- format(date_val, "%Y") ## Year with century |
284 | 306 |
day_str <- as.numeric(format(date_val, "%d")) ## numeric month |
285 | 307 |
date_str <- paste(month_str," ",day_str,", ",year_str,sep="") |
286 |
|
|
308 |
|
|
287 | 309 |
res_pix <- 1200 |
288 | 310 |
#res_pix <- 480 |
289 | 311 |
col_mfrow <- 1 |
... | ... | |
300 | 322 |
#legend.args=list(text='dNBR', side=4, line=2.49, cex=1.6)) |
301 | 323 |
dev.off() |
302 | 324 |
|
325 |
return(png_filename) |
|
303 | 326 |
} |
304 | 327 |
|
305 |
|
|
328 |
############### PART2: temporal profile ############# |
|
306 | 329 |
#### Extract time series |
307 |
|
|
330 |
### |
|
308 | 331 |
#-65,-22 |
309 | 332 |
|
333 |
df_points <- read.table(df_points_extracted_fname,sep=",") |
|
310 | 334 |
df_centroids <- read.table(df_centroids_fname,sep=",") |
335 |
|
|
311 | 336 |
coordinates(df_centroids)<- c("long","lat") |
312 | 337 |
proj4string(df_centroids) <- CRS_locs_WGS84 |
313 | 338 |
|
314 |
extract(df_centroids,) |
|
339 |
lf_mosaic_list <- list.files(path=in_dir_mosaic,pattern="*.tif") |
|
340 |
#r_mosaic_ts <- stack(lf_mosaic_list) |
|
341 |
#df_centroids <- extract(df_centroids,r_mosaic_ts) |
|
342 |
|
|
343 |
df_points$files <- lf_mosaic_list |
|
344 |
|
|
345 |
extract_date <- function(i,x){ |
|
346 |
y <- unlist(strsplit(x[[i]],"_")) |
|
347 |
date_str <- y[length(y)-2] |
|
348 |
} |
|
349 |
#debug(extract_date) |
|
350 |
#test <- (extract_date(1,lf_mosaic_list)) |
|
351 |
|
|
352 |
list_dates_produced <- unlist(mclapply(1:length(lf_mosaic_list),FUN=extract_date,mc.preschedule=FALSE,mc.cores = num_cores)) |
|
353 |
#list_dates_produced <- mclapply(1:11,FUN=extract_date,mc.preschedule=FALSE,x=lf_mosaic_list,mc.cores = num_cores) |
|
354 |
|
|
355 |
|
|
356 |
list_dates_produced_date_val <- as.Date(strptime(list_dates_produced,"%Y%m%d")) |
|
357 |
month_str <- format(list_dates_produced_date_val, "%b") ## Month, char, abbreviated |
|
358 |
year_str <- format(list_dates_produced_date_val, "%Y") ## Year with century |
|
359 |
day_str <- as.numeric(format(list_dates_produced_date_val, "%d")) ## numeric month |
|
360 |
|
|
361 |
df_points$date <- list_dates_produced_date_val |
|
362 |
df_points$month <- month_str |
|
363 |
df_points$year <- year_str |
|
364 |
df_points$day <- day_str |
|
365 |
|
|
366 |
#data_pixel <- data_df[id_selected,] |
|
367 |
#data_pixel$rainfall <- as.numeric(data_pixel$rainfall) |
|
368 |
#d_z_tmp <-zoo(data_pixel$rainfall,as.Date(data_pixel$date)) |
|
369 |
#names(d_z_tmp)<- "rainfall" |
|
370 |
#data_pixel <- as.data.frame(data_pixel) |
|
371 |
#d_z_tmp2 <- zoo(data_pixel[[var_name]],as.Date(data_pixel$date)) |
|
372 |
|
|
373 |
#start_date <-input$dates[1] |
|
374 |
#end_date <-input$dates[2] |
|
375 |
|
|
376 |
#d_z <- window(d_z_tmp,start=start_date,end=end_date) |
|
377 |
#d_z2 <- window(d_z_tmp2,start=start_date,end=end_date) |
|
378 |
#df2 <- as.data.frame(d_z2) |
|
379 |
#names(df2)<- var_name |
|
315 | 380 |
|
316 |
raster() |
|
317 | 381 |
|
318 | 382 |
############################ END OF SCRIPT ################################## |
Also available in: Unified diff
extracting temporal profiles for centroids of tiles in raster stack