[SciPy-User] scikits.timeseries.tsfromtxt & guess

Tim Michelsen timmichelsen at gmx-topmail.de
Mon Jan 4 12:11:42 EST 2010


Hello,
I first want to stress again that the tsfromtxt in the timeseries scikit is a
real killer function.
Once one has understood the easyness of the "dateconverter" function it becomes
a quick exercise to read in timeseries from ASCII files.

As I am currently predefining a set of dateconverters for frquently used
date-time combinations in different formats, I have the following question:
Is it possible to integrate "ts.extras.guess_freq(dates)" into the function
scikits.timeseries.tsfromtxt?


Currently, I would need to read a file twice: once for guessing the frequency
based on a created list of dates and then read file to create the timeseries.

Ideally, I would like to do:
 


def mydateconverter(year, month, day, hour):
    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,  
                      dateconverter=mydateconverter)

Or is this already possible and I am just not getting this right?


How can I pass a frequency value to the dateconverter argument?

Like:
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,  
                      dateconverter=mydateconverter(freq='H'))

I get this error then:
TypeError: mydateconverter() takes at least 2 non-keyword arguments (0 given)

Thanks in advance for any hints,
Timmie




More information about the SciPy-User mailing list