[SciPy-dev] time series implementation approach

Matt Knox mattknox_ca at hotmail.com
Wed Dec 13 09:31:07 CST 2006

Hi David,

computing monthly averages from a daily series is already implemented. Here is the code that would accomplish that with the current implementation:

import timeseries as ts
import numpy as np

startDate = ts.Date(freq='DAILY', year=1999, month=5, day=15)

# create a series with random data (note that the values could also be a masked array)
myDailyData = ts.TimeSeries(np.random.uniform(-100,100,600), freq='DAILY',observed='AVERAGED',startIndex=startDate)

# compute monthly mean (observed argument is optional, and will use the observed attribute of the time series if not specified)
monthlyAverageSeries = myDaiyData.convert(freq='MONTHLY',observed='AVERAGED')

print monthlyAverageSeries

Computing monthly variance can not be done easily at the moment. The frequency conversion code is implemented in C and the method of conversion is applied at the same time in one step (averaged in this example).  Pierre made a good suggestion that I am going to look at doing shortly, which is to just group the data in C and return a 2 dimensional array to python, and then in python apply a user specified function along the axis. It will be slower than doing the whole thing in C, but I think the flexibility is worth the trade off. This would make it very easy to compute monthly variance if that is what you were after.

As far as irregularily spaced data goes... I think Pierre's suggestion of a "nofreq" frequency would work pretty well. It should be fairly easy to support that special case, and also support converting it to a more rigid frequency.

I'm still wavering on the ShiftingArray vs sub-classing MaskedArray approach as the backbone of the TimeSeries object. At this moment I think I am leaning more towards sub-classing MaskedArray (bet you didn't expect that, Pierre!), but who knows what I will feel like this afternoon.

- Matt

More information about the Scipy-dev mailing list