本文整理汇总了Python中glue.core.data_collection.DataCollection.append方法的典型用法代码示例。如果您正苦于以下问题:Python DataCollection.append方法的具体用法?Python DataCollection.append怎么用?Python DataCollection.append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类glue.core.data_collection.DataCollection
的用法示例。
在下文中一共展示了DataCollection.append方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_data_files
# 需要导入模块: from glue.core.data_collection import DataCollection [as 别名]
# 或者: from glue.core.data_collection.DataCollection import append [as 别名]
def load_data_files(datafiles):
"""Load data files and return a DataCollection"""
from glue.core.data_collection import DataCollection
from glue.core.data_factories import auto_data, load_data
dc = DataCollection()
for df in datafiles:
dc.append(load_data(df, auto_data))
return dc
示例2: ParsedCommand
# 需要导入模块: from glue.core.data_collection import DataCollection [as 别名]
# 或者: from glue.core.data_collection.DataCollection import append [as 别名]
data.hub.broadcast(msg)
else:
pc = ParsedCommand(self._state[data][cid_new]['equation']._cmd, components)
link = ParsedComponentLink(cid_new, pc)
data.add_component_link(link)
# Findally, reorder components as needed
data.reorder_components(cids_all)
super(ArithmeticEditorWidget, self).accept()
if __name__ == "__main__": # pragma: nocover
from glue.utils.qt import get_qapp
app = get_qapp()
import numpy as np
from glue.core.data import Data
from glue.core.data_collection import DataCollection
x = np.random.random((5, 5))
y = x * 3
dc = DataCollection()
dc.append(Data(label='test1', x=x, y=y))
dc.append(Data(label='test2', a=x, b=y))
widget = ArithmeticEditorWidget(dc)
widget.exec_()
示例3: TestCommunication
# 需要导入模块: from glue.core.data_collection import DataCollection [as 别名]
# 或者: from glue.core.data_collection.DataCollection import append [as 别名]
class TestCommunication(object):
def setup_method(self, method):
self.data = Data(x=[1, 2, 3, 2, 2, 3, 1])
figure = MagicMock()
self.collect = DataCollection()
self.client = HistogramClient(self.collect, figure)
self.axes = self.client.axes
self.hub = self.collect.hub
self.connect()
def draw_count(self):
return self.axes.figure.canvas.draw.call_count
def connect(self):
self.client.register_to_hub(self.hub)
self.collect.register_to_hub(self.hub)
def test_ignore_data_add_message(self):
self.collect.append(self.data)
assert not (self.client.layer_present(self.data))
def test_update_data_ignored_if_data_not_present(self):
self.collect.append(self.data)
ct0 = self.draw_count()
self.data.style.color = 'blue'
assert self.draw_count() == ct0
def test_update_data_processed_if_data_present(self):
self.collect.append(self.data)
self.client.add_layer(self.data)
ct0 = self.draw_count()
self.data.style.color = 'blue'
assert self.draw_count() > ct0
def test_add_subset_ignored_if_data_not_present(self):
self.collect.append(self.data)
sub = self.data.new_subset()
assert not (self.client.layer_present(sub))
def test_add_subset_processed_if_data_present(self):
self.collect.append(self.data)
self.client.add_layer(self.data)
sub = self.data.new_subset()
assert (self.client.layer_present(sub))
def test_update_subset_ignored_if_not_present(self):
self.collect.append(self.data)
self.client.add_layer(self.data)
sub = self.data.new_subset()
self.client.remove_layer(sub)
ct0 = self.draw_count()
sub.style.color = 'blue'
assert self.draw_count() == ct0
def test_update_subset_processed_if_present(self):
self.collect.append(self.data)
self.client.add_layer(self.data)
sub = self.data.new_subset()
ct0 = self.draw_count()
sub.style.color = 'blue'
assert self.draw_count() > ct0
def test_data_remove_message(self):
self.collect.append(self.data)
self.client.add_layer(self.data)
self.collect.remove(self.data)
assert not self.client.layer_present(self.data)
def test_subset_remove_message(self):
self.collect.append(self.data)
self.client.add_layer(self.data)
sub = self.data.new_subset()
assert self.client.layer_present(sub)
sub.delete()
assert not self.client.layer_present(sub)
示例4: TestCategoricalHistogram
# 需要导入模块: from glue.core.data_collection import DataCollection [as 别名]
# 或者: from glue.core.data_collection.DataCollection import append [as 别名]
class TestCategoricalHistogram(TestHistogramClient):
def setup_method(self, method):
self.data = Data(y=[-1, -1, -1, -2, -2, -2, -3, -5, -7])
self.data.add_component(CategoricalComponent(['a', 'a', 'a', 'b', 'c', 'd', 'd', 'e', 'f']), 'x')
self.subset = self.data.new_subset()
self.collect = DataCollection(self.data)
self.client = HistogramClient(self.collect, FIGURE)
self.axes = self.client.axes
FIGURE.canvas.draw = MagicMock()
assert FIGURE.canvas.draw.call_count == 0
def test_xlimit_single_set(self):
self.client.add_layer(self.data)
self.client.set_component(self.data.id['x'])
self.client.xlimits = (None, 5)
assert self.client.xlimits == (-0.5, 5)
self.client.xlimits = (3, None)
assert self.client.xlimits == (3, 5)
def test_default_xlimits(self):
self.client.add_layer(self.data)
self.client.set_component(self.data.id['x'])
assert self.client.xlimits == (-0.5, 5.5)
self.client.set_component(self.data.id['y'])
assert self.client.xlimits == (-7, -1)
def test_change_default_bins(self):
self.client.add_layer(self.data)
self.client.set_component(self.data.id['x'])
assert self.client.nbins == 6
def test_tick_labels(self):
self.client.add_layer(self.data)
self.client.set_component(self.data.id['x'])
correct_labels = ['a', 'b', 'c', 'd', 'e', 'f']
formatter = self.client.axes.xaxis.get_major_formatter()
xlabels = [formatter.format_data(pos) for pos in range(6)]
assert correct_labels == xlabels
def test_apply_roi(self):
self.client.add_layer(self.data)
self.client.set_component(self.data.id['x'])
# bins are 1...4
self.data.edit_subset = [self.data.subsets[0]]
roi = MagicMock()
roi.to_polygon.return_value = [1.2, 2, 4], [2, 3, 4]
self.client.apply_roi(roi)
state = self.data.subsets[0].subset_state
assert isinstance(state, CategoricalROISubsetState)
np.testing.assert_equal(self.data.subsets[0].subset_state.roi.categories,
np.array(['b', 'c', 'd', 'e']))
# REMOVED TESTS
def test_xlog_axes_labels(self):
""" log-scale doesn't make sense for categorical data"""
pass
def test_xlog_snaps_limits(self):
""" log-scale doesn't make sense for categorical data"""
pass
def test_apply_roi_xlog(self):
""" log-scale doesn't make sense for categorical data"""
pass
def test_nbin_override_persists_over_attribute_change(self):
# regression test for #398
self.collect.append(self.data)
self.client.add_layer(self.data)
self.client.set_component(self.data.id['x'])
self.client.nbins = 7
self.client.set_component(self.data.id['y'])
assert self.client.nbins == 7
示例5: TestScatterClient
# 需要导入模块: from glue.core.data_collection import DataCollection [as 别名]
# 或者: from glue.core.data_collection.DataCollection import append [as 别名]
#.........这里部分代码省略.........
def plot_data(self, layer):
""" Return the data bounds for a given layer (data or subset)
Output format: [xmin, xmax], [ymin, ymax]
"""
client = self.client
x, y = client.artists[layer][0].get_data()
xmin = x.min()
xmax = x.max()
ymin = y.min()
ymax = y.max()
return [xmin, xmax], [ymin, ymax]
def plot_limits(self):
""" Return the plot limits
Output format [xmin, xmax], [ymin, ymax]
"""
ax = self.client.axes
xlim = ax.get_xlim()
ylim = ax.get_ylim()
return (min(xlim), max(xlim)), (min(ylim), max(ylim))
def assert_layer_inside_limits(self, layer):
"""Assert that points of a layer are within plot limits """
xydata = self.plot_data(layer)
xylimits = self.plot_limits()
assert xydata[0][0] >= xylimits[0][0]
assert xydata[1][0] >= xylimits[1][0]
assert xydata[0][1] <= xylimits[0][1]
assert xydata[1][1] <= xylimits[1][1]
def setup_2d_data(self):
d = Data(x=[[1, 2], [3, 4]], y=[[2, 4], [6, 8]])
self.collect.append(d)
self.client.add_layer(d)
self.client.xatt = d.id['x']
self.client.yatt = d.id['y']
return d
def add_data(self, data=None):
if data is None:
data = self.data[0]
data.edit_subset = data.new_subset()
self.collect.append(data)
self.client.add_data(data)
return data
def add_data_and_attributes(self):
data = self.add_data()
data.edit_subset = data.new_subset()
self.client.xatt = self.ids[0]
self.client.yatt = self.ids[1]
return data
def is_first_in_front(self, front, back):
z1 = self.client.get_layer_order(front)
z2 = self.client.get_layer_order(back)
return z1 > z2
def connect(self):
self.client.register_to_hub(self.hub)
self.collect.register_to_hub(self.hub)
def layer_drawn(self, layer):
return self.client.is_layer_present(layer) and \
all(a.enabled and a.visible for a in self.client.artists[layer])
示例6: receive_message
# 需要导入模块: from glue.core.data_collection import DataCollection [as 别名]
# 或者: from glue.core.data_collection.DataCollection import append [as 别名]
def receive_message(self, message):
""" Receives each DataMessage relay """
print " MyClient received a message \n"
# create objects
hub = Hub()
client = MyClient()
data = Data()
subset = data.new_subset()
data_collection = DataCollection()
# connect them to each other
data_collection.append(data)
data_collection.register_to_hub(hub)
client.register_to_hub(hub)
# manually send a DataMessage. Relayed to MyClient
print 'Manually sending DataMessage'
message = DataMessage(data)
hub.broadcast(message)
#modify the data object. Automatically generates a DataMessage
print 'Automatically triggering DataMessage'
data.label = "New label"
#send a SubsetMessage to the Hub.
print 'Manually sending SubsetMessage'
message = SubsetMessage(subset)