[SciPy-User] scikits.timeseries question

Pierre GM pgmdevlist@gmail....
Mon Nov 30 18:49:35 CST 2009


On Nov 30, 2009, at 7:23 PM, Christopher Barker wrote:
> Pierre GM wrote:
> ...
> 
>>        * a sequence of integers corresponding to the representation of 
>>          :class:`Date` objects.
> 
> That's what I'm trying to give it.

Ah OK. Well, the answer is: that depends. iIf you know that your dates are just in daily increments from 2001-01-01 (like a range), then just use start_date and length.

If you may have several duplicated dates (like 2001-01-01, 2001-01-02, 2001-01-02, 2001-01-03...), then the easiest is probably:
>>> da = ts.date_array(np.array(0,1,1,2)+sd)

np.array(...) + sd gives you a ndarray of Date objects (so its dtype is np.object), and you use that as the input of date_array. The frequency should be recognized properly.

Note that if 1 in your data set means '2001-01-01', then use (sd-1) instead, but you would have guessed that.

> While I'm at it -- what I really have is a big 'ol 3-d array, which is 
> gridded model output, of shape: (time, lat, lon). Time is expressed in 
> days since...
> 
> I need to do a moving average of the while grid over time. Can a 
> time_serie be n-d, with time as one of the axis?


Well, I never tried so I can tell you. Check wheter lib.moving_funcs supports 2D data. If not, not a big deal: just fill the missing dates (so that you have a regular-spaced series with masked elements for missing dates), and use whatever moving average you need on the .series attribute (which is just a MaskedArray). Or fill this .series with np.nans if your averaging function accepts floats but no missing values...

Let me know how it goes
P.



More information about the SciPy-User mailing list