Use of SeriesAggreg when TimeLag >= 3600
Use of SeriesAggreg when TimeLag >= 3600
The SeriesAggreg()
function does not work when TimeLag >= 3600
.
Error in `*tmp*`[1:(length(Ind2) - 1)] :
only 0's may be mixed with negative subscripts
- #25v1.6.10
- #43v1.6.10
Activity
- Delaigue Olivier added BUG R labels
- Author Owner
This is a very bad function. I think it might be a good idea to rewrite it entirely...
- Delaigue Olivier created branch
SeriesAggreg
to address this issuecreated branch
SeriesAggreg
to address this issue - Delaigue Olivier mentioned in commit 7a804e87
mentioned in commit 7a804e87
- Delaigue Olivier mentioned in commit 81fccf1d
mentioned in commit 81fccf1d
- Delaigue Olivier mentioned in commit 50d0ad9f
mentioned in commit 50d0ad9f
- Delaigue Olivier mentioned in commit 25d44cab
mentioned in commit 25d44cab
- Author Owner
First tests:
library(airGR) ## loading catchment data data(L0123002) ## preparation of the initial time series data frame at the daily time step TabSeries <- BasinObs[, c("DatesR", "P", "E", "T", "Qmm")] ## yearly time series NewTabSeries <- SeriesAggreg2(TabSeries = TabSeries, Format = "%Y", ConvertFun = c("sum", "sum", "mean", "sum")) plot(Qmm ~ DatesR, data = NewTabSeries, type = "l") ## monthly time series NewTabSeries <- SeriesAggreg2(TabSeries = TabSeries, Format = "%Y%m", ConvertFun = c("sum", "sum", "mean", "sum")) plot(Qmm ~ DatesR, data = NewTabSeries, type = "l") ## daily times series NewTabSeries <- SeriesAggreg2(TabSeries = TabSeries, Format = "%Y%m%d", ConvertFun = c("sum", "sum", "mean", "sum")) plot(Qmm ~ DatesR, data = NewTabSeries, type = "l")
Edited by Delaigue Olivier - Delaigue Olivier mentioned in commit 344a99d0
mentioned in commit 344a99d0
- Owner
The first tests on the new function seem to indicate that it works.
For
SeriesAggreg
andSeriesAggreg2
documentation, I think we should add the following in the Details:TabSeries first column must be a vector of class 'POSIXct' or 'POSIXlt'
and
Only 'sum' and 'mean' functions are allowed for the
ConvertFun argument
In
SeriesAggreg
andSeriesAggreg2
,09 for hydrological year starting in September
should be replaced with
10 for hydrological year starting in October
to be more consistent with what we usually define as hydrological year.
Edited by Thirel Guillaume - Owner
SeriesAggreg2
seems to work well when one column is full of NA.SeriesAggreg2
does not work when all functions are the same (onlymean
or onlysum
) or when there is only one column to aggregate.We should specify that
YearFirstMonth
must be comprised between 1 and 12.If
YearFirstMonth
is different from 1, with the example data, the aggregatedE
value differs between years, which is not the case isYearFirstMonth == 1
. Not sure why asE
is apparently recycled between years... - Author Owner
SeriesAggreg2
seems to work well when one column is full of NA.Yes, it is. In the old function, this was due to a bad check. Here, there's none at the moment, so it's okay.
SeriesAggreg2
does not work when all functions are the same (onlymean
or onlysum
) or when there is only one column to aggregate.I am aware of this. It is because I calculate on the one hand the variables for which a sum is calculated, and on the other hand the variables for which an average is calculated. I haven't written a condition yet, so it blocks as soon as there is only one type of calculation (which is the case when there is only one column).
We should specify that
YearFirstMonth
must be comprised between 1 and 12.That's the plan. It will be done with all checks.
If
YearFirstMonth
is different from 1, with the example data, the aggregatedE
value differs between years, which is not the case isYearFirstMonth == 1
. Not sure why asE
is apparently recycled between years...I don't think there's anything wrong with E, it's just an artifact due to the time lag.
t(sapply(1:12, function(iMonth) { colMeans(SeriesAggreg2(TabSeries = TabSeries, Format = "%Y", ConvertFun = c("sum", "sum", "mean", "sum"), YearFirstMonth = iMonth)[, -1], na.rm = TRUE) }))
P E T Qmm [1,] 1306.659 773.637 4.397387 834.0093 [2,] 1307.660 773.637 4.394651 837.2398 [3,] 1301.804 773.637 4.399010 837.1611 [4,] 1297.990 773.637 4.397400 834.4623 [5,] 1295.416 773.637 4.407993 836.4688 [6,] 1296.348 773.637 4.405374 830.5675 [7,] 1296.186 773.637 4.402236 820.5473 [8,] 1295.703 773.637 4.405294 818.0329 [9,] 1294.788 773.637 4.401807 817.5955 [10,] 1297.892 773.637 4.403590 817.5614 [11,] 1300.759 773.637 4.404807 818.1412 [12,] 1300.401 773.637 4.397562 818.2841
plot(E ~ DatesR, data = TabSeries, type = "l", col = "green3")
Edited by Delaigue Olivier - Delaigue Olivier mentioned in commit 34e7de42
mentioned in commit 34e7de42
- Author Owner
I think that all checks are now written.
- Owner
I tested the last version.
I corrected the help page (attached).
I also tested the checks. I made modifications in the code directly. I also corrected minor typos.
If we put a wrong value in NewTimeFormat, which is deprecated, then the error might not be 100% clear.
+ NewTimeFormat = "%d", + ConvertFun = c("sum", "sum", "mean", "sum")) Error in match.arg(Format, choices = listFormat) : 'arg' should be one of “%Y%m%d”, “%Y%m”, “%Y”, “%m”, “%d”
Maybe check just before line 10 that NewTimeFormat respects the correct possibilities?
TimeStep <- c("hourly", "daily", "monthly", "yearly") NewTimeFormat <- match.arg(NewTimeFormat, choices = TimeStep)
The function now runs when all
ConvertFun
are the same, but not yet when there is only one column to convert.> NewTabSeries <- SeriesAggreg2(TabSeries = TabSeries[, 1:2], + Format = "%Y%m%d", + ConvertFun = c("sum")) Error in apply(TabSeries[, -1L], MARGIN = 2, FUN = function(iCol) { : dim(X) must have a positive length
- Delaigue Olivier mentioned in commit 605281fc
mentioned in commit 605281fc
- Delaigue Olivier mentioned in commit 3fba4b08
mentioned in commit 3fba4b08
- Delaigue Olivier mentioned in commit c2f98a6f
mentioned in commit c2f98a6f
- Delaigue Olivier mentioned in commit 7f5b7e56
mentioned in commit 7f5b7e56
- Delaigue Olivier mentioned in commit 9b1db179
mentioned in commit 9b1db179