Revision 1867929d
Added by Benoit Parmentier about 8 years ago
climate/research/oregon/interpolation/global_product_assessment_part2_functions.R | ||
---|---|---|
5 | 5 |
#The file contains functions to genrate figures and animation (movie). |
6 | 6 |
#AUTHOR: Benoit Parmentier |
7 | 7 |
#CREATED ON: 10/03/2016 |
8 |
#MODIFIED ON: 10/10/2016
|
|
8 |
#MODIFIED ON: 10/19/2016
|
|
9 | 9 |
#Version: 2 |
10 | 10 |
#PROJECT: Environmental Layers project |
11 | 11 |
#COMMENTS: |
... | ... | |
251 | 251 |
return(missing_dates_obj) |
252 | 252 |
} |
253 | 253 |
|
254 |
check_missing <- function(lf, pattern_str=NULL,in_dir=".",date_start="1984101",date_end="20141231",item_no=13,out_suffix=""){ |
|
255 |
#Function to check for missing files such as mosaics or predictions for tiles etc. |
|
256 |
#The function assumes the name of the files contain "_". |
|
257 |
#INPUTS: |
|
258 |
#lf |
|
259 |
#pattern_str |
|
260 |
#in_dir |
|
261 |
#date_start |
|
262 |
#date_end |
|
263 |
#item_no |
|
264 |
#out_suffix |
|
265 |
#OUTPUTS |
|
266 |
# |
|
267 |
# |
|
268 |
|
|
269 |
##### Start script ##### |
|
270 |
|
|
271 |
out_dir <- in_dir |
|
272 |
|
|
273 |
list_dates_produced <- unlist(mclapply(1:length(lf), |
|
274 |
FUN = extract_date, |
|
275 |
x = lf, |
|
276 |
item_no = item_no, |
|
277 |
mc.preschedule = FALSE, |
|
278 |
mc.cores = num_cores)) |
|
279 |
|
|
280 |
list_dates_produced_date_val <- as.Date(strptime(list_dates_produced, "%Y%m%d")) |
|
281 |
month_str <- format(list_dates_produced_date_val, "%b") ## Month, char, abbreviated |
|
282 |
year_str <- format(list_dates_produced_date_val, "%Y") ## Year with century |
|
283 |
day_str <- as.numeric(format(list_dates_produced_date_val, "%d")) ## numeric month |
|
284 |
df_files <- data.frame(lf = basename(lf), |
|
285 |
date = list_dates_produced_date_val, |
|
286 |
month_str = month_str, |
|
287 |
year = year_str, |
|
288 |
day = day_str, |
|
289 |
dir = dirname(lf)) |
|
290 |
|
|
291 |
df_files_fname <- file.path(out_dir, paste0("df_files_", out_suffix, ".txt")) |
|
292 |
write.table(df_files,file = df_files_fname,sep = ",",row.names = F) |
|
293 |
|
|
294 |
#undebug(finding_missing_dates ) |
|
295 |
missing_dates_obj <- finding_missing_dates (date_start,date_end,list_dates_produced_date_val) |
|
296 |
|
|
297 |
df_time_series <- missing_dates_obj$df_dates |
|
298 |
df_time_series$date <- as.character(df_time_series$date) |
|
299 |
df_files$date <- as.character(df_files$date) |
|
300 |
|
|
301 |
df_time_series <- merge(df_time_series,df_files,by="date",all=T) #outer join to keep missing dates |
|
302 |
|
|
303 |
df_time_series$month_str <- format(as.Date(df_time_series$date), "%b") ## Month, char, abbreviated |
|
304 |
df_time_series$year_str <- format(as.Date(df_time_series$date), "%Y") ## Year with century |
|
305 |
df_time_series$day <- as.numeric(format(as.Date(df_time_series$date), "%d")) ## numeric month |
|
306 |
|
|
307 |
df_time_series_fname <- file.path(out_dir,paste0("df_time_series_",out_suffix,".txt")) #add the name of var later (tmax) |
|
308 |
write.table(df_time_series,file= df_time_series_fname,sep=",",row.names = F) |
|
309 |
|
|
310 |
df_time_series_obj <- list(df_raster_fname,df_time_series_fname,df_time_series) |
|
311 |
names(df_time_series_obj) <- c("df_raster_fname","df_time_series_fname","df_time_series") |
|
312 |
|
|
313 |
## report in text file missing by year and list of dates missing in separate textfile!! |
|
314 |
return(df_time_series_obj) |
|
315 |
} |
|
316 |
|
|
317 |
|
|
254 | 318 |
#create animation from figures: |
255 | 319 |
generate_animation_from_figures_fun <- function(filenames_figures,frame_speed=60,format_file=".gif",out_suffix="",out_dir=".",out_filename_figure_animation=NULL){ |
256 | 320 |
#This function generates an animation given a list of files or textfile. The default format is .gif. |
Also available in: Unified diff
adding function to check missing predictions/mosaics