Skip to content

Checks in CST_ functions

Hi @erifarov and @aho

You can find the script I am working on here: https://earth.bsc.es/gitlab/nperez/Flor/-/blob/master/csindicators/paper/PlotForecastPDF.R

The CST_ functions return a warning that needs to be fixed, in my opinion. Now, I am looking at PeriodAccumulation function but, probably, other functions will have the same checks for the $Dates length.

Warning message:
In CST_PeriodAccumulation(fcst_QM, start = list(21, 4), end = list(21,  :
  Dimensions in 'data' element 'Dates$start' are missed andall data would be used.

It appears when sdate dimension in $data is of length 1 because the comparison length(data$Dates$start) != dim(data$data)[time_dim].

I think there could be the following cases: A) data has sdate dim of length greater than 1 B) data has sdate dim of length 1 and then

  1. Dates$start is a vector. In this case, maybe two options as well: 1.1) the vector is of the length of ftime 1.2) the vector is of the length of the product ftime x sdate dimension
  2. Dates$start is an array with ftime and sdate dimensions

SelectPeriodOnDates and SelectPeriodOnData seem to work correctly when sdate dim is 1. And the result of of CST_PeriodAccumulation is correct as well. So, the only problem is the check.

I think that the warning should be moved in the check to:

  if (!is.null(start) && !is.null(end)) {
    if (is.null(dim(data$Dates$start))) {
      if (length(data$Dates$start) != dim(data$data)[time_dim]) {
        if (length(data$Dates$start) ==
            prod(dim(data$data)[time_dim] * dim(data$data)['sdate'])) {
          dim(data$Dates$start) <- c(dim(data$data)[time_dim],
                                     dim(data$data)['sdate'])
        } else {
        warning("Dimensions in 'data' element 'Dates$start' are missed and ",
                "all data would be used.")
        }
      }
    }
  }

Then, if start and end are missed, or Dates had dimension or the length of dates match the length of ftime, the function will jump and work. Only in case there are no dimensions and the length doesn't match the product ftime x sdate, the warning should appear or a transformation is needed. Here there is one assumption in the transformation that maybe could be removed, this is that the Dates are ordered in ftime x sdate and not the other way around.

Well, this check may depend on the changes you are introducing to s2dv_cube object too.

How do you see it?

Thanks in advance,

Núria