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


Python analysis.Aggregator类代码示例

本文整理汇总了Python中iris.analysis.Aggregator的典型用法代码示例。如果您正苦于以下问题:Python Aggregator类的具体用法?Python Aggregator怎么用?Python Aggregator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: test_kwarg_pass_through_no_kwargs

 def test_kwarg_pass_through_no_kwargs(self):
     lazy_func = Mock()
     data = sentinel.data
     axis = sentinel.axis
     aggregator = Aggregator('', None, lazy_func=lazy_func)
     aggregator.lazy_aggregate(data, axis)
     lazy_func.assert_called_once_with(data, axis)
开发者ID:Jozhogg,项目名称:iris,代码行数:7,代码来源:test_Aggregator.py

示例2: test_no_units_change

 def test_no_units_change(self):
     # If the Aggregator has no units_func then the units should be
     # left unchanged.
     aggregator = Aggregator('', None)
     cube = Mock(units=sentinel.units)
     aggregator.update_metadata(cube, [])
     self.assertIs(cube.units, sentinel.units)
开发者ID:Jozhogg,项目名称:iris,代码行数:7,代码来源:test_Aggregator.py

示例3: test_mdtol_intercept

 def test_mdtol_intercept(self):
     call_func = Mock()
     data = sentinel.data
     axis = sentinel.axis
     aggregator = Aggregator('', call_func)
     aggregator.aggregate(data, axis, wibble='wobble', mdtol=0.8)
     call_func.assert_called_once_with(data, axis=axis, wibble='wobble')
开发者ID:Jozhogg,项目名称:iris,代码行数:7,代码来源:test_Aggregator.py

示例4: test_kwarg_pass_through_init_kwargs

 def test_kwarg_pass_through_init_kwargs(self):
     lazy_func = Mock()
     data = sentinel.data
     axis = sentinel.axis
     kwargs = dict(wibble='wobble', foo='bar')
     aggregator = Aggregator('', None, lazy_func=lazy_func, **kwargs)
     aggregator.lazy_aggregate(data, axis)
     lazy_func.assert_called_once_with(data, axis, **kwargs)
开发者ID:Jozhogg,项目名称:iris,代码行数:8,代码来源:test_Aggregator.py

示例5: test_kwarg_pass_through_call_kwargs

 def test_kwarg_pass_through_call_kwargs(self):
     call_func = Mock()
     data = sentinel.data
     axis = sentinel.axis
     kwargs = dict(wibble='wobble', foo='bar')
     aggregator = Aggregator('', call_func)
     aggregator.aggregate(data, axis, **kwargs)
     call_func.assert_called_once_with(data, axis=axis, **kwargs)
开发者ID:Jozhogg,项目名称:iris,代码行数:8,代码来源:test_Aggregator.py

示例6: test_units_change

 def test_units_change(self):
     # If the Aggregator has a units_func then the new units should
     # be defined by its return value.
     units_func = Mock(return_value=sentinel.new_units)
     aggregator = Aggregator('', None, units_func)
     cube = Mock(units=sentinel.units)
     aggregator.update_metadata(cube, [])
     units_func.assert_called_once_with(sentinel.units)
     self.assertEqual(cube.units, sentinel.new_units)
开发者ID:Jozhogg,项目名称:iris,代码行数:9,代码来源:test_Aggregator.py

示例7: test_kwarg_pass_through_combined_kwargs

 def test_kwarg_pass_through_combined_kwargs(self):
     lazy_func = Mock()
     data = sentinel.data
     axis = sentinel.axis
     init_kwargs = dict(wibble='wobble', var=1.0)
     call_kwargs = dict(foo='foo', var=0.5)
     aggregator = Aggregator('', None, lazy_func=lazy_func, **init_kwargs)
     aggregator.lazy_aggregate(data, axis, **call_kwargs)
     expected_kwargs = init_kwargs.copy()
     expected_kwargs.update(call_kwargs)
     lazy_func.assert_called_once_with(data, axis, **expected_kwargs)
开发者ID:Jozhogg,项目名称:iris,代码行数:11,代码来源:test_Aggregator.py

示例8: setUp

 def setUp(self):
     self.TEST = Aggregator('test', None)
     self.array = ma.array([[1, 2, 3],
                            [4, 5, 6]],
                           mask=[[False, True, False],
                                 [True, False, False]],
                           dtype=np.float64)
     self.expected_result_axis0 = ma.array([1, 2, 3], mask=None)
     self.expected_result_axis1 = ma.array([4, 5], mask=None)
开发者ID:Jozhogg,项目名称:iris,代码行数:9,代码来源:test_Aggregator.py

示例9: Test_aggregate

class Test_aggregate(tests.IrisTest):
    # These unit tests don't call a data aggregation function, they call a
    # mocked one i.e. the return values of the mocked data aggregation
    # function don't matter, only how these are dealt with by the aggregate
    # method.
    def setUp(self):
        self.TEST = Aggregator('test', None)
        self.array = ma.array([[1, 2, 3],
                               [4, 5, 6]],
                              mask=[[False, True, False],
                                    [True, False, False]],
                              dtype=np.float64)
        self.expected_result_axis0 = ma.array([1, 2, 3], mask=None)
        self.expected_result_axis1 = ma.array([4, 5], mask=None)

    def test_masked_notol(self):
        # Providing masked array with no tolerance keyword (mdtol) provided.
        axis = 0
        mock_return = self.expected_result_axis0.copy()
        with patch.object(self.TEST, 'call_func',
                          return_value=mock_return) as mock_method:
            result = self.TEST.aggregate(self.array, axis)
            self.assertMaskedArrayEqual(result, self.expected_result_axis0)
        mock_method.assert_called_once_with(self.array, axis=axis)

        axis = 1
        mock_return = self.expected_result_axis1.copy()
        with patch.object(self.TEST, 'call_func',
                          return_value=mock_return) as mock_method:
            result = self.TEST.aggregate(self.array, axis)
            self.assertMaskedArrayEqual(result, self.expected_result_axis1)
        mock_method.assert_called_once_with(self.array, axis=axis)

    def test_masked_above_tol(self):
        # Providing masked array with a high tolerance (mdtol) provided.
        axis = 0
        mock_return = self.expected_result_axis0.copy()
        with patch.object(self.TEST, 'call_func',
                          return_value=mock_return) as mock_method:
            result = self.TEST.aggregate(self.array, axis, mdtol=.55)
            self.assertMaskedArrayEqual(result, self.expected_result_axis0)
        mock_method.assert_called_once_with(self.array, axis=axis)

        axis = 1
        mock_return = self.expected_result_axis1.copy()
        with patch.object(self.TEST, 'call_func',
                          return_value=mock_return) as mock_method:
            result = self.TEST.aggregate(self.array, axis, mdtol=.55)
            self.assertMaskedArrayEqual(result, self.expected_result_axis1)
        mock_method.assert_called_once_with(self.array, axis=axis)

    def test_masked_below_tol(self):
        # Providing masked array with a tolerance on missing values, low
        # enough to modify the resulting mask for axis 0.
        axis = 0
        result_axis_0 = self.expected_result_axis0.copy()
        result_axis_0.mask = np.array([True, True, False])
        mock_return = ma.array([1, 2, 3], mask=None)
        with patch.object(self.TEST, 'call_func',
                          return_value=mock_return) as mock_method:
            result = self.TEST.aggregate(self.array, axis, mdtol=.45)
            self.assertMaskedArrayAlmostEqual(result, result_axis_0)
        mock_method.assert_called_once_with(self.array, axis=axis)

        axis = 1
        mock_return = self.expected_result_axis1.copy()
        with patch.object(self.TEST, 'call_func',
                          return_value=mock_return) as mock_method:
            result = self.TEST.aggregate(self.array, axis, mdtol=.45)
            self.assertMaskedArrayEqual(result, self.expected_result_axis1)
        mock_method.assert_called_once_with(self.array, axis=axis)

    def test_masked_below_tol_alt(self):
        # Providing masked array with a tolerance on missing values, low
        # enough to modify the resulting mask for axis 1.
        axis = 1
        result_axis_1 = self.expected_result_axis1.copy()
        result_axis_1.mask = np.array([True, True])
        mock_return = self.expected_result_axis1.copy()
        with patch.object(self.TEST, 'call_func',
                          return_value=mock_return) as mock_method:
            result = self.TEST.aggregate(self.array, axis, mdtol=.1)
            self.assertMaskedArrayAlmostEqual(result, result_axis_1)
        mock_method.assert_called_once_with(self.array, axis=axis)

    def test_unmasked_with_mdtol(self):
        # Providing aggregator with an unmasked array and tolerance specified
        # for missing data - ensure that result is unaffected.
        data = self.array.data

        axis = 0
        mock_return = self.expected_result_axis0.data.copy()
        with patch.object(self.TEST, 'call_func',
                          return_value=mock_return) as mock_method:
            result = self.TEST.aggregate(data, axis, mdtol=0.5)
            self.assertArrayAlmostEqual(result, mock_return.copy())
        mock_method.assert_called_once_with(data, axis=axis)

        axis = 1
        mock_return = self.expected_result_axis1.data.copy()
#.........这里部分代码省略.........
开发者ID:Jozhogg,项目名称:iris,代码行数:101,代码来源:test_Aggregator.py

示例10: test_no_lazy_func

 def test_no_lazy_func(self):
     dummy_agg = Aggregator('custom_op', lambda x: 1)
     expected = 'custom_op aggregator does not support lazy operation'
     with self.assertRaisesRegexp(LazyAggregatorError, expected):
         dummy_agg.lazy_aggregate(np.arange(10), axis=0)
开发者ID:Jozhogg,项目名称:iris,代码行数:5,代码来源:test_Aggregator.py

示例11: Test_aggregate

class Test_aggregate(tests.IrisTest):
    # These unit tests don't call a data aggregation function, they call a
    # mocked one i.e. the return values of the mocked data aggregation
    # function don't matter, only how these are dealt with by the aggregate
    # method.
    def setUp(self):
        self.TEST = Aggregator('test', None)
        self.array = ma.array([[1, 2, 3],
                               [4, 5, 6]],
                              mask=[[False, True, False],
                                    [True, False, False]],
                              dtype=np.float64)
        self.expected_result_axis0 = ma.array([1, 2, 3], mask=None)
        self.expected_result_axis1 = ma.array([4, 5], mask=None)

    def test_masked_notol(self):
        # Providing masked array with no tolerance keyword (mdtol) provided.
        axis = 0
        mock_return = self.expected_result_axis0.copy()
        with patch.object(self.TEST, 'call_func',
                          return_value=mock_return) as mock_method:
            result = self.TEST.aggregate(self.array, axis)
            self.assertMaskedArrayEqual(result, self.expected_result_axis0)
        mock_method.assert_called_once_with(self.array, axis=axis)

        axis = 1
        mock_return = self.expected_result_axis1.copy()
        with patch.object(self.TEST, 'call_func',
                          return_value=mock_return) as mock_method:
            result = self.TEST.aggregate(self.array, axis)
            self.assertMaskedArrayEqual(result, self.expected_result_axis1)
        mock_method.assert_called_once_with(self.array, axis=axis)

    def test_masked_above_tol(self):
        # Providing masked array with a high tolerance (mdtol) provided.
        axis = 0
        mock_return = self.expected_result_axis0.copy()
        with patch.object(self.TEST, 'call_func',
                          return_value=mock_return) as mock_method:
            result = self.TEST.aggregate(self.array, axis, mdtol=.55)
            self.assertMaskedArrayEqual(result, self.expected_result_axis0)
        mock_method.assert_called_once_with(self.array, axis=axis)

        axis = 1
        mock_return = self.expected_result_axis1.copy()
        with patch.object(self.TEST, 'call_func',
                          return_value=mock_return) as mock_method:
            result = self.TEST.aggregate(self.array, axis, mdtol=.55)
            self.assertMaskedArrayEqual(result, self.expected_result_axis1)
        mock_method.assert_called_once_with(self.array, axis=axis)

    def test_masked_below_tol(self):
        # Providing masked array with a tolerance on missing values, low
        # enough to modify the resulting mask for axis 0.
        axis = 0
        result_axis_0 = self.expected_result_axis0.copy()
        result_axis_0.mask = np.array([True, True, False])
        mock_return = ma.array([1, 2, 3], mask=None)
        with patch.object(self.TEST, 'call_func',
                          return_value=mock_return) as mock_method:
            result = self.TEST.aggregate(self.array, axis, mdtol=.45)
            self.assertMaskedArrayAlmostEqual(result, result_axis_0)
        mock_method.assert_called_once_with(self.array, axis=axis)

        axis = 1
        mock_return = self.expected_result_axis1.copy()
        with patch.object(self.TEST, 'call_func',
                          return_value=mock_return) as mock_method:
            result = self.TEST.aggregate(self.array, axis, mdtol=.45)
            self.assertMaskedArrayEqual(result, self.expected_result_axis1)
        mock_method.assert_called_once_with(self.array, axis=axis)

    def test_masked_below_tol_alt(self):
        # Providing masked array with a tolerance on missing values, low
        # enough to modify the resulting mask for axis 1.
        axis = 1
        result_axis_1 = self.expected_result_axis1.copy()
        result_axis_1.mask = np.array([True, True])
        mock_return = self.expected_result_axis1.copy()
        with patch.object(self.TEST, 'call_func',
                          return_value=mock_return) as mock_method:
            result = self.TEST.aggregate(self.array, axis, mdtol=.1)
            self.assertMaskedArrayAlmostEqual(result, result_axis_1)
        mock_method.assert_called_once_with(self.array, axis=axis)

    def test_unmasked_with_mdtol(self):
        # Providing aggregator with an unmasked array and tolerance specified
        # for missing data - ensure that result is unaffected.
        data = self.array.data

        axis = 0
        mock_return = self.expected_result_axis0.data.copy()
        with patch.object(self.TEST, 'call_func',
                          return_value=mock_return) as mock_method:
            result = self.TEST.aggregate(data, axis, mdtol=0.5)
            self.assertArrayAlmostEqual(result, mock_return.copy())
        mock_method.assert_called_once_with(data, axis=axis)

        axis = 1
        mock_return = self.expected_result_axis1.data.copy()
#.........这里部分代码省略.........
开发者ID:TheClimateCorporation,项目名称:iris,代码行数:101,代码来源:test_Aggregator.py


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