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


Python DataCollection.add_link方法代码示例

本文整理汇总了Python中glue.core.DataCollection.add_link方法的典型用法代码示例。如果您正苦于以下问题:Python DataCollection.add_link方法的具体用法?Python DataCollection.add_link怎么用?Python DataCollection.add_link使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在glue.core.DataCollection的用法示例。


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

示例1: qglue

# 需要导入模块: from glue.core import DataCollection [as 别名]
# 或者: from glue.core.DataCollection import add_link [as 别名]
def qglue(**kwargs):
    """
    Quickly send python variables to Glue for visualization.

    The generic calling sequence is::

      qglue(label1=data1, label2=data2, ..., [links=links])

    The kewyords label1, label2, ... can be named anything besides ``links``

    data1, data2, ... can be in many formats:
      * A pandas data frame
      * A path to a file
      * A numpy array, or python list
      * A numpy rec array
      * A dictionary of numpy arrays with the same shape
      * An astropy Table

    ``Links`` is an optional list of link descriptions, each of which has
    the format: ([left_ids], [right_ids], forward, backward)

    Each ``left_id``/``right_id`` is a string naming a component in a dataset
    (i.e., ``data1.x``). ``forward`` and ``backward`` are functions which
    map quantities on the left to quantities on the right, and vice
    versa. `backward` is optional

    Examples::

        balls = {'kg': [1, 2, 3], 'radius_cm': [10, 15, 30]}
        cones = {'lbs': [5, 3, 3, 1]}
        def lb2kg(lb):
            return lb / 2.2
        def kg2lb(kg):
            return kg * 2.2

        links = [(['balls.kg'], ['cones.lbs'], lb2kg, kg2lb)]
        qglue(balls=balls, cones=cones, links=links)

    :returns: A :class:`~glue.app.qt.application.GlueApplication` object
    """
    from glue.core import DataCollection
    from glue.app.qt import GlueApplication

    links = kwargs.pop('links', None)

    dc = DataCollection()
    for label, data in kwargs.items():
        dc.extend(parse_data(data, label))

    if links is not None:
        dc.add_link(parse_links(dc, links))

    with restore_io():
        ga = GlueApplication(dc)
        ga.start()

    return ga
开发者ID:glue-viz,项目名称:glue,代码行数:59,代码来源:qglue.py

示例2: test_1d_world_link

# 需要导入模块: from glue.core import DataCollection [as 别名]
# 或者: from glue.core.DataCollection import add_link [as 别名]
def test_1d_world_link():
    x, y = r(10), r(10)
    d1 = Data(label='d1', x=x)
    d2 = Data(label='d2', y=y)
    dc = DataCollection([d1, d2])

    dc.add_link(LinkSame(d2.get_world_component_id(0), d1.id['x']))

    assert d2.get_world_component_id(0) in d1.components
    np.testing.assert_array_equal(d1[d2.get_world_component_id(0)], x)
    np.testing.assert_array_equal(d1[d2.get_pixel_component_id(0)], x)
开发者ID:DougBurke,项目名称:glue,代码行数:13,代码来源:test_links.py

示例3: test_2d_world_link

# 需要导入模块: from glue.core import DataCollection [as 别名]
# 或者: from glue.core.DataCollection import add_link [as 别名]
def test_2d_world_link():
    """Should be able to grab pixel coords after linking world"""

    x, y = r(10), r(10)
    cat = Data(label='cat', x=x, y=y)
    im = Data(label='im', inten=r((3, 3)))

    dc = DataCollection([cat, im])

    dc.add_link(LinkSame(im.get_world_component_id(0), cat.id['x']))
    dc.add_link(LinkSame(im.get_world_component_id(1), cat.id['y']))

    np.testing.assert_array_equal(cat[im.get_pixel_component_id(0)], x)
    np.testing.assert_array_equal(cat[im.get_pixel_component_id(1)], y)
开发者ID:DougBurke,项目名称:glue,代码行数:16,代码来源:test_links.py

示例4: test_link_aligned

# 需要导入模块: from glue.core import DataCollection [as 别名]
# 或者: from glue.core.DataCollection import add_link [as 别名]
def test_link_aligned(ndata, ndim):
    ds = []
    shp = tuple([2] * ndim)
    for i in range(ndata):
        d = Data()
        c = Component(np.random.random(shp))
        d.add_component(c, 'test')
        ds.append(d)

    # assert that all componentIDs are interchangeable
    links = LinkAligned(ds)
    dc = DataCollection(ds)
    dc.add_link(links)

    for i in range(ndim):
        id0 = ds[0].get_pixel_component_id(i)
        for j in range(1, ndata):
            id1 = ds[j].get_pixel_component_id(i)
            np.testing.assert_array_equal(ds[j][id0], ds[j][id1])
开发者ID:antonl,项目名称:glue,代码行数:21,代码来源:test_link_helpers.py

示例5: _load_data_collection

# 需要导入模块: from glue.core import DataCollection [as 别名]
# 或者: from glue.core.DataCollection import add_link [as 别名]
def _load_data_collection(rec, context):
    dc = DataCollection(list(map(context.object, rec['data'])))
    for link in rec['links']:
        dc.add_link(context.object(link))
    coerce_subset_groups(dc)
    return dc
开发者ID:crawfordsm,项目名称:glue,代码行数:8,代码来源:state.py

示例6: setup_method

# 需要导入模块: from glue.core import DataCollection [as 别名]
# 或者: from glue.core.DataCollection import add_link [as 别名]
class TestArithmeticEditorWidget:

    def setup_method(self):

        self.data1 = Data(x=[1, 2, 3], y=[3.5, 4.5, -1.0], z=['a', 'r', 'w'])
        self.data2 = Data(a=[3, 4, 1], b=[1.5, -2.0, 3.5], c=['y', 'e', 'r'])

        # Add a derived component so that we can test how we deal with existing ones
        components = dict((cid.label, cid) for cid in self.data2.components)
        pc = ParsedCommand('{a}', components)
        link = ParsedComponentLink(ComponentID('d'), pc)
        self.data2.add_component_link(link)

        self.data_collection = DataCollection([self.data1, self.data2])

        link = ComponentLink([self.data1.id['x']], self.data2.id['a'])
        self.data_collection.add_link(link)

        self.listener1 = ChangeListener(self.data1)
        self.listener2 = ChangeListener(self.data2)

    def test_nochanges(self):
        editor = ArithmeticEditorWidget(self.data_collection)
        editor.show()
        editor.button_ok.click()
        self.listener1.assert_exact_changes()
        self.listener2.assert_exact_changes()
        editor.close()

    def test_add_derived_and_rename(self):
        editor = ArithmeticEditorWidget(self.data_collection)
        editor.show()
        with patch.object(EquationEditorDialog, 'exec_', auto_accept('{x} + {y}')):
            editor.button_add_derived.click()
        item = list(editor.list)[0]
        item.setText(0, 'new')
        editor.button_ok.click()
        self.listener1.assert_exact_changes(added=[self.data1.id['new']])
        self.listener2.assert_exact_changes()
        assert_equal(self.data1['new'], [4.5, 6.5, 2.0])
        editor.close()

    def test_add_derived_and_cancel(self):
        editor = ArithmeticEditorWidget(self.data_collection)
        editor.show()
        with patch.object(EquationEditorDialog, 'exec_', auto_reject()):
            editor.button_add_derived.click()
        assert len(editor.list) == 0
        editor.close()

    def test_edit_existing_equation(self):
        assert_equal(self.data2['d'], [3, 4, 1])
        editor = ArithmeticEditorWidget(self.data_collection)
        editor.show()
        assert len(editor.list) == 0
        editor.combosel_data.setCurrentIndex(1)
        assert len(editor.list) == 1
        editor.list.select_cid(self.data2.id['d'])
        with patch.object(EquationEditorDialog, 'exec_', auto_accept('{a} + {b}')):
            editor.button_edit_derived.click()
        editor.button_ok.click()
        self.listener1.assert_exact_changes()
        self.listener2.assert_exact_changes(numerical=True)
        assert_equal(self.data2['d'], [4.5, 2.0, 4.5])
        editor.close()
开发者ID:glue-viz,项目名称:glue,代码行数:67,代码来源:test_component_arithmetic.py

示例7: load_data

# 需要导入模块: from glue.core import DataCollection [as 别名]
# 或者: from glue.core.DataCollection import add_link [as 别名]
                               format='ascii.ipac')
catalog.label='FittedLineParameters'
catalog.style.color = 'green'
catalog.style.marker = 'o'
cube = load_data(hpath('APEX_H2CO_303_202_bl.fits'))
cube.label='H2CO 303/202'
cube2 = load_data(molpath('APEX_SiO_54.fits'))
cube2.label='SiO'
cube3 = load_data(hpath('APEX_13CO_matched_H2CO.fits'))
cube3.label='13CO'
higaltem = load_data('/Users/adam/work/gc/gcmosaic_temp_conv36.fits')

dc = DataCollection([cube, catalog, cube2, cube3, higaltem])
dc.merge(cube,cube2,cube3)

dc.add_link(LinkSame(cube.id['Galactic Longitude'], catalog.id['GLON']))
dc.add_link(LinkSame(cube.id['Galactic Latitude'], catalog.id['GLAT']))

def ms_to_kms(x): return x/1e3
def kms_to_ms(x): return x*1e3

dc.add_link(LinkTwoWay(cube.id['Vrad'], catalog.id['center'], ms_to_kms, kms_to_ms))

subset_tem_lt_60 = (catalog.id['temperature_chi2'] < 60) & (catalog.id['temperature_chi2'] > 10) & (catalog.id['area'] < 0.015)

subset_tem_gt_60 = (catalog.id['temperature_chi2'] > 60) & (catalog.id['area'] < 0.015)

app = GlueApplication(dc)

# plot x vs y, flip the x axis, log-scale y axis
scatter = app.new_data_viewer(ScatterWidget)
开发者ID:bsipocz,项目名称:APEX_CMZ_H2CO,代码行数:33,代码来源:glue_cat.py

示例8: TestReprojection

# 需要导入模块: from glue.core import DataCollection [as 别名]
# 或者: from glue.core.DataCollection import add_link [as 别名]
class TestReprojection():

    def setup_method(self, method):

        self.data_collection = DataCollection()

        self.array = np.arange(3024).reshape((6, 7, 8, 9))

        # The reference dataset. Shape is (6, 7, 8, 9).
        self.data1 = Data(x=self.array)
        self.data_collection.append(self.data1)

        # A dataset with the same shape but not linked. Shape is (6, 7, 8, 9).
        self.data2 = Data(x=self.array)
        self.data_collection.append(self.data2)

        # A dataset with the same number of dimesnions but in a different
        # order, linked to the first. Shape is (9, 7, 6, 8).
        self.data3 = Data(x=np.moveaxis(self.array, (3, 1, 0, 2), (0, 1, 2, 3)))
        self.data_collection.append(self.data3)
        self.data_collection.add_link(LinkSame(self.data1.pixel_component_ids[0],
                                               self.data3.pixel_component_ids[2]))
        self.data_collection.add_link(LinkSame(self.data1.pixel_component_ids[1],
                                               self.data3.pixel_component_ids[1]))
        self.data_collection.add_link(LinkSame(self.data1.pixel_component_ids[2],
                                               self.data3.pixel_component_ids[3]))
        self.data_collection.add_link(LinkSame(self.data1.pixel_component_ids[3],
                                               self.data3.pixel_component_ids[0]))

        # A dataset with fewer dimensions, linked to the first one. Shape is
        # (8, 7, 6)
        self.data4 = Data(x=self.array[:, :, :, 0].transpose())
        self.data_collection.append(self.data4)
        self.data_collection.add_link(LinkSame(self.data1.pixel_component_ids[0],
                                               self.data4.pixel_component_ids[2]))
        self.data_collection.add_link(LinkSame(self.data1.pixel_component_ids[1],
                                               self.data4.pixel_component_ids[1]))
        self.data_collection.add_link(LinkSame(self.data1.pixel_component_ids[2],
                                               self.data4.pixel_component_ids[0]))

        # A dataset with even fewer dimensions, linked to the first one. Shape
        # is (8, 6)
        self.data5 = Data(x=self.array[:, 0, :, 0].transpose())
        self.data_collection.append(self.data5)
        self.data_collection.add_link(LinkSame(self.data1.pixel_component_ids[0],
                                               self.data5.pixel_component_ids[1]))
        self.data_collection.add_link(LinkSame(self.data1.pixel_component_ids[2],
                                               self.data5.pixel_component_ids[0]))

        # A dataset that is not on the same pixel grid and requires reprojection
        self.data6 = Data()
        self.data6.coords = SimpleCoordinates()
        self.array_nonaligned = np.arange(60).reshape((5, 3, 4))
        self.data6['x'] = np.array(self.array_nonaligned)
        self.data_collection.append(self.data6)
        self.data_collection.add_link(LinkSame(self.data1.world_component_ids[0],
                                               self.data6.world_component_ids[1]))
        self.data_collection.add_link(LinkSame(self.data1.world_component_ids[1],
                                               self.data6.world_component_ids[2]))
        self.data_collection.add_link(LinkSame(self.data1.world_component_ids[2],
                                               self.data6.world_component_ids[0]))

        self.viewer_state = ImageViewerState()
        self.viewer_state.layers.append(ImageLayerState(viewer_state=self.viewer_state, layer=self.data1))
        self.viewer_state.layers.append(ImageLayerState(viewer_state=self.viewer_state, layer=self.data2))
        self.viewer_state.layers.append(ImageLayerState(viewer_state=self.viewer_state, layer=self.data3))
        self.viewer_state.layers.append(ImageLayerState(viewer_state=self.viewer_state, layer=self.data4))
        self.viewer_state.layers.append(ImageLayerState(viewer_state=self.viewer_state, layer=self.data5))
        self.viewer_state.layers.append(ImageLayerState(viewer_state=self.viewer_state, layer=self.data6))

        self.viewer_state.reference_data = self.data1

    def test_default_axis_order(self):

        # Start off with a combination of x/y that means that only one of the
        # other datasets will be matched.

        self.viewer_state.x_att = self.data1.pixel_component_ids[3]
        self.viewer_state.y_att = self.data1.pixel_component_ids[2]
        self.viewer_state.slices = (3, 2, 4, 1)

        image = self.viewer_state.layers[0].get_sliced_data()
        assert_equal(image, self.array[3, 2, :, :])

        with pytest.raises(IncompatibleAttribute):
            self.viewer_state.layers[1].get_sliced_data()

        image = self.viewer_state.layers[2].get_sliced_data()
        assert_equal(image, self.array[3, 2, :, :])

        with pytest.raises(IncompatibleDataException):
            self.viewer_state.layers[3].get_sliced_data()

        with pytest.raises(IncompatibleDataException):
            self.viewer_state.layers[4].get_sliced_data()

    def test_transpose_axis_order(self):

        # Next make it so the x/y axes correspond to the dimensions with length
        # 6 and 8 which most datasets will be compatible with, and this also
#.........这里部分代码省略.........
开发者ID:jzuhone,项目名称:glue,代码行数:103,代码来源:test_state.py

示例9: setup_method

# 需要导入模块: from glue.core import DataCollection [as 别名]
# 或者: from glue.core.DataCollection import add_link [as 别名]
class TestLinkEditor:

    def setup_method(self, method):

        self.data1 = Data(x=[1, 2, 3], y=[2, 3, 4], z=[6, 5, 4], label='data1')
        self.data2 = Data(a=[2, 3, 4], b=[4, 5, 4], c=[3, 4, 1], label='data2')
        self.data3 = Data(i=[5, 4, 3], j=[2, 2, 1], label='data3')

        self.data_collection = DataCollection([self.data1, self.data2, self.data3])

    @pytest.mark.parametrize('accept', [False, True])
    def test_basic(self, accept):

        # Set up an existing link
        link1 = ComponentLink([self.data1.id['x']], self.data2.id['c'])
        self.data_collection.add_link(link1)

        # Set up two suggested links

        def add(x, y):
            return x + y

        def double(x):
            return x * 2

        def halve(x):
            return x / 2

        link2 = ComponentLink([self.data2.id['a'], self.data2.id['b']], self.data3.id['j'], using=add)
        link3 = ComponentLink([self.data3.id['i']], self.data2.id['c'], using=double, inverse=halve)

        suggested_links = [link2, link3]

        dialog = AutoLinkPreview('test autolinker', self.data_collection, suggested_links)
        dialog.show()
        link_widget = dialog.link_widget

        link_widget.state.data1 = self.data1
        link_widget.state.data2 = self.data2

        assert link_widget.listsel_current_link.count() == 1

        link_widget.state.data1 = self.data3

        assert link_widget.listsel_current_link.count() == 2

        if accept:

            dialog.accept()

            links = self.data_collection.external_links

            assert len(links) == 3

            assert isinstance(links[0], ComponentLink)
            assert links[0].get_from_ids()[0] is self.data1.id['x']
            assert links[0].get_to_id() is self.data2.id['c']
            assert links[0].get_using() is identity

            assert isinstance(links[1], ComponentLink)
            assert links[1].get_from_ids()[0] is self.data2.id['a']
            assert links[1].get_from_ids()[1] is self.data2.id['b']
            assert links[1].get_to_id() is self.data3.id['j']
            assert links[1].get_using() is add

            assert isinstance(links[2], ComponentLink)
            assert links[2].get_from_ids()[0] is self.data3.id['i']
            assert links[2].get_to_id() is self.data2.id['c']
            assert links[2].get_using() is double
            assert links[2].get_inverse() is halve

        else:

            dialog.reject()

            links = self.data_collection.external_links

            assert len(links) == 1

            assert isinstance(links[0], ComponentLink)
            assert links[0].get_from_ids()[0] is self.data1.id['x']
            assert links[0].get_to_id() is self.data2.id['c']
            assert links[0].get_using() is identity
开发者ID:glue-viz,项目名称:glue,代码行数:85,代码来源:test_autolinker.py

示例10: load_data

# 需要导入模块: from glue.core import DataCollection [as 别名]
# 或者: from glue.core.DataCollection import add_link [as 别名]
from glue.core.data_factories import load_data
from glue.core import DataCollection
from glue.core.link_helpers import LinkSame
from glue.qt.glue_application import GlueApplication

#load 2 datasets from files
image = load_data('w5.fits')
catalog = load_data('w5_psc.vot')
dc = DataCollection([image, catalog])

# link positional information
dc.add_link(LinkSame(image.id['World x: RA---TAN'], catalog.id['RAJ2000']))
dc.add_link(LinkSame(image.id['World y: DEC--TAN'], catalog.id['DEJ2000']))

#start Glue
app = GlueApplication(dc)
app.start()
开发者ID:ChrisBeaumont,项目名称:glue,代码行数:19,代码来源:w5.py

示例11: DataCollection

# 需要导入模块: from glue.core import DataCollection [as 别名]
# 或者: from glue.core.DataCollection import add_link [as 别名]
dc = DataCollection(dendrogram)
#dc = DataCollection([cube, dendrogram, catalog])
#dc.merge(cube,sncube)
#sncube.join_on_key(dendro, 'structure', dendro.pixel_component_ids[0])
#dc.merge(catalog, dendro)

# UNCOMMENT THIS LINE TO BREAK THE VIEWER
dc.append(catalog)

app = GlueApplication(dc)

cube_viewer = app.new_data_viewer(ImageWidget)
cube_viewer.add_data(sncube)

# link positional information
dc.add_link(LinkSame(sncube.id['structure'], catalog.id['_idx']))
#dc.add_link(LinkSame(image.id['World y: DEC--TAN'], catalog.id['DEJ2000']))

dc.add_link(LinkSame(cube.id['Galactic Longitude'], catalog.id['x_cen']))
dc.add_link(LinkSame(cube.id['Galactic Latitude'], catalog.id['y_cen']))

def ms_to_kms(x): return x/1e3
def kms_to_ms(x): return x*1e3

dc.add_link(LinkTwoWay(cube.id['Vrad'], catalog.id['v_cen'], ms_to_kms, kms_to_ms))

scatter = app.new_data_viewer(ScatterWidget)
scatter.add_data(catalog)
scatter.yatt = catalog.id['temperature_chi2']
scatter.xatt = catalog.id['area_exact']
开发者ID:bsipocz,项目名称:APEX_CMZ_H2CO,代码行数:32,代码来源:dendro_glue_sm.py

示例12: setup_method

# 需要导入模块: from glue.core import DataCollection [as 别名]
# 或者: from glue.core.DataCollection import add_link [as 别名]
class TestComponentManagerWidget:

    def setup_method(self):

        self.data1 = Data(x=[1, 2, 3], y=[3.5, 4.5, -1.0], z=['a', 'r', 'w'])
        self.data2 = Data(a=[3, 4, 1], b=[1.5, -2.0, 3.5], c=['y', 'e', 'r'])

        # Add a derived component so that we can test how we deal with existing ones
        components = dict((cid.label, cid) for cid in self.data2.components)
        pc = ParsedCommand('{a}', components)
        link = ParsedComponentLink(ComponentID('d'), pc)
        self.data2.add_component_link(link)

        self.data_collection = DataCollection([self.data1, self.data2])

        link = ComponentLink([self.data1.id['x']], self.data2.id['a'])
        self.data_collection.add_link(link)

        self.listener1 = ChangeListener(self.data1)
        self.listener2 = ChangeListener(self.data2)

    def test_nochanges(self):
        self.manager = ComponentManagerWidget(self.data_collection)
        self.manager.show()
        self.manager.button_ok.click()
        self.listener1.assert_exact_changes()
        self.listener2.assert_exact_changes()

    def test_remove(self):
        x_cid = self.data1.id['x']
        self.manager = ComponentManagerWidget(self.data_collection)
        self.manager.show()
        item = list(self.manager.list)[0]
        self.manager.list.select_item(item)
        self.manager.button_remove_main.click()
        self.manager.button_ok.click()
        self.listener1.assert_exact_changes(removed=[x_cid])
        self.listener2.assert_exact_changes()

    def test_rename_valid(self):
        x_cid = self.data1.id['x']
        self.manager = ComponentManagerWidget(self.data_collection)
        self.manager.show()
        item = list(self.manager.list)[0]
        item.setText(0, 'newname')
        self.manager.button_ok.click()
        assert self.manager.result() == 1
        self.listener1.assert_exact_changes(renamed=[x_cid])
        self.listener2.assert_exact_changes()
        assert x_cid.label == 'newname'
        assert_equal(self.data1['newname'], [1, 2, 3])

    def test_rename_invalid(self):
        x_cid = self.data1.id['x']
        self.manager = ComponentManagerWidget(self.data_collection)
        self.manager.show()
        item = list(self.manager.list)[0]
        item.setText(0, 'y')
        assert not self.manager.button_ok.isEnabled()
        assert self.manager.ui.label_status.text() == 'Error: some components have duplicate names'
        item = list(self.manager.list)[0]
        item.setText(0, 'a')
        assert self.manager.button_ok.isEnabled()
        assert self.manager.ui.label_status.text() == ''
        self.manager.button_ok.click()
        self.listener1.assert_exact_changes(renamed=[x_cid])
        self.listener2.assert_exact_changes()
        assert x_cid.label == 'a'
        assert_equal(self.data1['a'], [1, 2, 3])
开发者ID:glue-viz,项目名称:glue,代码行数:71,代码来源:test_component_manager.py

示例13: TestFixedResolutionBuffer

# 需要导入模块: from glue.core import DataCollection [as 别名]
# 或者: from glue.core.DataCollection import add_link [as 别名]
class TestFixedResolutionBuffer():

    def setup_method(self, method):

        self.data_collection = DataCollection()

        # The reference dataset. Shape is (6, 7, 8, 9).
        self.data1 = Data(x=ARRAY)
        self.data_collection.append(self.data1)

        # A dataset with the same shape but not linked. Shape is (6, 7, 8, 9).
        self.data2 = Data(x=ARRAY)
        self.data_collection.append(self.data2)

        # A dataset with the same number of dimensions but in a different
        # order, linked to the first. Shape is (9, 7, 6, 8).
        self.data3 = Data(x=np.moveaxis(ARRAY, (3, 1, 0, 2), (0, 1, 2, 3)))
        self.data_collection.append(self.data3)
        self.data_collection.add_link(LinkSame(self.data1.pixel_component_ids[0],
                                               self.data3.pixel_component_ids[2]))
        self.data_collection.add_link(LinkSame(self.data1.pixel_component_ids[1],
                                               self.data3.pixel_component_ids[1]))
        self.data_collection.add_link(LinkSame(self.data1.pixel_component_ids[2],
                                               self.data3.pixel_component_ids[3]))
        self.data_collection.add_link(LinkSame(self.data1.pixel_component_ids[3],
                                               self.data3.pixel_component_ids[0]))

        # A dataset with fewer dimensions, linked to the first one. Shape is
        # (8, 7, 6)
        self.data4 = Data(x=ARRAY[:, :, :, 0].transpose())
        self.data_collection.append(self.data4)
        self.data_collection.add_link(LinkSame(self.data1.pixel_component_ids[0],
                                               self.data4.pixel_component_ids[2]))
        self.data_collection.add_link(LinkSame(self.data1.pixel_component_ids[1],
                                               self.data4.pixel_component_ids[1]))
        self.data_collection.add_link(LinkSame(self.data1.pixel_component_ids[2],
                                               self.data4.pixel_component_ids[0]))

        # A dataset with even fewer dimensions, linked to the first one. Shape
        # is (8, 6)
        self.data5 = Data(x=ARRAY[:, 0, :, 0].transpose())
        self.data_collection.append(self.data5)
        self.data_collection.add_link(LinkSame(self.data1.pixel_component_ids[0],
                                               self.data5.pixel_component_ids[1]))
        self.data_collection.add_link(LinkSame(self.data1.pixel_component_ids[2],
                                               self.data5.pixel_component_ids[0]))

        # A dataset that is not on the same pixel grid and requires reprojection
        # self.data6 = Data()
        # self.data6.coords = SimpleCoordinates()
        # self.array_nonaligned = np.arange(60).reshape((5, 3, 4))
        # self.data6['x'] = np.array(self.array_nonaligned)
        # self.data_collection.append(self.data6)
        # self.data_collection.add_link(LinkSame(self.data1.world_component_ids[0],
        #                                        self.data6.world_component_ids[1]))
        # self.data_collection.add_link(LinkSame(self.data1.world_component_ids[1],
        #                                        self.data6.world_component_ids[2]))
        # self.data_collection.add_link(LinkSame(self.data1.world_component_ids[2],
        #                                        self.data6.world_component_ids[0]))

    # Start off with the cases where the data is the target data. Enumerate
    # the different cases for the bounds and the expected result.

    DATA_IS_TARGET_CASES = [

        # Bounds are full extent of data
        ([(0, 5, 6), (0, 6, 7), (0, 7, 8), (0, 8, 9)],
            ARRAY),

        # Bounds are inside data
        ([(2, 3, 2), (3, 3, 1), (0, 7, 8), (0, 7, 8)],
            ARRAY[2:4, 3:4, :, :8]),

        # Bounds are outside data along some dimensions
        ([(-5, 9, 15), (3, 5, 3), (0, 9, 10), (5, 6, 2)],
            np.pad(ARRAY[:, 3:6, :, 5:7], [(5, 4), (0, 0), (0, 2), (0, 0)],
                   mode='constant', constant_values=-np.inf)),

        # No overlap
        ([(2, 3, 2), (3, 3, 1), (-5, -4, 2), (0, 7, 8)],
            -np.inf * np.ones((2, 1, 2, 8)))

    ]

    @pytest.mark.parametrize(('bounds', 'expected'), DATA_IS_TARGET_CASES)
    def test_data_is_target_full_bounds(self, bounds, expected):

        buffer = self.data1.compute_fixed_resolution_buffer(target_data=self.data1, bounds=bounds,
                                                            target_cid=self.data1.id['x'])
        assert_equal(buffer, expected)

        buffer = self.data3.compute_fixed_resolution_buffer(target_data=self.data1, bounds=bounds,
                                                            target_cid=self.data3.id['x'])
        assert_equal(buffer, expected)
开发者ID:glue-viz,项目名称:glue,代码行数:96,代码来源:test_fixed_resolution_buffer.py

示例14: setup_method

# 需要导入模块: from glue.core import DataCollection [as 别名]
# 或者: from glue.core.DataCollection import add_link [as 别名]
class TestLinkEditor:

    def setup_method(self, method):

        self.data1 = Data(x=[1, 2, 3], y=[2, 3, 4], z=[6, 5, 4], label='data1')
        self.data2 = Data(a=[2, 3, 4], b=[4, 5, 4], c=[3, 4, 1], label='data2')
        self.data3 = Data(i=[5, 4, 3], j=[2, 2, 1], label='data3')

        self.data_collection = DataCollection([self.data1, self.data2, self.data3])

    def test_defaults(self):
        # Make sure the dialog opens and closes and check default settings.
        dialog = LinkEditor(self.data_collection)
        dialog.show()
        link_widget = dialog.link_widget

        assert link_widget.state.data1 is None
        assert link_widget.state.data2 is None
        assert not link_widget.button_add_link.isEnabled()
        assert not link_widget.button_remove_link.isEnabled()

        link_widget.state.data1 = self.data2

        assert not link_widget.button_add_link.isEnabled()
        assert not link_widget.button_remove_link.isEnabled()

        link_widget.state.data2 = self.data1

        assert link_widget.button_add_link.isEnabled()
        assert link_widget.button_remove_link.isEnabled()

        dialog.accept()

        assert len(self.data_collection.external_links) == 0

    def test_defaults_two(self):
        # Make sure the dialog opens and closes and check default settings. With
        # two datasets, the datasets should be selected by default.
        self.data_collection.remove(self.data3)
        dialog = LinkEditor(self.data_collection)
        dialog.show()
        link_widget = dialog.link_widget
        assert link_widget.state.data1 is self.data1
        assert link_widget.state.data2 is self.data2
        assert link_widget.button_add_link.isEnabled()
        assert link_widget.button_remove_link.isEnabled()
        dialog.accept()
        assert len(self.data_collection.external_links) == 0

    def test_ui_behavior(self):

        # This is a bit more detailed test that checks that things update
        # correctly as we change various settings

        dialog = LinkEditor(self.data_collection)
        dialog.show()
        link_widget = dialog.link_widget

        link_widget.state.data1 = self.data1
        link_widget.state.data2 = self.data2

        add_identity_link = get_action(link_widget, 'identity')
        add_lengths_volume_link = get_action(link_widget, 'lengths_to_volume')

        # At this point, there should be no links in the main list widget
        # and nothing on the right.
        assert link_widget.listsel_current_link.count() == 0
        assert link_widget.link_details.text() == ''
        assert link_widget.link_io.itemAt(0) is None

        # Let's add an identity link
        add_identity_link.trigger()

        # Ensure that all events get processed
        process_events()

        # Now there should be one link in the main list and content in the
        # right hand panel.
        assert link_widget.listsel_current_link.count() == 1
        assert link_widget.link_details.text() == 'Link conceptually identical components'
        assert non_empty_rows_count(get_link_io(link_widget)) == 5
        assert get_link_io(link_widget).itemAtPosition(1, 1).widget().currentText() == 'x'
        assert get_link_io(link_widget).itemAtPosition(4, 1).widget().currentText() == 'a'

        # Let's change the current components for the link
        link_widget.state.current_link.x = self.data1.id['y']
        link_widget.state.current_link.y = self.data2.id['b']

        # and make sure the UI gets updated
        assert get_link_io(link_widget).itemAtPosition(1, 1).widget().currentText() == 'y'
        assert get_link_io(link_widget).itemAtPosition(4, 1).widget().currentText() == 'b'

        # We now add another link of a different type
        add_lengths_volume_link.trigger()

        # Ensure that all events get processed
        process_events()

        # and make sure the UI has updated
        assert link_widget.listsel_current_link.count() == 2
#.........这里部分代码省略.........
开发者ID:glue-viz,项目名称:glue,代码行数:103,代码来源:test_link_editor.py


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