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


Python ArrayDataSource.get_data方法代码示例

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


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

示例1: test_change_min_max

# 需要导入模块: from chaco.api import ArrayDataSource [as 别名]
# 或者: from chaco.api.ArrayDataSource import get_data [as 别名]
    def test_change_min_max(self):
        """ Test that changing min_value and max_value does not break map. """

        datarange = self.colormap.range

        # Perform a dummy mapping.
        a = ArrayDataSource(array([0.0, 0.5, 1.0]))
        datarange.add(a)
        b = self.colormap.map_screen(a.get_data())
        datarange.remove(a)

        # Update the min_value.
        datarange.low = -1.0

        # Test that the map still works.
        a = ArrayDataSource(array([-1.0, 0.0, 1.0]))
        datarange.add(a)
        b = self.colormap.map_screen(a.get_data())
        datarange.remove(a)
        expected = array([0.0, 0.5, 1.0])

        close = allclose(ravel(b[:,:1]), expected, atol=0.02)
        self.assertTrue(close,
            "Changing min value broke map.  Expected %s.  Got %s" % (expected, b[:,:1]))

        # Update the max_value.
        datarange.high = 0.0
        # Test that the map still works.
        a = ArrayDataSource(array([-1.0, -0.5, 0.0]))
        datarange.add(a)
        b = self.colormap.map_screen(a.get_data())
        datarange.remove(a)
        expected = array([0.0, 0.5, 1.0])

        close = allclose(ravel(b[:,:1]), expected, atol=0.02)
        self.assertTrue(close,
            "Changing min value broke map.  Expected %s.  Got %s" % (expected, b[:,:1]))


        return
开发者ID:enthought,项目名称:chaco,代码行数:42,代码来源:colormapper_test_case.py

示例2: test_simple_map

# 需要导入模块: from chaco.api import ArrayDataSource [as 别名]
# 或者: from chaco.api.ArrayDataSource import get_data [as 别名]
    def test_simple_map(self):

        a = ArrayDataSource(array([0.0, 0.5, 1.0]))
        self.colormap.range.add(a)
        b = self.colormap.map_screen(a.get_data())
        self.colormap.range.remove(a)

        expected = array([0.0, 0.5, 1.0])

        close = allclose(ravel(b[:,:1]), expected, atol=0.02)
        self.assertTrue(close,
            "Simple map failed.  Expected %s.  Got %s" % (expected, b[:,:1]))

        return
开发者ID:enthought,项目名称:chaco,代码行数:16,代码来源:colormapper_test_case.py

示例3: test_array_factory

# 需要导入模块: from chaco.api import ArrayDataSource [as 别名]
# 或者: from chaco.api.ArrayDataSource import get_data [as 别名]
    def test_array_factory(self):
        """ Test that the array factory creates valid colormap. """

        colors = array([[0.0,0.0,0.0], [1.0,1.0,1.0]])
        cm = ColorMapper.from_palette_array(colors)
        cm.range = DataRange1D()

        ar = ArrayDataSource(array([0.0, 0.5, 1.0]))
        cm.range.add(ar)
        b = cm.map_screen(ar.get_data())
        cm.range.remove(ar)

        expected = array([0.0, 0.5, 1.0])

        self.assertTrue(allclose(ravel(b[:,:1]), expected, atol=0.02),
            "Array factory failed.  Expected %s.  Got %s" % (expected, b[:,:1]))

        return
开发者ID:enthought,项目名称:chaco,代码行数:20,代码来源:colormapper_test_case.py

示例4: test_get_data_no_data

# 需要导入模块: from chaco.api import ArrayDataSource [as 别名]
# 或者: from chaco.api.ArrayDataSource import get_data [as 别名]
    def test_get_data_no_data(self):
        data_source = ArrayDataSource(None)

        assert_array_equal(data_source.get_data(), 0.0)
开发者ID:,项目名称:,代码行数:6,代码来源:

示例5: ArrayDataSourceTestCase

# 需要导入模块: from chaco.api import ArrayDataSource [as 别名]
# 或者: from chaco.api.ArrayDataSource import get_data [as 别名]
class ArrayDataSourceTestCase(UnittestTools, unittest.TestCase):

    def setUp(self):
        self.myarray = arange(10)
        self.mymask = array([i % 2 for i in self.myarray], dtype=bool)
        self.data_source = ArrayDataSource(self.myarray)

    def test_init_defaults(self):
        data_source = ArrayDataSource()
        assert_array_equal(data_source._data, [])
        self.assertEqual(data_source.value_dimension, "scalar")
        self.assertEqual(data_source.index_dimension, "scalar")
        self.assertEqual(data_source.sort_order, "none")
        self.assertFalse(data_source.is_masked())
        self.assertEqual(data_source.persist_data, True)

    def test_basic_setup(self):
        assert_array_equal(self.myarray, self.data_source._data)
        self.assertEqual(self.data_source.value_dimension, "scalar")
        self.assertEqual(self.data_source.sort_order, "none")
        self.assertFalse(self.data_source.is_masked())

    def test_set_data(self):
        new_array = arange(0, 20, 2)

        with self.assertTraitChanges(self.data_source, 'data_changed',
                                     count=1):
            self.data_source.set_data(new_array)

        assert_array_equal(new_array, self.data_source._data)
        self.assertEqual(self.data_source.get_bounds(), (0, 18))
        self.assertEqual(self.data_source.sort_order, "none")

    def test_set_data_ordered(self):
        new_array = arange(20, 0, -2)

        with self.assertTraitChanges(self.data_source, 'data_changed',
                                     count=1):
            self.data_source.set_data(new_array, sort_order='descending')

        assert_array_equal(new_array, self.data_source._data)
        self.assertEqual(self.data_source.get_bounds(), (2, 20))
        self.assertEqual(self.data_source.sort_order, "descending")

    def test_set_mask(self):
        with self.assertTraitChanges(self.data_source, 'data_changed',
                                     count=1):
            self.data_source.set_mask(self.mymask)

        assert_array_equal(self.myarray, self.data_source._data)
        assert_array_equal(self.mymask, self.data_source._cached_mask)
        self.assertTrue(self.data_source.is_masked())
        self.assertEqual(self.data_source.get_bounds(), (0, 9))

    def test_remove_mask(self):
        self.data_source.set_mask(self.mymask)
        self.assertTrue(self.data_source.is_masked())

        with self.assertTraitChanges(self.data_source, 'data_changed',
                                     count=1):
            self.data_source.remove_mask()

        assert_array_equal(self.myarray, self.data_source._data)
        self.assertIsNone(self.data_source._cached_mask, None)
        self.assertFalse(self.data_source.is_masked())
        self.assertEqual(self.data_source.get_bounds(), (0, 9))

    def test_get_data(self):
        assert_array_equal(self.myarray, self.data_source.get_data())

    def test_get_data_no_data(self):
        data_source = ArrayDataSource(None)

        assert_array_equal(data_source.get_data(), 0.0)

    def test_get_data_mask(self):
        self.data_source.set_mask(self.mymask)

        data, mask = self.data_source.get_data_mask()
        assert_array_equal(data, self.myarray)
        assert_array_equal(mask, self.mymask)

    @unittest.skip('get_data_mask() fails in this case')
    def test_get_data_mask_no_data(self):
        data_source = ArrayDataSource(None)

        data, mask = data_source.get_data_mask()
        assert_array_equal(data, 0.0)
        assert_array_equal(mask, True)

    def test_get_data_mask_no_mask(self):
        data, mask = self.data_source.get_data_mask()
        assert_array_equal(data, self.myarray)
        assert_array_equal(mask, ones(shape=10, dtype=bool))

    def test_bounds(self):
        # ascending
        bounds = self.data_source.get_bounds()
        self.assertEqual(bounds, (0, 9))

#.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:103,代码来源:


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