Commit 6b227250 authored by jbracher's avatar jbracher
Browse files

Deleting old versions.

parent 0a7c80e4
# process data for visualization
# to be run from ptsfc_viz
# setwd("/home/johannes/Documents/Teaching/Ensemble_Seminar/ptsfc_results/ptsfc_viz")
source("../code/functions.R")
library(lubridate)
# get folder names where forecasts are stored
labels_weeks <- list.dirs("..", full.names = FALSE)
labels_weeks <- labels_weeks[grepl("202", labels_weeks)]
# run through folders:
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
# 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
}
}
# 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("plot_data/plot_data_", forecast_date, ".csv"), row.names = FALSE)
}
}
setwd("/home/johannes/Documents/Teaching/Ensemble_Seminar/ptsfc_results/ptsfc_viz/")
library(rdwd)
## temperature data
dwd_url <- selectDWD(
name = "Berlin-Tempelhof",
res = "hourly",
per = "recent",
var = "air_temperature"
)
obs_data_t2m <- dataDWD(dwd_url, force = TRUE, overwrite = TRUE)
obs_data_t2m_ts <- obs_data_t2m[,c("MESS_DATUM", "TT_TU")]
names(obs_data_t2m_ts) <- c("time", "value")
obs_data_t2m_ts <- subset(obs_data_t2m_ts,
grepl("00:00:00", as.character(obs_data_t2m_ts$time)) |
grepl("12:00:00", as.character(obs_data_t2m_ts$time)))
obs_data_t2m_ts <- tail(obs_data_t2m_ts, 300)
plot(obs_data_t2m_ts$time, obs_data_t2m_ts$Observation, type = "l")
write.csv(obs_data_t2m_ts, file = "plot_data/t2m.csv", row.names = FALSE)
## wind data
dwd_url <- selectDWD(
name = "Berlin-Tempelhof",
res = "hourly",
per = "recent",
var = "wind"
)
obs_data_wind <- dataDWD(dwd_url, force = TRUE, overwrite = TRUE)
obs_data_wind_ts <- obs_data_wind[,c("MESS_DATUM", "F")]
names(obs_data_wind_ts) <- c("time", "value")
obs_data_wind_ts$value <- obs_data_wind_ts$value*3.6
obs_data_wind_ts <- subset(obs_data_wind_ts,
grepl("00:00:00", as.character(obs_data_wind_ts$time)) |
grepl("12:00:00", as.character(obs_data_wind_ts$time)))
obs_data_wind_ts <- tail(obs_data_wind_ts, 300)
write.csv(obs_data_wind_ts, file = "plot_data/wind.csv", row.names = FALSE)
plot(obs_data_wind_ts$time, obs_data_wind_ts$value, type = "l")
Supports Markdown
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