Changeset 1044
- Timestamp:
- 06/18/08 20:42:59 (2 months ago)
- Files:
-
- trunk/timeseries/scikits/timeseries/__init__.py (modified) (1 diff)
- trunk/timeseries/scikits/timeseries/const.py (modified) (1 diff)
- trunk/timeseries/scikits/timeseries/extras.py (modified) (2 diffs)
- trunk/timeseries/scikits/timeseries/lib/__init__.py (modified) (1 diff)
- trunk/timeseries/scikits/timeseries/lib/avcf.py (modified) (20 diffs)
- trunk/timeseries/scikits/timeseries/lib/interpolate.py (modified) (1 diff)
- trunk/timeseries/scikits/timeseries/lib/moving_funcs.py (modified) (1 diff)
- trunk/timeseries/scikits/timeseries/lib/plotlib.py (modified) (1 diff)
- trunk/timeseries/scikits/timeseries/lib/reportlib.py (modified) (1 diff)
- trunk/timeseries/scikits/timeseries/lib/tests/test_avcf.py (modified) (6 diffs)
- trunk/timeseries/scikits/timeseries/lib/tests/test_interpolate.py (modified) (1 diff)
- trunk/timeseries/scikits/timeseries/lib/tests/test_moving_funcs.py (modified) (2 diffs)
- trunk/timeseries/scikits/timeseries/setup.py (modified) (1 diff)
- trunk/timeseries/scikits/timeseries/tdates.py (modified) (5 diffs)
- trunk/timeseries/scikits/timeseries/tests/test_dates.py (modified) (1 diff)
- trunk/timeseries/scikits/timeseries/tests/test_extras.py (modified) (1 diff)
- trunk/timeseries/scikits/timeseries/tests/test_timeseries.py (modified) (1 diff)
- trunk/timeseries/scikits/timeseries/tests/test_trecords.py (modified) (3 diffs)
- trunk/timeseries/scikits/timeseries/trecords.py (modified) (5 diffs)
- trunk/timeseries/scikits/timeseries/tseries.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/timeseries/scikits/timeseries/__init__.py
r1043 r1044 8 8 9 9 __author__ = "Pierre GF Gerard-Marchant & Matt Knox ($Author$)" 10 #__version__ = '0.67'11 10 __revision__ = "$Revision$" 12 11 __date__ = '$Date$' trunk/timeseries/scikits/timeseries/const.py
r1043 r1044 74 74 """ 75 75 __author__ = "Pierre GF Gerard-Marchant & Matt Knox ($Author$)" 76 __version__ = '0.67'77 76 __revision__ = "$Revision$" 78 77 __date__ = '$Date$' trunk/timeseries/scikits/timeseries/extras.py
r1032 r1044 7 7 """ 8 8 __author__ = "Pierre GF Gerard-Marchant & Matt Knox ($Author$)" 9 __version__ = '0.67'10 9 __revision__ = "$Revision$" 11 10 __date__ = '$Date$' … … 143 142 fcode = _c.FR_HR 144 143 elif getattr(res, 'day', 0) >= 1: 145 fcode = _c.FR_DAY 144 fcode = _c.FR_DAY 146 145 elif getattr(res, 'day', 0) >= 7: 147 146 fcode = _c.FR_WK trunk/timeseries/scikits/timeseries/lib/__init__.py
r1032 r1044 5 5 """ 6 6 __author__ = "Pierre GF Gerard-Marchant & Matt Knox ($Author$)" 7 __version__ = '0.67'8 7 __revision__ = "$Revision$" 9 8 __date__ = '$Date$' trunk/timeseries/scikits/timeseries/lib/avcf.py
r1032 r1044 8 8 """ 9 9 __author__ = "Pierre GF Gerard-Marchant ($Author$)" 10 __version__ = '1.0'11 10 __revision__ = "$Revision$" 12 11 __date__ = '$Date$' … … 39 38 where $j$ is the lag. 40 39 Positive lags: 41 N.correlate(y,x)[n//2+j] = N.correlate(x,y)[n//2-j] = gamma[j] 40 N.correlate(y,x)[n//2+j] = N.correlate(x,y)[n//2-j] = gamma[j] 42 41 """ 43 42 44 43 def lags(x, y=None): 45 44 """Returns the lags at which a cross-correlation is computed. 46 45 47 46 :Parameters: 48 47 `x` : Sequence … … 63 62 return L 64 63 65 64 66 65 #............................................................................... 67 66 … … 74 73 and ending point match. 75 74 76 The crosscovariance at lag k, $\hat{R_{x,y}}(k)$, of 2 series {x_1,...,x_n} 75 The crosscovariance at lag k, $\hat{R_{x,y}}(k)$, of 2 series {x_1,...,x_n} 77 76 and {y_1,...,y_n} with mean 0 is defined as: 78 77 \hat{R_{x,y}(k) = \sum_{t=1}^{n-k}{x_t y_{t+k}} / \sum_{t=1}^{n-k}{a_t b_{t+k}} … … 83 82 If the optional parameter `periodogram` is True, the denominator of the previous 84 83 expression is $\sum_{t=1}^{n-k}{a_t a_{t+k}} + k$. 85 84 86 85 Parameters 87 86 ---------- 88 87 x : sequence 89 Input data. 88 Input data. 90 89 y : sequence 91 Input data. 90 Input data. 92 91 If y is longer than x, it is truncated to match the length of x. 93 92 If y is shorter than x, x is truncated. 94 93 periodogram : {True, False} optional 95 94 Whether to return a periodogram or a standard estimate of the autocovariance. 96 95 97 96 Returns 98 97 ------- 99 98 cvf : ma.array 100 99 Cross-covariance at lags [0,1,...,n,n-1,...,-1] 101 100 102 101 """ 103 102 # … … 134 133 135 134 136 def ccf(x, y, periodogram=True): 135 def ccf(x, y, periodogram=True): 137 136 """Computes the auto-correlation of the series x and y at different lags. 138 137 The computations are performed on anomalies (deviations from average). … … 141 140 If x and y are valid TimeSeries object, they are aligned so that their starting 142 141 and ending point match. 143 142 144 143 Parameters 145 144 ---------- 146 145 x : sequence 147 Input data. 146 Input data. 148 147 y : sequence 149 Input data. 148 Input data. 150 149 If y is longer than x, it is truncated to match the length of x. 151 150 If y is shorter than x, x is truncated. 152 151 periodogram : {True, False} optional 153 152 Whether to return a periodogram or a standard estimate of the autocovariance. 154 153 155 154 Returns 156 155 ------- … … 176 175 If the optional parameter `periodogram` is True, the denominator of the previous 177 176 expression is $\sum_{t=1}^{n-k}{a_t a_{t+k}} + k$. 178 177 179 178 Parameters 180 179 ---------- … … 183 182 mode : {True, False} optional 184 183 Whether to return a periodogram or a standard estimate of the autocovariance. 185 184 186 185 Returns 187 186 ------- 188 187 avf : ma.array 189 188 Autocovariance at lags [0,1,...,n,n-1,...,-1] 190 189 191 190 """ 192 191 x = ma.array(x, copy=False, subok=True, dtype=float) … … 215 214 Gaps in the series are filled first, anomalies are then computed and missing 216 215 values filled with 0. 217 218 216 217 219 218 Parameters 220 219 ---------- … … 223 222 mode : {True, False} optional 224 223 Whether to return a periodogram or a standard estimate of the autocorrelation. 225 224 226 225 Returns 227 226 ------- … … 239 238 Gaps in the series are filled first, the anomalies are then computed and the missing 240 239 values filled with 0. 241 240 242 241 :Parameters: 243 242 `x` : TimeSeries … … 259 258 if mode: 260 259 dnm_ = np.fromiter((np.sum(x[k:]*x[:-k])/np.sum(m[k:]*xx[:-k]) 261 for k in range(1,n)), 260 for k in range(1,n)), 262 261 dtype=float) 263 262 else: 264 263 dnm_ = np.fromiter((np.sum(x[k:]*x[:-k])/\ 265 264 np.sqrt((m[k:]*xx[:-k]).sum() * (m[:-k]*xx[k:]).sum()) 266 for k in range(1,n)), 265 for k in range(1,n)), 267 266 dtype=float) 268 267 poslags = _avf[1:]/dnm_ 269 return ma.fix_invalid(np.concatenate([np.array([1.]), 270 poslags, 268 return ma.fix_invalid(np.concatenate([np.array([1.]), 269 poslags, 271 270 poslags[::-1]])) 272 271 273 ##.............................................................................. 272 ##.............................................................................. 274 273 def acf_std(x, maxlag=None, periodogram=True, 275 274 confidence=0.6826895, simplified=True, acf_cached=None): 276 """Computes the approximate standard deviation of the autocorrelation 275 """Computes the approximate standard deviation of the autocorrelation 277 276 coefficients. 278 277 … … 280 279 Parameters 281 280 ---------- 282 x : ndarray 281 x : ndarray 283 282 Input data. 284 283 maxlag : {None, int} optional … … 286 285 periodogram : {True, False} 287 286 Whether to use a periodogram-like estimate of the ACF or not. 288 confidence : {0.6826895, float} optional 287 confidence : {0.6826895, float} optional 289 288 Confidence level. The default value returns the standard deviation. 290 289 simplified : {True, False} optional … … 292 291 acf_cached : {ndarray} optional 293 292 Pre-computed acf coefficients. 294 293 295 294 Notes 296 295 ----- … … 302 301 \begin{equation} 303 302 \begin{split} 304 var[r_k] &\approx 303 var[r_k] &\approx 305 304 \frac{1}{N} \sum_{j=-\infty}^{+\infty}{ \left\{ 306 305 r_{j}^2 + r_{j+k} r_{j-k} - 4 r_{k} r_{j} r_{j-k} + 2 r_{j}^2 r_{k}^2 … … 308 307 \frac{1}{N} \sum_{j=-\infty}^{+\infty}{ \left\{ 309 308 r_{j}^2 [ 1 + 2 r_{k}^2] + r_{j+k} r_{j-k} - 4 r_{k} r_{j} r_{j-k} 310 \right\} 309 \right\} 311 310 \end{split} 312 311 \end{equation} … … 348 347 ##.............................................................................. 349 348 def pacf(x, periodogram=True, lagmax=None): 350 """Computes the partial autocorrelation function of series `x` along 349 """Computes the partial autocorrelation function of series `x` along 351 350 the given axis. 352 351 … … 355 354 Time series. 356 355 periodogram : {True, False} optional 357 Whether to use a periodogram-like estimate of the ACF or not. 356 Whether to use a periodogram-like estimate of the ACF or not. 358 357 lagmax : {None, int} optional 359 358 Maximum lag. If None, the maximum lag is set to n/4+1, with n the series 360 length. 361 """ 359 length. 360 """ 362 361 acfx = acf(x, periodogram)[:,None] 363 362 # trunk/timeseries/scikits/timeseries/lib/interpolate.py
r1032 r1044 7 7 """ 8 8 __author__ = "Pierre GF Gerard-Marchant & Matt Knox ($Author$)" 9 __version__ = '1.0'10 9 __revision__ = "$Revision$" 11 10 __date__ = '$Date$' trunk/timeseries/scikits/timeseries/lib/moving_funcs.py
r1043 r1044 8 8 """ 9 9 __author__ = "Pierre GF Gerard-Marchant & Matt Knox ($Author$)" 10 __version__ = '0.67'11 10 __revision__ = "$Revision$" 12 11 __date__ = '$Date$' trunk/timeseries/scikits/timeseries/lib/plotlib.py
r1032 r1044 8 8 """ 9 9 __author__ = "Pierre GF Gerard-Marchant & Matt Knox ($Author$)" 10 __version__ = '0.67'11 10 __revision__ = "$Revision$" 12 11 __date__ = '$Date$' trunk/timeseries/scikits/timeseries/lib/reportlib.py
r1043 r1044 54 54 """ 55 55 __author__ = "Pierre GF Gerard-Marchant & Matt Knox ($Author$)" 56 __version__ = '0.67'57 56 __revision__ = "$Revision$" 58 57 __date__ = '$Date$' trunk/timeseries/scikits/timeseries/lib/tests/test_avcf.py
r956 r1044 8 8 """ 9 9 __author__ = "Pierre GF Gerard-Marchant ($Author: backtopop $)" 10 __version__ = '1.0'11 10 __revision__ = "$Revision: 55 $" 12 11 __date__ = '$Date: 2006-12-20 03:24:40 -0500 (Wed, 20 Dec 2006) $' … … 44 43 self.fdeaths = [901, 689, 827, 677, 522, 406, 441, 393, 387, 582, 578, 45 44 666, 830, 752, 785, 664, 467, 438, 421, 412, 343, 440, 46 531, 771, 767,1141, 896, 532, 447, 420, 376, 330, 357, 47 445, 546, 764, 862, 660, 663, 643, 502, 392, 411, 348, 48 387, 385, 411, 638, 796, 853, 737, 546, 530, 446, 431, 49 362, 387, 430, 425, 679, 821, 785, 727, 612, 478, 429, 45 531, 771, 767,1141, 896, 532, 447, 420, 376, 330, 357, 46 445, 546, 764, 862, 660, 663, 643, 502, 392, 411, 348, 47 387, 385, 411, 638, 796, 853, 737, 546, 530, 446, 431, 48 362, 387, 430, 425, 679, 821, 785, 727, 612, 478, 429, 50 49 405, 379, 393, 411, 487, 574] 51 50 self.mdeaths = ma.asarray(self.mdeaths) 52 51 self.fdeaths = ma.asarray(self.fdeaths) 53 52 54 53 # 55 54 def test_avf_nomasked(self): … … 87 86 assert_almost_equal(avfp[:21], 88 87 np.r_[[pz.var()], 89 [(pz[k:]*pz[:-k]).sum()/(mz[k:]*mz[:-k]).sum() 88 [(pz[k:]*pz[:-k]).sum()/(mz[k:]*mz[:-k]).sum() 90 89 for k in range(1,21)]]) 91 90 #...................................................... … … 97 96 assert_almost_equal(cvfmf[:16].round(), 98 97 [ 74941, 56473, 27961, -820,-29395,-47777,-52855, 99 -46871,-29427, -1390, 30090, 50403,55378, 49061, 98 -46871,-29427, -1390, 30090, 50403,55378, 49061, 100 99 27739,-260]) 101 100 assert_almost_equal(cvfmf[-15:].round(), 102 101 [ 1156, 28067, 47243, 54365, 47740, 26100, -1883, 103 -29299,-46964,-52031,-46368,-26827, 1517, 31105, 102 -29299,-46964,-52031,-46368,-26827, 1517, 31105, 104 103 57137,]) 105 104 #...................................................... … … 107 106 (mdeaths, fdeaths) = (self.mdeaths, self.fdeaths) 108 107 (mdeaths_, fdeaths_) = (mdeaths.copy(), fdeaths.copy()) 109 mdeaths_[0] = fdeaths_[-1] = ma.masked 108 mdeaths_[0] = fdeaths_[-1] = ma.masked 110 109 cvfmf = cvf(mdeaths_,fdeaths_) 111 110 assert_almost_equal(cvfmf[:16].round(4), … … 128 127 -0.046,-0.059, 0.068, 0.148, 0.061]) 129 128 mdeaths_ = mdeaths.copy() 130 mdeaths_[0] = ma.masked 129 mdeaths_[0] = ma.masked 131 130 pacfm = pacf(mdeaths_) 132 131 assert_almost_equal(pacfm[:19].round(3), trunk/timeseries/scikits/timeseries/lib/tests/test_interpolate.py
r768 r1044 5 5 """ 6 6 __author__ = "Pierre GF Gerard-Marchant & Matt Knox ($Author: matthew.brett@gmail.com $)" 7 __version__ = '1.0'8 7 __revision__ = "$Revision: 3836 $" 9 8 __date__ = '$Date: 2008-01-15 08:09:03 -0500 (Tue, 15 Jan 2008) $' trunk/timeseries/scikits/timeseries/lib/tests/test_moving_funcs.py
r1029 r1044 7 7 """ 8 8 __author__ = "Pierre GF Gerard-Marchant & Matt Knox ($Author: pierregm $)" 9 __version__ = '1.0'10 9 __revision__ = "$Revision: 2819 $" 11 10 __date__ = '$Date: 2007-03-03 18:00:20 -0500 (Sat, 03 Mar 2007) $' … … 77 76 assert(isinstance(ravg, MaskedArray)) 78 77 #!!!: __getitem__[int] used to return a TimeSeries, now returns an array 79 # assert_almost_equal(ravg[18]._series.squeeze(), 78 # assert_almost_equal(ravg[18]._series.squeeze(), 80 79 # data[18-k:18+k+1]._series.mean(0)) 81 assert_almost_equal(ravg[18].squeeze(), 80 assert_almost_equal(ravg[18].squeeze(), 82 81 data[18-k:18+k+1]._series.mean(0)) 83 82 m = np.zeros(data.shape, bool) trunk/timeseries/scikits/timeseries/setup.py
r1032 r1044 1 1 2 __version__ = '0.67'3 2 __revision__ = "$Revision$" 4 3 __date__ = '$Date$' trunk/timeseries/scikits/timeseries/tdates.py
r1043 r1044 10 10 11 11 __author__ = "Pierre GF Gerard-Marchant & Matt Knox" 12 __version__ = '1.0'13 12 __revision__ = "$Revision$" 14 13 __date__ = '$Date$' 15 16 14 17 15 import datetime as dt … … 20 18 import warnings 21 19 import types 22 23 20 24 21 import numpy as np … … 377 374 _result = np.empty(self.shape, dtype=np.object_) 378 375 _result.flat = [d.datetime for d in self.ravel()] 379 # for idx, val in numpy.ndenumerate(self):380 # operator.setitem(_result, idx, Date(freq=self.freq, value=val).datetime)381 376 return _result.tolist() 382 377 # … … 545 540 return self[-1] 546 541 return None 547 548 #............................549 542 550 543 nodates = DateArray([]) … … 644 637 if end_date is None: 645 638 if length is None: 646 # raise ValueError,"No length precised!"647 639 length = 1 648 640 else: trunk/timeseries/scikits/timeseries/tests/test_dates.py
r1036 r1044 7 7 """ 8 8 __author__ = "Pierre GF Gerard-Marchant ($Author: matthew.brett@gmail.com $)" 9 __version__ = '1.0'10 9 __revision__ = "$Revision: 3836 $" 11 10 __date__ = '$Date: 2008-01-15 08:09:03 -0500 (Tue, 15 Jan 2008) $' trunk/timeseries/scikits/timeseries/tests/test_extras.py
r941 r1044 8 8 """ 9 9 __author__ = "Pierre GF Gerard-Marchant & Matt Knox ($Author: matthew.brett@gmail.com $)" 10 __version__ = '1.0'11 10 __revision__ = "$Revision: 3836 $" 12 11 __date__ = '$Date: 2008-01-15 08:09:03 -0500 (Tue, 15 Jan 2008) $' 13 14 12 15 13 import numpy as np trunk/timeseries/scikits/timeseries/tests/test_timeseries.py
r1037 r1044 8 8 """ 9 9 __author__ = "Pierre GF Gerard-Marchant & Matt Knox ($Author: matthew.brett@gmail.com $)" 10 __version__ = '1.0'11 10 __revision__ = "$Revision: 3836 $" 12 11 __date__ = '$Date: 2008-01-15 08:09:03 -0500 (Tue, 15 Jan 2008) $' trunk/timeseries/scikits/timeseries/tests/test_trecords.py
r1029 r1044 7 7 """ 8 8 __author__ = "Pierre GF Gerard-Marchant & Matt Knox ($Author: matthew.brett@gmail.com $)" 9 __version__ = '1.0'10 9 __revision__ = "$Revision: 3836 $" 11 10 __date__ = '$Date: 2008-01-15 08:09:03 -0500 (Tue, 15 Jan 2008) $' … … 214 213 # 215 214 def setup(self): 216 a = time_series(np.random.rand(24), 215 a = time_series(np.random.rand(24), 217 216 start_date=ts.now('M')) 218 b = time_series(np.random.rand(24)*100, dtype=int, 217 b = time_series(np.random.rand(24)*100, dtype=int, 219 218 start_date=ts.now('M'),) 220 # c = time_series(["%02i" % _ for _ in np.arange(24)], 219 # c = time_series(["%02i" % _ for _ in np.arange(24)], 221 220 # start_date=ts.now('M')) 222 c = time_series(np.arange(24), 221 c = time_series(np.arange(24), 223 222 start_date=ts.now('M')) 224 223 trec = fromarrays([a,b,c], dates=a.dates, names='a,b,c') … … 235 234 for key in ('a','b','c'): 236 235 assert_equal(a_trec[key], base[key].convert('A', ma.mean)) 237 236 238 237 239 238 ############################################################################### trunk/timeseries/scikits/timeseries/trecords.py
r1032 r1044 8 8 """ 9 9 __author__ = "Pierre GF Gerard-Marchant & Matt Knox ($Author$)" 10 __version__ = '1.0'11 10 __revision__ = "$Revision$" 12 11 __date__ = '$Date$' … … 117 116 118 117 def __array_finalize__(self,obj): 119 self.__dict__.update(_varshape = getattr(obj, '_varshape', ()), 118 self.__dict__.update(_varshape = getattr(obj, '_varshape', ()), 120 119 _dates=getattr(obj,'_dates',DateArray([])), 121 120 _observed=getattr(obj,'_observed',None), … … 211 210 if self.size > 1: 212 211 mstr = ["(%s)" % ",".join([str(i) for i in s]) 213 for s in zip(*[getattr(self,f)._series 212 for s in zip(*[getattr(self,f)._series 214 213 for f in self.dtype.names])] 215 214 return "[%s]" % ", ".join(mstr) 216 215 else: 217 216 mstr = ["%s" % ",".join([str(i) for i in s]) 218 for s in zip([getattr(self,f)._series 217 for s in zip([getattr(self,f)._series 219 218 for f in self.dtype.names])] 220 219 return "(%s)" % ", ".join(mstr) … … 276 275 if a func is specified that requires additional keyword parameters, 277 276 specify them here. 278 277 279 278 """ 280 279 kwargs.update(func=func, position=position) 281 280 field_names = self.dtype.names 282 281 by_field = [self[f].convert(freq,**kwargs) for f in field_names] 283 output = fromarrays(by_field, 282 output = fromarrays(by_field, 284 283 dates=by_field[0].dates, 285 284 names=field_names) … … 421 420 #!!!: Anyway, we need to use numpy.io first, shouldn't we ? 422 421 #!!!: Using the kind of autodetermination of dtypes, or all-as-object 423 # err_msg = "trecords.fromtextfile is temporarily out of service.\n"\ 424 # "Please accept our apologies for any inconvenience." 425 # raise NotImplementedError(err_msg) 426 422 427 423 # Declare the pattern for the dates column 428 424 import re trunk/timeseries/scikits/timeseries/tseries.py
r1037 r1044 20 20 21 21 __author__ = "Pierre GF Gerard-Marchant & Matt Knox" 22 __version__ = '1.0'23 22 __revision__ = "$Revision$" 23 __date__ = '$Date$' 24 24 25 25 import sys … … 721 721 raise NotImplementedError(err_msg) 722 722 #!!!: We could also not do anything... 723 #result._dates = self._dates724 723 return result 725 724 … … 1063 1062 def __call__ (self, *args, **params): 1064 1063 raise NotImplementedError 1065 #TimeSeries.transpose = _tsarraymethod('transpose', ondates=True) 1064 1066 1065 TimeSeries.swapaxes = _tsarraymethod('swapaxes', ondates=True) 1067 1068 1066 1069 1067 #####--------------------------------------------------------------------------- … … 1480 1478 length=len(tmpdata), 1481 1479 freq=to_freq) 1482 # assert(get_varshape(tmpdata, newdates), newvarshape)1483 1480 1484 1481 newseries = tmpdata.view(type(series)) … … 1707 1704 err_msg = "fill_missing_dates is not yet implemented for nD series!" 1708 1705 raise NotImplementedError(err_msg) 1709 # if dates.ndim > 1 and dates.ndim == datad.ndim:1710 # datad.shape = -11711 1706 # ...and now, fill it ! ...... 1712 1707 (tstart, tend) = dflat[[0,-1]]
