11
$\begingroup$

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?

$\endgroup$
2
  • $\begingroup$ Congratulations on being our foremost question poster! $\endgroup$
    – Mr.Wizard
    Jul 27, 2014 at 15:45
  • $\begingroup$ 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? $\endgroup$ Sep 29, 2014 at 17:43

1 Answer 1

16
$\begingroup$

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

$\endgroup$
4
  • $\begingroup$ How do I get the results back into a TimeSeries? It's returning a different format causing subsequent errors in code that expects a TimeSeries. $\endgroup$
    – Michael
    Jul 11, 2021 at 17:09
  • $\begingroup$ @Michael, the TimeSeriesWindow argument to DateListPlot will be a TimeSeries. You might be using the DateListPlot output which is not a TimeSeries. $\endgroup$
    – david
    Jul 12, 2021 at 16:17
  • $\begingroup$ I'm actually using the output of FinancialData $\endgroup$
    – Michael
    Jul 14, 2021 at 19:44
  • $\begingroup$ I'm not sure what to say without more information. I do know that TimeSeriesWindow will return a TimeSeries when used as documented. $\endgroup$
    – david
    Jul 14, 2021 at 22:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.