preprocess_datasets <- function(recipe, data) {
  # Remove extra dimensions from the input datasets and add any missing ones,
  # so that the inputs are uniformized before being transformed to s2dv_cubes.
  for (element in names(data)) {
    dimension_names <- names(dim(data[[element]]))
    # These auxiliary dimension used to load the data with Start() are removed
    EXTRA_DIMS <- c("var_dir", "dcpp", "table", "grid", "version")
    dims_to_remove <- dimension_names[dimension_names %in% EXTRA_DIMS]
    if (length(dims_to_remove) > 0) {
      indices_to_remove <- rep(list(1), length.out = length(dims_to_remove))
      data[[element]] <- Subset(x = data[[element]],
                                along = dims_to_remove,
                                indices = indices_to_remove,
                                drop = 'selected')
    }
    # Add sday and sweek if missing
    if (!("sday" %in% dimension_names)) {
      dim(data[[element]]) <- c(dim(data[[element]]), sday = 1)
    }
    if (!("sweek" %in% dimension_names)) {
      dim(data[[element]]) <- c(dim(data[[element]]), sweek = 1)
    }
  }
  # Add 'ensemble' dimension to obs
  dim(data$obs) <- c(dim(data$obs), ensemble = 1)
  return(data)
}
