Visualization improvements. PlotRobinson parameters and forecast ensemble methods
Hi @vagudets,
As previously mentioned, we will need to plot other methods than forecast ensemble mean.
I am already doing so by adding a few lines to the function plot_ensemble_mean.R so instead of:
# Compute ensemble mean
ensemble_mean <- s2dv::MeanDims(fcst$data, 'ensemble')
I added a parameter to the function called method
, which is 'median' by default.
# Compute ensemble mean or other
if (!is.null(method)) {
method <- tolower(method)
}
if (method == 'mean') {
ensemble_mean <- s2dv::MeanDims(fcst$data, 'ensemble')
} else if (method == 'iqr') {
ensemble_mean <- Apply(fcst$data, target_dim = 'ensemble',
fun = function(x) {
IQR(x)})$output1
} else {
ensemble_mean <- Apply(fcst$data, target_dim = 'ensemble',
fun = function(x) {
median(x)})$output1
}
I haven't changed the name of the function or the object ensemble_mean
but it could be an improvement as well.
On the other hand, I needed the lenged to be centered in zero and use the S2S4E color palette. So, I modified the code in line https://earth.bsc.es/gitlab/es/sunset/-/blob/master/modules/Visualization/R/plot_ensemble_mean.R#L80
max_value <- max(abs(var_ens_mean), na.rm = T)
brks <- pretty(c(-1 * max_value, max_value), n = 15, min.n = 8)
For output files and titles, I substituted 'mean' by method, e.g.:
outfile <- paste0(outdir[[var]], "forecast_ensemble_", method,
"-", i_syear)
I also needed to configure the PlotRobinson parameters, so, I added the output_configuration
output_configuration <- output_conf$PlotRobinson$forecast_ensemble_mean
base_args <- list(data = NULL, mask = NULL, dots = NULL,
lon = longitude, lat = latitude,
lon_dim = 'longitude', lat_dim = 'latitude',
target_proj = target_proj, legend = 's2dv',
style = 'point', brks = brks, cols = cols,
bar_extra_margin = c(3.5, 0, 3.5, 0),
point_size = "auto", title_size = 10,
dots_size = 0.2,
width = 8, height = 5,
units = units)
base_args[names(output_configuration)] <- output_configuration
This development, to use the output_size.yml file is also needed in plot_metrics.R
In the case of plot_mostlikely, I removed some lines because my probabilities were already in an array:
REMOVED
if (is.null(probabilities$probs_fcst$prob_b33) ||
is.null(probabilities$probs_fcst$prob_33_to_66) ||
is.null(probabilities$probs_fcst$prob_a66)) {
stop("The forecast tercile probability bins are not present inside ",
"'probabilities', the most likely tercile map cannot be plotted.")
}
probs_fcst <- abind(probabilities$probs_fcst$prob_b33,
probabilities$probs_fcst$prob_33_to_66,
probabilities$probs_fcst$prob_a66,
along = 0)
names(dim(probs_fcst)) <- c("bin",
names(dim(probabilities$probs_fcst$prob_b33)))
ADDED:
probs_fcst <- probabilities$probs_fcst
Maybe we can add a check asking for the object class, if it is a list, the use the previous lines, otherwise look for 'bin' category.
Well, I have a mess in my branch, so, let me know how to proceed to add any of these developments to sunset.
Cheers,
Núria