Changeset 2100
- Timestamp:
- 02/26/09 13:45:53 (3 years ago)
- Location:
- trunk/timeseries/scikits/timeseries
- Files:
-
- 7 modified
-
doc/source/conf.py (modified) (1 diff)
-
doc/source/core.timeseries.conversion.rst (modified) (2 diffs)
-
extras.py (modified) (2 diffs)
-
lib/plotlib.py (modified) (2 diffs)
-
tests/test_dates.py (modified) (2 diffs)
-
tests/test_extras.py (modified) (1 diff)
-
tseries.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/timeseries/scikits/timeseries/doc/source/conf.py
r2083 r2100 222 222 intersphinx_mapping = {'http://docs.python.org/dev': None, 223 223 'http://docs.scipy.org/doc/numpy': None, 224 'http://docs.scipy.org/doc/scipy/reference': None, 224 225 'http://matplotlib.sourceforge.net': None} 225 226 -
trunk/timeseries/scikits/timeseries/doc/source/core.timeseries.conversion.rst
r2068 r2100 50 50 51 51 .. warning:: 52 Be careful not to confuse the two methods :meth:`asfreq` and :meth:`convert`. 52 Be careful not to confuse the two methods :meth:`~TimeSeries.asfreq` 53 and :meth:`~TimeSeries.convert`. 53 54 54 55 * :meth:`~TimeSeries.asfreq` simply takes every date … … 62 63 places the data from the original series into appropriate points in the new 63 64 series. 65 66 67 .. autosummary:: 68 :toctree: generated/ 69 70 convert 71 scikits.timeseries.extras.convert_to_annual -
trunk/timeseries/scikits/timeseries/extras.py
r2080 r2100 24 24 25 25 __all__ = ['accept_atmost_missing', 26 'co unt_missing',26 'convert_to_annual', 'count_missing', 27 27 'guess_freq', 28 28 'isleapyear', … … 97 97 raise NotImplementedError, "Not yet implemented for that frequency..." 98 98 return missing 99 100 101 102 def convert_to_annual(series): 103 """ 104 Group a series by years, taking leap years into account. 105 106 The output has as many rows as distinct years in the original series, 107 and as many columns as the length of a leap year in the units corresponding 108 to the original frequency (366 for daily frequency, 366*24 for hourly...). 109 The fist column of the output corresponds to Jan. 1st, 00:00:00, 110 while the last column corresponds to Dec, 31st, 23:59:59. 111 Entries corresponding to Feb. 29th are masked for non-leap years. 112 113 For example, if the initial series has a daily frequency, the 59th column 114 of the output always corresponds to Feb. 28th, the 61st column to Mar. 1st, 115 and the 60th column is masked for non-leap years. 116 With a hourly initial frequency, the (59*24)th column of the output always 117 correspond to Feb. 28th 23:00, the (61*24)th column to Mar. 1st, 00:00, and 118 the 24 columns between (59*24) and (61*24) are masked. 119 120 If the original frequency is less than daily, the output is equivalent to 121 ``series.convert('A', func=None)``. 122 123 124 Parameters 125 ---------- 126 series : TimeSeries 127 A valid :class:`~scikits.timeseries.TimeSeries` object. 128 129 Returns 130 ------- 131 aseries : TimeSeries 132 A 2D :class:`~scikits.timeseries.TimeSeries` object with annual ('A') 133 frequency. 134 135 """ 136 dates = series.dates 137 if dates.freq < _c.FR_DAY: 138 return series.convert('A') 139 idx0228 = dates.date_to_index(Date(dates.freq, 140 year=dates[0].year, month=2, day=28, 141 hour=00, minute=00, second=00)) 142 idx0301 = dates.date_to_index(Date(dates.freq, 143 year=dates[0].year, month=3, day=1, 144 hour=00, minute=00, second=00)) 145 aseries = series.convert('A') 146 leapcondition = isleapyear(aseries.dates.years) 147 leapidx = np.arange(len(aseries), dtype=int)[~leapcondition] 148 aseries[leapidx, idx0301:] = aseries[leapidx, idx0228:idx0228-idx0301] 149 aseries[leapidx, idx0228:idx0301] = ma.masked 150 return aseries 151 152 99 153 100 154 #............................................................................. -
trunk/timeseries/scikits/timeseries/lib/plotlib.py
r2068 r2100 995 995 """ 996 996 Plots the data parsed in argument to the current axes. 997 This command accepts the same optional keywords as :func:`matplotlib.p lot`.997 This command accepts the same optional keywords as :func:`matplotlib.pyplot.plot`. 998 998 999 999 The argument ``args`` is a variable length argument, allowing for multiple … … 1014 1014 1015 1015 a :class:`~scikits.timeseries.TimeSeries` object or one of its subclass 1016 with or without a format string:1016 with or without a format string: 1017 1017 The given time series is plotted with the given format. 1018 1018 If no format string is given, the default format is used instead. -
trunk/timeseries/scikits/timeseries/tests/test_dates.py
r2073 r2100 123 123 _dt = ts.Date(freq='D', datetime=datetime.datetime(2007, 1, 1, 0, 0, 0, 0)) 124 124 assert_equal(_dt, _tsdt) 125 print "finished test_fromsobjects"126 125 127 126 … … 145 144 assert_equal(date_array(n,length=3), d) 146 145 assert_equal(date_array(n, n+2), d) 147 print "finished test_shortcuts"148 146 149 147 -
trunk/timeseries/scikits/timeseries/tests/test_extras.py
r2080 r2100 78 78 assert_equal(result._mask.all(-1), [1,1]) 79 79 80 def test_convert_to_annual(self): 81 "Test convert_to_annual" 82 base = dict(D=1, H=24, T=24*60, S=24*3600) 83 #for fq in ('D', 'H', 'T', 'S'): 84 # Don't test for minuTe and Second frequency, too time consuming. 85 for fq in ('D', 'H'): 86 dates = date_array(start_date=Date(fq, '2001-01-01 00:00:00'), 87 end_date=Date(fq, '2004-12-31 23:59:59')) 88 bq = base[fq] 89 series = time_series(range(365*bq)*3+range(366*bq), 90 dates=dates) 91 control = ma.masked_all((4, 366*bq), dtype=series.dtype) 92 control[0, :58*bq] = range(58*bq) 93 control[0, 59*bq:] = range(58*bq, 365*bq) 94 control[[1, 2]] = control[0] 95 control[3] = range(366*bq) 96 test = convert_to_annual(series) 97 assert_equal(test, control) 98 80 99 81 100 -
trunk/timeseries/scikits/timeseries/tseries.py
r2068 r2100 1305 1305 _s = np.choose(idx, np.rollaxis(_series,axis,0)) 1306 1306 _d = np.choose(idx, np.rollaxis(_dates,axis,0)) 1307 result = time_series(_s, dates=_d )1307 result = time_series(_s, dates=_d, freq=_dates.freq) 1308 1308 return result 1309 1309
