Ejemplo n.º 1
0
    def test_links(self):
        d1 = Data(label='x', x=[1, 2, 3])
        d2 = Data(label='y', y=[3, 4, 8])
        dc = DataCollection([d1, d2])
        link = ComponentLink([d1.id['x']], d2.id['y'], doubler)
        dc.add_link(link)

        np.testing.assert_array_equal(d1['y'], [2, 4, 6])

        app = GlueApplication(dc)
        self.check_clone(app)
Ejemplo n.º 2
0
    def test_links(self):
        d1 = Data(label='x', x=[1, 2, 3])
        d2 = Data(label='y', y=[3, 4, 8])
        dc = DataCollection([d1, d2])
        link = ComponentLink([d1.id['x']], d2.id['y'], doubler)
        dc.add_link(link)

        np.testing.assert_array_equal(d1['y'], [2, 4, 6])

        app = GlueApplication(dc)
        self.check_clone(app)
Ejemplo n.º 3
0
def test_pixel_selection_subset_state():

    data1 = Data(x=np.ones((2, 4, 3)))
    data2 = Data(y=np.ones((4, 3, 2)))
    data3 = Data(z=np.ones((2, 3)))

    y_id = data2.main_components[0]
    z_id = data3.main_components[0]

    slice_1d = [slice(1, 2), slice(None), slice(None)]
    slice_2d = [slice(None), slice(2, 3), slice(1, 2)]
    slice_3d = [slice(1, 2), slice(2, 3), slice(1, 2)]

    state_1d = PixelSubsetState(data1, slice_1d)
    state_2d = PixelSubsetState(data1, slice_2d)
    state_3d = PixelSubsetState(data1, slice_3d)

    states = [state_1d, state_2d, state_3d]

    dc = DataCollection([data1, data2, data3])

    # Calling to_array with reference data should work by default, and not work
    # with unlinked datasets.

    for data in dc:
        for state in states:
            cid = data.main_components[0]
            if data is data1:
                assert_array_equal(state.to_array(data, cid),
                                   data[cid][state.slices])
            else:
                with pytest.raises(IncompatibleAttribute):
                    state.to_array(data, cid)

    # Add one set of links

    dc.add_link(
        LinkSame(data1.pixel_component_ids[0], data2.pixel_component_ids[2]))
    dc.add_link(
        LinkSame(data1.pixel_component_ids[0], data3.pixel_component_ids[0]))

    assert_array_equal(state_1d.to_array(data2, y_id), data2[y_id][:, :, 1:2])
    with pytest.raises(IncompatibleAttribute):
        state_2d.to_array(data2, y_id)
    with pytest.raises(IncompatibleAttribute):
        state_3d.to_array(data2, y_id)

    assert_array_equal(state_1d.to_array(data3, z_id), data3[z_id][1:2])
    with pytest.raises(IncompatibleAttribute):
        state_2d.to_array(data3, z_id)
    with pytest.raises(IncompatibleAttribute):
        state_3d.to_array(data3, z_id)

    # Add links with multiple components, in this case linking two cids with two cids

    def forwards(x, y):
        return x + y, x - y

    def backwards(x, y):
        return 0.5 * (x + y), 0.5 * (x - y)

    dc.add_link(
        MultiLink(data1.pixel_component_ids[1:],
                  data2.pixel_component_ids[:2],
                  forwards=forwards,
                  backwards=backwards))

    assert_array_equal(state_1d.to_array(data2, y_id), data2[y_id][:, :, 1:2])
    assert_array_equal(state_2d.to_array(data2, y_id), data2[y_id][2:3,
                                                                   1:2, :])
    assert_array_equal(state_3d.to_array(data2, y_id), data2[y_id][2:3, 1:2,
                                                                   1:2])

    assert_array_equal(state_1d.to_array(data3, z_id), data3[z_id][1:2])
    with pytest.raises(IncompatibleAttribute):
        state_2d.to_array(data3, z_id)
    with pytest.raises(IncompatibleAttribute):
        state_3d.to_array(data3, z_id)