Hi Ricardo,
The issue is some of the input time series already contains duplicate timestamps after the shift. Probably something like:
- the source data already had repeated timestamps,
- the shift changes leap-year alignment,
- the series has irregular timestamps that become duplicated after normalization,
- or the time series includes identical dates at different positions.
You need to disambiguate the duplicated timestamps, one way being to add a tiny jitter (10^9 seconds) only when a year has exact duplicate timestamps, which should preserve the original order. So rebuild each series with explicit {time, value} pairs and then create the TimeSeries with TemporalRegularity -> False so not to force a regular grid.
ClearAll[shiftAndJitterDuplicates];
shiftAndJitterDuplicates[ts_] := Module[{pairs, adjustedPairs},
pairs = Normal @ ts;
adjustedPairs = Flatten[
Map[
Function[group,
Module[{n = Length[group], times, values},
times = group[[All, 1]];
values = group[[All, 2]];
Transpose[{times + Range[0, n - 1]*Quantity[10^-9, "Seconds"],
values}]]
],
GatherBy[pairs, First]
], 1];
TimeSeries[adjustedPairs, TemporalRegularity -> False]];
tsvsh2 = shiftAndJitterDuplicates /@
(TimeSeriesShift[
tsv[[# - 1979]], {{aniofinal - #, "Year"}, {0, "Day"}}] & /@
Range[1980, aniofinal]);
Other series are not affected.
tsvsh[[44]] === tsvsh2[[44]] - TRUE
Hope this helps.