本文整理汇总了Python中orangecontrib.timeseries.Timeseries类的典型用法代码示例。如果您正苦于以下问题:Python Timeseries类的具体用法?Python Timeseries怎么用?Python Timeseries使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Timeseries类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: set_data
def set_data(self, data):
# TODO: set xAxis resolution and tooltip time contents depending on
# data.time_delta. See: http://imgur.com/yrnlgQz
# If the same data is updated, short circuit to just updating the chart,
# retaining all panels and list view selections ...
if data is not None and self.data is not None and data.domain == self.data.domain:
self.data = Timeseries.from_data_table(data)
for config in self.configs:
config.selection_changed()
return
self.data = data = None if data is None else Timeseries.from_data_table(data)
if data is None:
self.varmodel.clear()
self.chart.clear()
return
if getattr(data.time_variable, 'utc_offset', False):
offset_minutes = data.time_variable.utc_offset.total_seconds() / 60
self.chart.evalJS('Highcharts.setOptions({global: {timezoneOffset: %d}});' % -offset_minutes) # Why is this negative? It works.
self.chart.chart()
self.chart.setXAxisType(
'datetime'
if (data.time_variable and
(getattr(data.time_variable, 'have_date', False) or
getattr(data.time_variable, 'have_time', False))) else
'linear')
self.varmodel.wrap([var for var in data.domain.variables
if var.is_continuous and var != data.time_variable])
示例2: finance_data
def finance_data(symbol,
since=None,
until=None,
granularity='d'):
"""Fetch Yahoo Finance data for stock or index `symbol` within the period
after `since` and before `until` (both inclusive).
Parameters
----------
symbol: str
A stock or index symbol, as supported by Yahoo Finance.
since: date
A start date (default: 1900-01-01).
until: date
An end date (default: today).
granularity: 'd' or 'w' or 'm' or 'v'
What data to get: daily, weekly, monthly, or dividends.
Returns
-------
data : Timeseries
"""
if since is None:
since = date(1900, 1, 1)
if until is None:
until = date.today()
YAHOO_URL = ('http://chart.finance.yahoo.com/table.csv?'
's={SYMBOL}&d={TO_MONTH}&e={TO_DAY}&f={TO_YEAR}&'
'g={GRANULARITY}&a={FROM_MONTH}&b={FROM_DAY}&c={FROM_YEAR}&ignore=.csv')
url = YAHOO_URL.format(SYMBOL=symbol,
GRANULARITY=granularity,
TO_MONTH=until.month - 1,
TO_DAY=until.day,
TO_YEAR=until.year,
FROM_MONTH=since.month - 1,
FROM_DAY=since.day,
FROM_YEAR=since.year)
data = Timeseries.from_url(url)[::-1]
# Make Adjusted Close a class variable
attrs = [var.name for var in data.domain.attributes]
attrs.remove('Adj Close')
data = Timeseries(Domain(attrs, [data.domain['Adj Close']], None, source=data.domain), data)
data.name = symbol
data.time_variable = data.domain['Date']
return data
示例3: test_nan_timeseries
def test_nan_timeseries(self):
"""
Widget used to crash because interpolation crashed when
there was a column with all nans or all nuns and only one number.
Now interpolation is skipped.
GH-27
"""
time_series = Timeseries(
Domain(attributes=[ContinuousVariable("a"), ContinuousVariable("b")]),
list(zip(list(range(5)), list(range(5))))
)
time_series.X[:, 1] = np.nan
self.send_signal(self.widget.Inputs.time_series, time_series)
time_series.X[2, 1] = 42
self.send_signal(self.widget.Inputs.time_series, time_series)
示例4: set_data
def set_data(self, data):
slider = self.slider
self.data = data = None if data is None else Timeseries.from_data_table(data)
def disabled():
slider.setFormatter(str)
slider.setHistogram(None)
slider.setScale(0, 0)
slider.setValues(0, 0)
slider.setDisabled(True)
self.send('Subset', None)
if data is None:
disabled()
return
if not isinstance(data.time_variable, TimeVariable):
self.Error.no_time_variable()
disabled()
return
self.Error.clear()
var = data.time_variable
time_values = np.ravel(data[:, var])
# Save values for handler
slider.time_values = time_values
slider.setDisabled(False)
slider.setHistogram(time_values)
slider.setFormatter(var.repr_val)
slider.setScale(time_values.min(), time_values.max())
self.valuesChanged(slider.minimumValue(), slider.maximumValue())
示例5: quandl_data
def quandl_data(symbol,
since=None,
until=None,
*,
collapse='daily',
api_key=''):
"""
Parameters
----------
symbol
since
until
collapse: none|daily|weekly|monthly|quarterly|annual
api_key
Returns
-------
"""
if since is None:
since = date(1900, 1, 1).isoformat()
if until is None:
until = date.today().isoformat()
QUANDL_URL = ('https://www.quandl.com/api/v3/datasets/WIKI/{SYMBOL}/data.csv?'
'start_date={START_DATE}&end_date={END_DATE}&order=asc&'
'collapse={COLLAPSE}&transform=rdiff&api_key={API_KEY}')
url = QUANDL_URL.format(SYMBOL=symbol,
START_DATE=since,
END_DATE=until,
COLLAPSE=collapse,
API_KEY=api_key)
ts = Timeseries.from_url(url)
return ts
示例6: _as_table
def _as_table(self, values, what):
"""Used for residuals() and fittedvalues() methods."""
from Orange.data import Domain, ContinuousVariable
attrs = []
n_vars = values.shape[1] if values.ndim == 2 else 1
if n_vars == 1:
values = np.atleast_2d(values).T
tvar = None
# If 1d, time var likely not already present, so lets add it if possible
if n_vars == 1 and self._table_timevar:
values = np.column_stack((self._table_timevals[-values.shape[0]:],
values))
tvar = self._table_timevar
attrs.append(tvar)
for i, name in zip(range(n_vars),
self._table_var_names or range(n_vars)):
attrs.append(ContinuousVariable('{} ({})'.format(name, what)))
# Make the fitted time variable time variable
if self._table_timevar and self._table_timevar.name == name:
tvar = attrs[-1]
table = Timeseries.from_numpy(Domain(attrs), values)
table.time_variable = tvar
table.name = (self._table_name or '') + '({} {})'.format(self, what)
return table
示例7: set_data
def set_data(self, data):
self.data = data = None if data is None else Timeseries.from_data_table(data)
def init_combos():
for combo in (self.combo_ax1, self.combo_ax2):
combo.clear()
self.attrlist_model[:] = []
for i in Spiralogram.AxesCategories:
for combo in (self.combo_ax1, self.combo_ax2):
combo.addItem(_enum_str(i))
for var in data.domain if data is not None else []:
if (var.is_primitive() and
(var is not data.time_variable or
isinstance(var, TimeVariable) and data.time_delta is None)):
self.attrlist_model.append(var)
if var.is_discrete:
for combo in (self.combo_ax1, self.combo_ax2):
combo.addItem(gui.attributeIconDict[var], var.name)
init_combos()
self.chart.clear()
if data is None:
self.commit()
return
self.ax1 = 'months of year'
self.ax2 = 'years'
self.replot()
示例8: set_data
def set_data(self, data):
self.data = data = None if data is None else Timeseries.from_data_table(data)
self.add_button.setDisabled(not len(getattr(data, 'domain', ())))
self.table_model.clear()
if data is not None:
self.var_model.wrap([var for var in data.domain
if var.is_continuous and var is not data.time_variable])
self.on_changed()
示例9: commit
def commit(self):
data = self.data
if not data or not self.selected:
self.send(Output.TIMESERIES, data)
return
selected_subset = Timeseries(Domain(self.selected, source=data.domain), data) # FIXME: might not pass selected interpolation method
with self.progressBar(len(self.selected)) as progress:
adjusted_data = seasonal_decompose(
selected_subset,
self.DECOMPOSITION_MODELS[self.decomposition],
self.n_periods,
callback=lambda *_: progress.advance())
ts = Timeseries(Timeseries.concatenate((data, adjusted_data)))
ts.time_variable = data.time_variable
self.send(Output.TIMESERIES, ts)
示例10: test_output_metas
def test_output_metas(self):
"""
Do not create 3-dimensional numpy metas array.
GH-44
"""
w = self.widget
data = Timeseries("airpassengers")
new_domain = Domain(
attributes=data.domain.attributes,
class_vars=data.domain.class_vars,
metas=[DiscreteVariable("meta", values=["0"])]
)
data = data.transform(new_domain)
data.metas = np.zeros((144, 1), dtype=object)
self.assertEqual(len(data.metas.shape), 2)
self.send_signal(w.Inputs.time_series, data)
w.controls.autocommit.click()
output = self.get_output(w.Outputs.time_series)
self.assertEqual(len(output.metas.shape), 2)
示例11: commit
def commit(self):
data = self.data
if not data or not len(self.selected):
self.send(Output.TIMESERIES, None)
return
X = []
attrs = []
invert = self.invert_direction
shift = self.shift_period
order = self.diff_order
for var in self.selected:
col = np.ravel(data[:, var])
if invert:
col = col[::-1]
out = np.empty(len(col))
if shift == 1:
out[:-order] = np.diff(col, order)
out[-order:] = np.nan
else:
out[:-shift] = col[shift:] - col[:-shift]
out[-shift:] = np.nan
if invert:
out = out[::-1]
X.append(out)
template = '{} (diff; {})'.format(var,
'order={}'.format(order) if shift == 1 else
'shift={}'.format(shift))
name = available_name(data.domain, template)
attrs.append(ContinuousVariable(name))
ts = Timeseries(Domain(data.domain.attributes + tuple(attrs),
data.domain.class_vars,
data.domain.metas),
np.column_stack((data.X, np.column_stack(X))),
data.Y, data.metas)
ts.time_variable = data.time_variable
self.send(Output.TIMESERIES, ts)
示例12: commit
def commit(self):
data = self.data
self.Error.clear()
if data is None or (self.selected_attr not in data.domain and not self.radio_sequential):
self.Outputs.time_series.send(None)
return
attrs = data.domain.attributes
cvars = data.domain.class_vars
metas = data.domain.metas
X = data.X
Y = np.column_stack((data.Y,)) # make 2d
M = data.metas
# Set sequence attribute
if self.radio_sequential:
for i in chain(('',), range(10)):
name = '__seq__' + str(i)
if name not in data.domain:
break
time_var = ContinuousVariable(name)
attrs = attrs.__class__((time_var,)) + attrs
X = np.column_stack((np.arange(1, len(data) + 1), X))
data = Table(Domain(attrs, cvars, metas), X, Y, M)
else:
# Or make a sequence attribute one of the existing attributes
# and sort all values according to it
time_var = data.domain[self.selected_attr]
values = Table.from_table(Domain([], [], [time_var]),
source=data).metas.ravel()
if np.isnan(values).any():
self.Error.nan_times(time_var.name)
self.Outputs.time_series.send(None)
return
ordered = np.argsort(values)
if (ordered != np.arange(len(ordered))).any():
data = data[ordered]
ts = Timeseries(data.domain, data)
# TODO: ensure equidistant
ts.time_variable = time_var
self.Outputs.time_series.send(ts)
示例13: set_data
def set_data(self, data):
self.data = data = None if data is None else Timeseries.from_data_table(data)
self.all_attrs = []
if data is None:
self.plot.clear()
return
self.all_attrs = [(var.name, gui.attributeIconDict[var])
for var in data.domain
if (var is not data.time_variable and
isinstance(var, ContinuousVariable))]
self.attrs = [0]
self.on_changed()
示例14: set_data
def set_data(self, data):
self.data = data = None if data is None else Timeseries.from_data_table(data)
def init_combos():
for model in (self.combo_ax1_model, self.combo_ax2_model):
model.clear()
newmodel = []
if data is not None and data.time_variable is not None:
for model in (self.combo_ax1_model, self.combo_ax2_model):
model[:] = [_enum_str(i) for i in Spiralogram.AxesCategories]
for var in data.domain.variables if data is not None else []:
if (var.is_primitive() and
(var is not data.time_variable or
isinstance(var, TimeVariable) and data.time_delta is None)):
newmodel.append(var)
if var.is_discrete:
for model in (self.combo_ax1_model, self.combo_ax2_model):
model.append(var)
self.attrlist_model.wrap(newmodel)
init_combos()
self.chart.clear()
if data is None:
self.commit()
return
self.closeContext()
self.ax2 = next((self.combo_ax2.itemText(i)
for i in range(self.combo_ax2.count())), '')
self.ax1 = next((self.combo_ax1.itemText(i)
for i in range(1, self.combo_ax1.count())), self.ax2)
self.agg_attr = [data.domain.variables[0]] if len(data.domain.variables) else []
self.agg_func = 0
if getattr(data, 'time_variable', None) is not None:
self.openContext(data.domain)
if self.agg_attr:
self.attrlist.blockSignals(True)
self.attrlist.selectionModel().clear()
for attr in self.agg_attr:
try:
row = self.attrlist_model.indexOf(attr)
except ValueError:
continue
self.attrlist.selectionModel().select(
self.attrlist_model.index(row),
QItemSelectionModel.SelectCurrent)
self.attrlist.blockSignals(False)
self.replot()
示例15: finance_data
def finance_data(symbol,
since=None,
until=None,
granularity='d'):
"""Fetch Yahoo Finance data for stock or index `symbol` within the period
after `since` and before `until` (both inclusive).
Parameters
----------
symbol: str
A stock or index symbol, as supported by Yahoo Finance.
since: date
A start date (default: 1900-01-01).
until: date
An end date (default: today).
granularity: 'd' or 'w' or 'm' or 'v'
What data to get: daily, weekly, monthly, or dividends.
Returns
-------
data : Timeseries
"""
if since is None:
since = date(1900, 1, 1)
if until is None:
until = date.today()
f = web.DataReader(symbol, 'yahoo', since, until)
data = Timeseries(table_from_frame(f))
# Make Adjusted Close a class variable
attrs = [var.name for var in data.domain.attributes]
attrs.remove('Adj Close')
data = Timeseries(Domain(attrs, [data.domain['Adj Close']], None, source=data.domain), data)
data.name = symbol
data.time_variable = data.domain['Date']
return data