# [SciPy-User] scikits.timeseries question

Robert Ferrell ferrell@diablotech....
Mon Nov 30 18:53:56 CST 2009

```On Nov 30, 2009, at 5:23 PM, Christopher Barker wrote:

> Pierre GM wrote:
>> On Nov 30, 2009, at 6:58 PM, Christopher Barker wrote:
>> I guess you're confusing DateArrays and TimeSeries.
>
>> DateArrays are just arrays of dates (think a ndarray of datetime
>> objects, or a ndarray with a datetime64 dtype). TimeSeries are like
>> MaskedArrays, the combination of a ndarray of values with 2 others
>> ndarrays: one array of booleans (the mask), one DateArray.
>
> Actually, I think I got that.
>
>>> In [41]: sd = ts.Date(freq='D', year=2001, month=1, day=1)
>>>
>>> In [42]: sd
>>> Out[42]: <D : 01-Jan-2001>
>>
>> All is well here.
>
> yup.
>
>>> In [43]: da = ts.date_array((1,2,3,4), start_date=sd)
>>
>> Check the doc for date_array: the first argument can be
>
> ...
>
>>        * a sequence of integers corresponding to the representation
>> of
>>          :class:`Date` objects.
>
> That's what I'm trying to give it.
>
>> So, what you're trying to do is to build a an array of four dates
>> (1,2,3,4)
>>
>>>>> ts.time_series((1,2,3,4),start_date=sd)
>> timeseries([1 2 3 4],
>>   dates = [01-Jan-2001 ... 04-Jan-2001],
>>   freq  = D)
>
> Ah, but what I am trying to do is build that "dates" array -- in teh
> real case, I have 1212 pieces of data, associated with time, in
> terms of
> "days since Jan 1, 2001). So I need to construct that dates array to
> associate with the time_series data.
>
> So I want:
>
> dates = what_to_put_here?

I may be misunderstanding what you are trying to do, but here's what I
do:

In [68]: sd = ts.Date('d', '2001-01-01')

In [69]: dates = ts.date_array(cumsum(ones(4)) + sd)

In [70]: dates
Out[70]:
DateArray([02-Jan-2001, 03-Jan-2001, 04-Jan-2001, 05-Jan-2001],
freq='D')

If the dates aren't consecutive, you can always just use the known
offsets:

In [73]: days_since_beginning = array([1, 3, 4, 8])

In [74]: dates = ts.date_array(days_since_beginning + sd)

In [75]: dates
Out[75]:
DateArray([02-Jan-2001, 04-Jan-2001, 05-Jan-2001, 09-Jan-2001],
freq='D')

There's probably an easier way...

If this happens to be what you are trying to do, be careful of the
counting of days (0 based, vs 1 based).

-robert

>
> ts.time_series(an_array_of_data,
>      start_date=sd)
>      timeseries([1 2 3 4],
>      dates = dates],
>      freq  = D)
>
> 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_series be n-d, with time as one of the axis?
>
> -Chris
>
>
>
> --
> Christopher Barker, Ph.D.
> Oceanographer
>
> Emergency Response Division
> NOAA/NOS/OR&R            (206) 526-6959   voice
> 7600 Sand Point Way NE   (206) 526-6329   fax
> Seattle, WA  98115       (206) 526-6317   main reception
>
> Chris.Barker@noaa.gov
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user

```