+
+#' @title Plot relative conditional variability / absolute variability
+#'
+#' @description Draw the relative conditional variability / absolute variability based on on
+#' filaments obtained by \code{computeFilaments}
+#'
+#' @param data Object return by \code{getData}
+#' @param indices Indices as output by \code{computeFilaments}
+#'
+#' @export
+plotRelativeVariability = function(data, indices, ...)
+{
+ #plot left / right separated by vertical line brown dotted
+ #median of 3 runs for random length(indices) series
+ ref_series = t( sapply(indices, function(i) {
+ c( data$getSerie(i), data$getSerie(i+1) )
+ }) )
+ ref_var = apply(ref_series, 2, sd)
+
+ # Determine indices of no-NAs days followed by no-NAs tomorrows
+ first_day = ifelse(length(data$getCenteredSerie(1))<length(ref_series[1,]), 2, 1)
+ fdays_indices = c()
+ for (i in first_day:(tail(indices,1)-1))
+ {
+ if ( !any(is.na(data$getSerie(i)) | is.na(data$getSerie(i+1))) )
+ fdays_indices = c(fdays_indices, i)
+ }
+
+ # TODO: 3 == magic number
+ random_var = matrix(nrow=3, ncol=48)
+ for (mc in seq_len(nrow(random_var)))
+ {
+ random_indices = sample(fdays_indices, length(indices))
+ random_series = t( sapply(random_indices, function(i) {
+ c( data$getSerie(i), data$getSerie(i+1) )
+ }) )
+ random_var[mc,] = apply(random_series, 2, sd)
+ }
+ random_var = apply(random_var, 2, median)
+
+ yrange = range(ref_var, random_var)
+ par(mar=c(4.7,5,1,1), cex.axis=1.5, cex.lab=1.5)
+ plot(ref_var, type="l", col=1, lwd=3, ylim=yrange, xlab="Temps (heures)", ylab="Écart-type")
+ par(new=TRUE)
+ plot(random_var, type="l", col=2, lwd=3, ylim=yrange, xlab="", ylab="")
+ abline(v=24, lty=2, col=colors()[56])
+}