Remove a specific element of a TimeSeries?
You can use TimeSeriesResample
as follows:
ts2 = TimeSeries[{0.0, 0.0, 0.0, 0.0, 15.0, 0.0, 0.0, 0.0}, {1}];
pks = FindPeaks[ts2];
ts3 = TimeSeriesResample[ts2, { Complement[ts2["Times"], pks["Times"]]}]
Normal@ts3
{{1, 0.}, {2, 0.}, {3, 0.}, {4, 0.}, {6, 0.}, {7, 0.}, {8, 0.}}
Complete automation
I think what you are actually looking for is DeleteAnomalies
. Define these data:
ts=TimeSeries[{1,2,3,15,3,2,1},{1}]
Now compare old and new:
DateListPlot[
{ts,TimeSeries[DeleteAnomalies[ts["Path"]]]},
PlotMarkers->Automatic,PlotRange->All]
Surgery
Now if you want to play surgeon, you can define a function:
deleteTS[ts_,pts_]:=
DeleteMissing[TimeSeriesInsert[ts,TimeSeries[Thread[{pts,Missing[]}]]]]
It uses TimeSeriesInsert
to replace elements at positions pts with Missing[]
and then removes them with DeleteMissing
. For example compare:
ts["Path"]
deleteTS[ts, {4}]["Path"]
deleteTS[ts, FindPeaks[ts]["Times"]]["Path"]
Out[1]= {{1, 1}, {2, 2}, {3, 3}, {4, 15}, {5, 3}, {6, 2}, {7, 1}}
Out[2]= {{1, 1}, {2, 2}, {3, 3}, {5, 3}, {6, 2}, {7, 1}}
Out[3]= {{1, 1}, {2, 2}, {3, 3}, {5, 3}, {6, 2}, {7, 1}}
You can also delete a set of points:
DateListPlot[
{ts,deleteTS[ts,{3,5}]},
PlotMarkers->Automatic,PlotRange->All]
and add some fancy replacement/smothing for deleted points:
DateListPlot[
{ts,
TimeSeriesResample[deleteTS[ts,{4}],
ResamplingMethod->{"Interpolation",InterpolationOrder->2}]},
PlotMarkers->Automatic,PlotRange->All]