[SciPy-User] scikits.timeseries.tsfromtxt & guess
Mon Jan 4 14:25:30 CST 2010
>> I first want to stress again that the tsfromtxt in the timeseries scikit is a
>> real killer function.
> My, thanks a lot
Yes, you may remember all my questions (still at the beginning of my
scipy learning curve) on the data loading and creation of masked time
This is now all obsolete. And as I receive data (logger) in wicked
formats not counting from 0-23 but rather 1-24, I appreciate the
datconverters which are based on strong datetime manupulations.
> I'd first create the time series from the input, then try to guess the frequency from the DateArray
So you'd recommend to create the timeseries using the userdefined
def mydateconverter(year, month, day, hour, freq='U'):
freq = ts.extras.guess_freq(year, month, day, hour)
ts_date = ts.Date(freq, year=int(year), month=int(month), day=int(day))
and then use guess_freq to assign the correct one?
I want to have the dateconverters in a flexible style only variyng by
input format and clumns used. They should be working regardless of the
frequency (be the data set hourly or minutely).
>> How can I pass a frequency value to the dateconverter argument?
>> def mydateconverter(year, month, day, hour, freq='T'):
>> freq = ts.extras.guess_freq(year, month, day, hour)
>> ts_date = ts.Date(freq, year=int(year), month=int(month), day=int(day))
>> return ts_date
>> myts= ts.tsfromtxt(datafile, skiprows=1, names=None,
>> datecols=(1,2,3), guess_freq=True,
>> I get this error then:
>> TypeError: mydateconverter() takes at least 2 non-keyword arguments (0 given)
> Please send a small example of datafile so that I can test wht goes wrong. If I have to guess: the line `dateconverter=mydateconverter(freq='H')` forces a call to mydateconverter without any argument (but for he frequency). Of course, that won't fly.
> What you want is to have `mydateconverter(freq='H')` callable. You should probably create a class that takes a frequency as instantiation input and that has a __call__ method, something like:
> class myconverter(object)
> def __init__(freq='D'):
> def __call__(self, y,m,d,h):
> return ts.Date(self.freq, year=int(y),month=int(m),day=int(day),hour=int(h))
> That way, myconverter(freq='T') becomes a valid function (you can call it).
Thanks. I will try this way.
More information about the SciPy-User