[SciPy-user] aggregation of long-term time series

Pierre GM pgmdevlist@gmail....
Tue Mar 25 12:59:34 CDT 2008


On Tuesday 25 March 2008 13:46:23 Marco Tuckner wrote:
> Hello,
> I'd like to aggregate several years of a long term data set into a
> year-long data set (365 days).

Relatively straightforward with scikits.timeseries:

>>>import numpy as np
>>>import scikits.timeseries as ts
>>>test = ts.time_series(np.arange(36), start_date=ts.now('M'))
timeseries([ 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 
22 23 24
 25 26 27 28 29 30 31 32 33 34 35],
           dates = [Mar-2008 ... Feb-2011],
           freq  = M)
>>>atest = test.convert('A')
timeseries(
 [[-- -- 0 1 2 3 4 5 6 7 8 9]
 [10 11 12 13 14 15 16 17 18 19 20 21]
 [22 23 24 25 26 27 28 29 30 31 32 33]
 [34 35 -- -- -- -- -- -- -- -- -- --]],
           dates =
 [2008 ... 2011],
           freq  = A-DEC)

Now you can get your result per month using the method you want and axis=0:

Monthly mean: atest.mean(0)
Monthly variance: atest.varu(0) (that's the unbiased variance)
and so forth.

HIH
P.


More information about the SciPy-user mailing list