How to slice TimeSeries data?

11

4

When retrieving curated data, v10 now returns TimeSeries objects.

For example,

ts = WeatherData["KP60", "Temperature", {{2013, 7, 1}, {2013, 9, 30}}]

DateListPlot[ts]

What is the most convenient way to extract a range from this temporal data, for example for plotting purposes? E.g. only plot the first two weeks of August from this data.

I know I can simply convert it to a list using Normal and then use e.g. Select to filter. Is there anything better?

Szabolcs

Posted 2014-07-26T03:16:36.510

Reputation: 213 047

Congratulations on being our foremost question poster!

– Mr.Wizard – 2014-07-27T15:45:52.267

WeatherData fails when I try w/ 10.0.1: ibraryFunction::versint: The version number 1 of the library is from a previous WolframLibrary that cannot support integers as large as 4472425792. Anyone else? – alancalvitti – 2014-09-29T17:43:57.750

Answers

16

One of the new operations on TimeSeries objects is TimeSeriesWindow. I think it does what you need.

ts = WeatherData["KP60", "Temperature", {{2013, 7, 1}, {2013, 9, 30}}];
DateListPlot[TimeSeriesWindow[ts, {{2013, 8, 1}, {2013, 8, 14}}]]

enter image description here

david

Posted 2014-07-26T03:16:36.510

Reputation: 1 078