当前位置: 首页>>代码示例>>Python>>正文


Python timeseries.time_series函数代码示例

本文整理汇总了Python中scikits.timeseries.time_series函数的典型用法代码示例。如果您正苦于以下问题:Python time_series函数的具体用法?Python time_series怎么用?Python time_series使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了time_series函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_convert_to_annual

 def test_convert_to_annual(self):
     "Test convert_to_annual"
     base = dict(D=1, H=24, T=24 * 60, S=24 * 3600)
     #for fq in ('D', 'H', 'T', 'S'):
     # Don't test for minuTe and Second frequency, too time consuming.
     for fq in ('D', 'H'):
         dates = date_array(start_date=Date(fq, '2001-01-01 00:00:00'),
                            end_date=Date(fq, '2004-12-31 23:59:59'))
         bq = base[fq]
         series = time_series(range(365 * bq) * 3 + range(366 * bq),
                              dates=dates)
         control = ma.masked_all((4, 366 * bq), dtype=series.dtype)
         control[0, :58 * bq] = range(58 * bq)
         control[0, 59 * bq:] = range(58 * bq, 365 * bq)
         control[[1, 2]] = control[0]
         control[3] = range(366 * bq)
         test = convert_to_annual(series)
         assert_equal(test, control)
     #
     series = time_series(range(59, 365) + range(366) + range(365),
                          start_date=Date('D', '2003-03-01'))
     test = convert_to_annual(series)
     assert_equal(test[:, 59:62],
                  ma.masked_values([[-1, 59, 60], [59, 60, 61], [-1, 59, 60]],
                                   - 1))
开发者ID:ndawe,项目名称:scikit-timeseries,代码行数:25,代码来源:test_extras.py

示例2: op

def op(func,x,y,l='?'):
    logger.debug("TYPE XY=%s,%s",type(x),type(y))
    if type(x)!=Timeseries:
        if type(y)==Timeseries:
            return op(func,y,x,l)
        else:
            raise ValueError, "operands not timeseries"
    if type(x)==Timeseries:
        if type(y)==Timeseries:
            r = func(x,y)
            return r
        elif type(y) in (int,float,np.float64):
            _ts1 = x._data
            _ts2 = ts.time_series(_ts1, copy=True)
            _ts2.data.fill(y)
            _ts3 = ts.time_series(func(_ts1,_ts2),copy=True)
            try:
                _ts3.adjust_endpoints() #start_date=_ts1.start_date,end_date=_ts1.end_date)
            except ts.tseries.TimeSeriesError, exc:
                logger.debug("{TS OP} exception: %s",exc.value)
            _ts3.compressed()
            name='%s%s%s' % (x.name,l,str(y))
            if not _ts3.is_valid():
                _ts3.fill_missing_dates()
            _tr =Timeseries(data=_ts3,
                            name=name)
            return _tr

        logger.error("1 operand should be a Timeseries other could be number")
        raise ValueError, "1 operand should be a Timeseries other could be number (%s,%s)"%(type(x),type(y))
开发者ID:exedre,项目名称:e4t,代码行数:30,代码来源:__init__.py

示例3: test_convert

 def test_convert(self):
     series = self.series
     series.thresholds = (-0.5, +0.5)
     series.minimum_size = 5
     _cached = series._cachedmonthly.get('indices_monthly', None)
     self.failUnless(_cached is None)
     control = [ 0, 0, 0,+1,+1,+1,+1,+1,+1, 0,-1,-1,
                -1,-1,-1,-1,-1, 0, 0,-1,-1,-1,-1,-1,
                -1,+1,+1,+1,+1,+1,+1, 0, 0, 0, 0, 0,
                 0, 0, 0,-1,-1,-1,-1,-1, 0, 0,+1,+1,
                +1,+1,+1,+1,+1,+1,+1, 0, 0, 0, 0, 0,]
     control = ts.time_series(control, dates=series._dates)
     assert_equal(series.indices, control)
     # Convert to daily
     dseries = series.convert('D')
     dcontrol = ts.lib.backward_fill(control.convert('D'))
     assert_equal(dseries.indices, dcontrol)
     #
     control = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1,-1,
                -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
                -1,-1,-1,-1,-1,-1,-1,-1,-1,-1, 0, 0,
                 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,+1,+1,
                +1,+1,+1,+1,+1,+1,+1,+1,+1,+1, 0, 0,]
     control = ts.time_series(control, dates=series._dates)
     assert_equal(dseries.set_indices(full_year=True, reference_season='NDJ'),
                  ts.lib.backward_fill(control.convert('D')))
开发者ID:dacoex,项目名称:scikits.hydroclimpy,代码行数:26,代码来源:test_ensobase.py

示例4: common_ts_setup

def common_ts_setup():
    series2D = ts.time_series([np.random.rand(25).reshape(5,5),
                               np.random.rand(25).reshape(5,5),
                               np.random.rand(25).reshape(5,5),
                               np.random.rand(25).reshape(5,5),
                               np.random.rand(25).reshape(5,5),],
                              start_date=ts.now('M'),
                              mask=[np.random.rand(25).reshape(5,5)>.5,
                                    np.random.rand(25).reshape(5,5)>.5,
                                    np.random.rand(25).reshape(5,5)>.5,
                                    np.random.rand(25).reshape(5,5)>.5,
                                    np.random.rand(25).reshape(5,5)>.5,]
                             ) 
    series1D = ts.time_series(np.random.rand(25),
                              mask=np.random.rand(25)>0.7,
                              start_date=ts.now('M'),
                              fill_value=-999)
    series5V = ts.time_series(np.random.rand(25).reshape(5,5),
                              mask=np.random.rand(25).reshape(5,5)>0.7,
                              start_date=ts.now('M'))
    series5N = ts.time_series(zip(np.random.rand(5),
                                  np.random.rand(5),
                                  np.arange(5)),
                              start_date=ts.now('M'),
                              dtype=[('a',float),('b',float),('c',int)]
                              )
    return dict(series1D=series1D, 
                series5V=series5V,
                series2D=series2D,
                series5N=series5N)
开发者ID:ndawe,项目名称:scikit-timeseries,代码行数:30,代码来源:test_tstables.py

示例5: setup

    def setup(self):
        a = time_series(np.random.rand(24),
                        start_date=ts.now('M'))
        b = time_series(np.random.rand(24) * 100, dtype=int,
                        start_date=ts.now('M'),)
#        c = time_series(["%02i" % _ for _ in np.arange(24)],
#                         start_date=ts.now('M'))
        c = time_series(np.arange(24),
                         start_date=ts.now('M'))
        trec = fromarrays([a, b, c], dates=a.dates, names='a,b,c')
        self.info = (a, b, c, trec)
开发者ID:B-Rich,项目名称:scikits.timeseries-sandbox,代码行数:11,代码来源:test_trecords.py

示例6: test_get_field_asattribute

 def test_get_field_asattribute(self):
     "Tests item retrieval"
     [d, m, mrec, dlist, dates, mts, rts] = self.data
     self.failUnless(isinstance(rts.f0, TimeSeries))
     self.failUnless(not isinstance(rts[0], TimeSeriesRecords))
     assert_equal(rts.f0, time_series(d, dates=dates, mask=m))
     assert_equal(rts.f1, time_series(d[::-1], dates=dates, mask=m[::-1]))
     self.failUnless((rts._mask == nr.fromarrays([m, m[::-1]])).all())
     # Was _mask, now is recordmask
     assert_equal(rts.recordmask, np.r_[[m, m[::-1]]].all(0))
     assert_equal(rts.f0[1], rts[1].f0)
开发者ID:B-Rich,项目名称:scikits.timeseries-sandbox,代码行数:11,代码来源:test_trecords.py

示例7: setUp

 def setUp(self):
     (a, b) = (np.arange(10), np.random.rand(10))
     ndtype = [('a', np.float), ('b', np.float)]
     tarr = ts.time_series(np.array(zip(a, b), dtype=ndtype),
                           start_date=ts.now('M'))
     tarr.mask[3] = (False, True)
     self.data = (tarr, a, b)
开发者ID:B-Rich,项目名称:scikits.timeseries-sandbox,代码行数:7,代码来源:test_trecords.py

示例8: test_sorted

 def test_sorted(self):
     dates = [ts.Date('D', string='2007-01-%02i' % i) for i in (3, 2, 1)]
     (a, b) = zip(*[(3., 30), (2., 20), (1., 10), ])
     ndtype = [('a', np.float), ('b', np.int)]
     controldates = date_array(dates, freq='D')
     controldates.sort_chronologically()
     series = time_series(zip(*(a, b)), dates, freq='D', dtype=ndtype)
     assert_equal(series._data.tolist(), [(1., 10), (2., 20), (3., 30)])
     assert_equal(series._dates, controldates)
     #
     trec = time_records(zip(*(a, b)), dates, freq='D', dtype=ndtype)
     assert_equal(trec._data.tolist(), [(1., 10), (2., 20), (3., 30)])
     assert_equal(trec._dates, controldates)
     assert_equal(trec['a'], [1., 2., 3.])
     assert_equal(trec.a, [1., 2., 3.])
     #
     trec = fromrecords(zip(a, b), dates, names=('a', 'b'))
     assert_equal(trec._data.tolist(), [(1., 10), (2., 20), (3., 30)])
     assert_equal(trec._dates, controldates)
     assert_equal(trec['a'], [1., 2., 3.])
     assert_equal(trec.a, [1., 2., 3.])
     #
     trec = fromarrays([a, b], dates, names=('a', 'b'))
     assert_equal(trec._data.tolist(), [(1., 10), (2., 20), (3., 30)])
     assert_equal(trec._dates, controldates)
     assert_equal(trec['a'], [1., 2., 3.])
     assert_equal(trec.a, [1., 2., 3.])
开发者ID:B-Rich,项目名称:scikits.timeseries-sandbox,代码行数:27,代码来源:test_trecords.py

示例9: gen_ts_from_tpm

def gen_ts_from_tpm(tpm, bin_width, length, freq='T'):
    """
    Create timeseries using a Transisiton Probability Matrix
    INPUT: tpm  = ndarray of n*n values
           length (int)
    OUTPUT: tseries = timeseries of length
    """
    ## Create cumulative matrix from tpm
    cumu_tpm = gen_cumu_tpm(tpm)
    
    ## Initial wind range starts near median
    source_bin = int(len(cumu_tpm) / 2)

    ## Create empty array for wind speed data
    tseries_data = []

    ## Create wind speed data
    for index in range(length):
        ## Find wind range that random number falls into
        destination_bin = weighted_choice(cumu_tpm[source_bin])
        
        ## Create random wind speed within range of destination bin
        wind_speed = (destination_bin + np.random.uniform()) * bin_width
        
        ## Add wind speed to timeseries
        tseries_data.append(wind_speed)
        
        ## Destination bin becomes source bin
        source_bin = destination_bin
    
    ## Create timeseries out of tseries_data and freq
    tseries = ts.time_series(data=tseries_data, 
    start_date="01-01-2001",freq=freq)
    
    return tseries
开发者ID:kmonsoor,项目名称:windenergytk,代码行数:35,代码来源:synthesis.py

示例10: test_apply_on_fields_series

 def test_apply_on_fields_series(self):
     "Test apply_on_fields w/ time_series"
     adtype = [('fi', int), ('ff', float)]
     a = ts.time_series([(1, 1.), (2, 2.), (3, 3.)],
                        mask=[(0, 0), (0, 1), (0, 0)],
                        dtype=adtype,
                        start_date=ts.now('M'))
     func = ma.cumsum
     test = apply_on_fields(a, func)
     control = ts.time_series([(1, 1.), (3, -1), (6, 4.)],
                              mask=[(0, 0), (0, 1), (0, 0)],
                              dtype=adtype,
                              start_date=ts.now('M'))
     assert_equal(test, control)
     self.failUnless(isinstance(test, ts.TimeSeries))
     assert_equal(test.dates, control.dates)
开发者ID:dacoex,项目名称:scikits.hydroclimpy,代码行数:16,代码来源:test_tsaddons.py

示例11: setUp

 def setUp(self):
     "Setting common information"
     try:
         from BeautifulSoup import BeautifulSoup, SoupStrainer
     except ImportError:
         self.indices = None
         return
     # Load the file as a tree, but only take the SST table (border=1)
     from urllib import urlopen
     url = "http://www.cpc.noaa.gov/products/analysis_monitoring/"\
           "ensostuff/ensoyears.shtml"
     url = urlopen(url)
     table = BeautifulSoup(url.read(),
                           parseOnlyThese=SoupStrainer("table", border=1))
     # Separate it by rows, but skip the first one (the header)
     years = []
     indices = []
     color = dict(red=+1, white=0, blue=-1)
     deft = [(None,'color:white')]
     for row in table.findAll("tr")[1:]:
         cols = row.findAll('td')
         years.append(int(cols.pop(0).strong.string))
         indices.append([color[getattr(_.span, 'attrs', deft)[0][-1].split(':')[-1]]
                         for _ in cols])
     start_date = ts.Date('M', year=years[0], month=1)
     self.indices = time_series(np.array(indices).ravel(),
                                start_date=start_date)
开发者ID:dacoex,项目名称:scikits.hydroclimpy,代码行数:27,代码来源:test_ensodata.py

示例12: tseries

 def tseries(self,_freq,*_args):
     args=_args[0]
     logger.debug('{TSERIES} freq=%s %s',_freq,args)
     if _freq == 'Q':
         year    = int(args[0])
         quarter = int(args[1])
         vals    = [ float(v) for v in args[2:] ]
         freq="Q"
         start   = ts.Date(freq="Q", year=year,quarter=quarter)
     elif _freq == 'M':
         freq="M"
         year  = int(args[0])
         month = int(args[1])
         vals  = [ float(v) for v in args[2:] ]
         start = ts.Date(freq=freq,
                         year=year,
                         month=month)
     else:
         raise ValueError, "FREQUENZA NON PREVISTA in TSERIES"
     logger.debug('{TSERIES} %s',start)
     _ts =  ts.time_series(vals,
                           freq=freq,
                           start_date=start)
     _res = ets.Timeseries(data=_ts)
     return _res
开发者ID:exedre,项目名称:e4t,代码行数:25,代码来源:FunctionProcessor.py

示例13: block_average

def block_average(timeseries, new_freq=''):
    """
    Reduce size of timeseries by taking averages of larger block size.
    Input: timeseries, new_freq (str) See scikits.timeseries doc
    Output: block averaged timeseries obj. in new frequency
    """
    # Label timeseries data with new frequency
    # ie: [5.5, 4.5] | [13-May-2009 11:40 13-May-2009 11:50] becomes
    #     [5.5, 4.5] | [13-May-2009 13-May-2009]
    timeseries = timeseries.asfreq(new_freq)

    # Create empty arrays, set first block_time
    current_block_values = []
    averages = []
    timesteps = []
    current_block_time = timeseries.dates[0]

    # For each index in timeseries, if the block of time has changed,
    # average the previous block values.  Otherwise keep adding
    # values to be averaged.
    for index in range(0,len(timeseries)):
        if current_block_time != timeseries.dates[index]:
            averages.append(npmean(current_block_values))
            timesteps.append(current_block_time)
            current_block_values = []
            current_block_time = timeseries.dates[index]
        current_block_values.append(timeseries[index])
    # Take average for last (or only) time block
    if current_block_values:
        averages.append(npmean(current_block_values))
        timesteps.append(current_block_time)
        

    # Return new block averages and timesteps as timeseries object
    return ts.time_series(averages,dates=timesteps)
开发者ID:kmonsoor,项目名称:windenergytk,代码行数:35,代码来源:analysis.py

示例14: get_irt_data

def get_irt_data(date1, date2):
    import sqlite3
    from scipy.signal import medfilt
    DB_FILE = "/home/Work/magn/IRT.sqlite"
    try:
        conn = sqlite3.connect(DB_FILE)
    except OperationalError:
        print "Cannot find database!"
        return
    cursor = conn.cursor()
    # считываем
    cursor.execute("""
        SELECT intdt, f
        FROM irt_vectordata WHERE intdt BETWEEN ? AND ?
        ORDER BY intdt ASC
        """, (
            ts.Date('T', datetime=date1).value,#series.dates[0].datetime).value,
            ts.Date('T', datetime=date2).value+1,
        )
    )
    #print date1, date2
    _dates, _values = zip(*cursor.fetchall())
    conn.close()
    #print "get series from values and dates"
    series = ts.time_series(medfilt(_values), dates=_dates, freq='T')
    # скроем пропуски = 99999.0
    series[(series==99999)]=np.ma.masked
    return series.compressed()
开发者ID:cormorant,项目名称:stuff_code,代码行数:28,代码来源:tektmagn.py

示例15: a0002

    def a0002(self,ts1,*_args):
        """Funzione usata in CHEXTERNAL-A11
        Fino al duemila dieci
        
        in CHACTIVITY la seconda è shift(1) indietro"""
        args=_args[0]        
        _t1 = ts1._data
        _ts =  ts.time_series(_t1,copy=True)
        _da = _ts.dates
        _c = 0
        for _i,_d in enumerate(_da[:-1]):
            _p = _i % 4
            if _d.year<2010:
                if _p == 0:
                    _c = _ts[_d+1] / 2.0
                    _ts[_d]=_c
                elif _p == 2:
                    _c = (_ts[_d+1] - 2*_ts[_d-1]) / 2.0
                    _ts[_d]=_c
                else:
                    _ts[_d]=_c
            elif _d.year>=2010:
                if _p > 0:
                    _c_ = _ts[_d]
                    _ts[_d]=_ts[_d]-_c
                    _c = _c_
                else:
                    _c = _ts[_d]
#        _report(ts1._data,_ts)
        _res = ets.Timeseries(data=_ts)
        return _res
开发者ID:exedre,项目名称:e4t,代码行数:31,代码来源:FunctionProcessor.py


注:本文中的scikits.timeseries.time_series函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。