Commit 25e93446 authored by jbracher's avatar jbracher
Browse files

Prevent creation of plot_data if ensemble is not created yet (otherwise...

Prevent creation of plot_data if ensemble is not created yet (otherwise problem with default of plotting app)
parent 31730518
......@@ -15,66 +15,72 @@ for(lab in labels_weeks){
# identify files
fls <- list.files(paste0("../", lab))
# run through files and read in:
result <- NULL
for(i in seq_along(fls)){
dat_temp <- read.csv(paste0("../", lab, "/", fls[i]),
colClasses = c(forecast_date = "Date"))
# remove row numbers if necessary:
dat_temp$X <- NULL
# add model name:
dat_temp$model <- extract_name_from_file(fls[i])
# add column for target end date / time:
dat_temp$target_end_date <- NA
# re-format forecast time:
dat_temp$forecast_date <- as.POSIXlt(dat_temp$forecast_date, "GMT") + 24*60*60 - 60
# handle DAX forecasts:
subs_DAX <- subset(dat_temp, target == "DAX")
# generate target end date / time:
days_numeric <- as.numeric(gsub(" day", "", subs_DAX$horizon))
subs_DAX$target_end_date <- subs_DAX$forecast_date + 60 + days_numeric*24*60*60 - 6.5*60*60
if(any(grepl("ensemble", fls))){
# run through files and read in:
result <- NULL
for(i in seq_along(fls)){
dat_temp <- read.csv(paste0("../", lab, "/", fls[i]),
colClasses = c(forecast_date = "Date"))
# remove row numbers if necessary:
dat_temp$X <- NULL
# add model name:
dat_temp$model <- extract_name_from_file(fls[i])
# add column for target end date / time:
dat_temp$target_end_date <- NA
# re-format forecast time:
dat_temp$forecast_date <- as.POSIXlt(dat_temp$forecast_date, "GMT") + 24*60*60 - 60
# handle DAX forecasts:
subs_DAX <- subset(dat_temp, target == "DAX")
# generate target end date / time:
days_numeric <- as.numeric(gsub(" day", "", subs_DAX$horizon))
subs_DAX$target_end_date <- subs_DAX$forecast_date + 60 + days_numeric*24*60*60 - 6.5*60*60
# handle weather forecasts:
subs_weather <- subset(dat_temp, target %in% c("wind", "temperature"))
# generate target end date / time:
hours_numeric <- as.numeric(gsub(" hour", "", subs_weather$horizon))
subs_weather$target_end_date <- subs_weather$forecast_date + 60 + hours_numeric*60*60 - 24*60*60
# put back together:
dat_temp <- rbind(subs_DAX, subs_weather)
# add to data.frame:
if(!is.null(result)){
result <- rbind(result, dat_temp)
}else{
result <- dat_temp
}
}
# handle weather forecasts:
subs_weather <- subset(dat_temp, target %in% c("wind", "temperature"))
# generate target end date / time:
hours_numeric <- as.numeric(gsub(" hour", "", subs_weather$horizon))
subs_weather$target_end_date <- subs_weather$forecast_date + 60 + hours_numeric*60*60 - 24*60*60
# get evaluation data:
dat_eval <- NULL
try({
dat_eval <- read.csv(paste0("../evaluation/evaluation_", lab, ".csv"))
}, silent = TRUE)
# put back together:
dat_temp <- rbind(subs_DAX, subs_weather)
# add to data.frame:
# write out if non-empty
if(!is.null(result)){
result <- rbind(result, dat_temp)
}else{
result <- dat_temp
# add evaluation data:
if(!is.null(dat_eval)){
dat_eval <- dat_eval[, c("target", "model", "horizon", "mean_qscore", "ae")]
result <- merge(result, dat_eval, by = c("model", "target", "horizon"), all.x = TRUE)
}else{
result$mean_qscore <- result$ae <- NA
}
# result <- subset(result, target == "DAX" & horizon %in% paste(c(1, 2, 5, 6, 7), "day"))
forecast_date <- as.Date(result$forecast_date[1])
write.csv(result, file = paste0("../ptsfc_viz/plot_data/plot_data_", forecast_date, ".csv"), row.names = FALSE)
}
}else{
warning(paste("Not processing visualization data for ", lab, "as ensemble not created yet."))
}
# get evaluation data:
dat_eval <- NULL
try({
dat_eval <- read.csv(paste0("../evaluation/evaluation_", lab, ".csv"))
}, silent = TRUE)
# write out if non-empty
if(!is.null(result)){
# add evaluation data:
if(!is.null(dat_eval)){
dat_eval <- dat_eval[, c("target", "model", "horizon", "mean_qscore", "ae")]
result <- merge(result, dat_eval, by = c("model", "target", "horizon"), all.x = TRUE)
}else{
result$mean_qscore <- result$ae <- NA
}
# result <- subset(result, target == "DAX" & horizon %in% paste(c(1, 2, 5, 6, 7), "day"))
forecast_date <- as.Date(result$forecast_date[1])
write.csv(result, file = paste0("../ptsfc_viz/plot_data/plot_data_", forecast_date, ".csv"), row.names = FALSE)
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment