[SciPy-User] scikits.timeseries question
Christopher Barker
Chris.Barker at noaa.gov
Wed Dec 2 18:14:08 EST 2009
Folks,
Sorry ask a question and then disappear, but I had a full day away from
work and email yesterday! I do appreciate all the help, though. It's
going to ake a bit to digest this, but it looks like I can do what I
want to do here.
Pierre GM wrote:
>>> 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.
>> OK -- though it seems I SHOULD be able to go straight to an DateArray,
>> and I'm still confused about what this means:
>
> Well, that depends on the type of starting date, actually. If it's a
> Date, adding a ndarray to it will give you a ndarray of Date
> objects. If it's a DateArray of length 1, it'll give you a DateArray.
ah -- that does look helpful -- I guess I find it surprising that there
is a difference -- I think this may be legacy issues -- what I imagine
we'd want is a DateArray, and there would be a corresponding DateScalar
-- like there is for an array of float128s or whatever.
>>> * a sequence of integers corresponding to the representation of
>>> :class:`Date` objects.
>> That's what I have: a sequence of integers corresponding to the
>> representation of the Date objects (doesn't it represent them as "units
>> since start date" where units is the "freq" ?
>
> No, not exactly: the representation of a Date objects is relative to an absolute build-in reference (Day #1 being 01/01/01). (Likewise, nump.datetime64 uses the standard 1970/01/01).
OK -- got that now. I suppose I could add the integer value of my start
date and then I"d get what I want.
>> Definition:
>> ts_lib.mov_average(data, span, dtype=None)
>> Docstring:
>> Calculates the moving average of a series.
>>
>> Parameters
>> ----------
>> data : array-like
>> Input data, as a sequence or (subclass of) ndarray.
>> Masked arrays and TimeSeries objects are also accepted.
>> The input array should be 1D or 2D at most.
>> If the input array is 2D, the function is applied on each
>> column.
>>
>> I've got a 3-d array -- darn! Maybe I'll poke into it and see if it can
>> be generalized.
>
>
> 3D ? What are your actual variables? Keep in mind that when we talk about dimensions with time series, we zap the time one, so if you have a series of maps, your array is only 2D in our terminology.
> If you have a time series of (lat, lon), mov_average will average your lats independently of your lons
Then is should work -- what I've got is a 3-d array in a netcdf file, it
has dimensions: (time, lat, long) -- so it sounds like that should work.
Robert Ferrell wrote:
> Is the issue that sd is a Date and not a DateArray? You can always
> make a DataArray with sd, of the correct length, and then add to that:
>
> In [83]: sd = ts.Date('d', '2001-01-01')
> In [86]: d1 + array([0,2,3,5])
> Out[86]:
> DateArray([01-Jan-2001, 03-Jan-2001, 04-Jan-2001, 06-Jan-2001],
> freq='D')
yup - that's what I want! Thanks.
> In any case, I get the impression that the OP has an array of integer
> offsets generated in some other fashion entirely.
exactly.
Matt Knox wrote:
> In addition to the methods described by Pierre and Robert, you could also do:
>
>>>> sd = ts.now('d')
>>>> relative_days = np.array([1,5,8])
>>>> absolute_days = relative_days + sd.value
>>>> darray = ts.date_array(absolute_days, freq = sd.freq)
>
> which I think probably has the lowest overhead (but don't hold me to that :) )
> if that matters for your application.
Frankly, I don't think it does matter, but I like efficiency all the same.
Thanks to all three of you,
-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 at noaa.gov
More information about the SciPy-User
mailing list