Example #1
0
 def test_unit_weighted(self):
     # unit weights should be the same as no weights
     data = np.array([5, 2, 6, 4], dtype=np.float64)
     weights = np.ones_like(data)
     rms = RMS.aggregate(data, 0, weights=weights)
     expected_rms = 4.5
     self.assertAlmostEqual(rms, expected_rms)
Example #2
0
 def test_2d_weighted(self):
     # 2-dimensional input with weights
     data = np.array([[4, 7, 10, 8], [14, 16, 20, 8]], dtype=np.float64)
     weights = np.array([[1, 4, 3, 2], [2, 1, 1.5, 0.5]], dtype=np.float64)
     expected_rms = np.array([8.0, 16.0], dtype=np.float64)
     rms = RMS.aggregate(data, 1, weights=weights)
     self.assertArrayAlmostEqual(rms, expected_rms)
Example #3
0
 def test_1d(self):
     # 1-dimensional input.
     data = as_lazy_data(np.array([5, 2, 6, 4], dtype=np.float64),
                         chunks=-1)
     rms = RMS.lazy_aggregate(data, 0)
     expected_rms = 4.5
     self.assertAlmostEqual(rms, expected_rms)
Example #4
0
 def test_2d(self):
     # 2-dimensional input.
     data = as_lazy_data(
         np.array([[5, 2, 6, 4], [12, 4, 10, 8]], dtype=np.float64))
     expected_rms = np.array([4.5, 9.0], dtype=np.float64)
     rms = RMS.lazy_aggregate(data, 1)
     self.assertArrayAlmostEqual(rms, expected_rms)
Example #5
0
 def test_1d_weighted(self):
     # 1-dimensional input with weights
     data = np.array([4, 7, 10, 8], dtype=np.float64)
     weights = np.array([1, 4, 3, 2], dtype=np.float64)
     expected_rms = 8.0
     rms = RMS.aggregate(data, 0, weights=weights)
     self.assertAlmostEqual(rms, expected_rms)
Example #6
0
 def test_1d(self):
     # 1-dimensional input.
     data = as_lazy_data(np.array([5, 2, 6, 4], dtype=np.float64),
                         chunks=-1)
     rms = RMS.lazy_aggregate(data, 0)
     expected_rms = 4.5
     self.assertAlmostEqual(rms, expected_rms)
Example #7
0
 def test_2d_weighted(self):
     # 2-dimensional input with weights
     data = np.array([[4, 7, 10, 8], [14, 16, 20, 8]], dtype=np.float64)
     weights = np.array([[1, 4, 3, 2], [2, 1, 1.5, 0.5]], dtype=np.float64)
     expected_rms = np.array([8.0, 16.0], dtype=np.float64)
     rms = RMS.aggregate(data, 1, weights=weights)
     self.assertArrayAlmostEqual(rms, expected_rms)
Example #8
0
 def test_unit_weighted(self):
     # unit weights should be the same as no weights
     data = np.array([5, 2, 6, 4], dtype=np.float64)
     weights = np.ones_like(data)
     rms = RMS.aggregate(data, 0, weights=weights)
     expected_rms = 4.5
     self.assertAlmostEqual(rms, expected_rms)
Example #9
0
 def test_1d_weighted(self):
     # 1-dimensional input with weights
     data = np.array([4, 7, 10, 8], dtype=np.float64)
     weights = np.array([1, 4, 3, 2], dtype=np.float64)
     expected_rms = 8.0
     rms = RMS.aggregate(data, 0, weights=weights)
     self.assertAlmostEqual(rms, expected_rms)
Example #10
0
 def test_masked_weighted(self):
     # weights should work properly with masked arrays
     data = ma.array([4, 7, 18, 10, 11, 8], mask=[False, False, True, False, True, False], dtype=np.float64)
     weights = np.array([1, 4, 5, 3, 8, 2], dtype=np.float64)
     expected_rms = 8.0
     rms = RMS.aggregate(data, 0, weights=weights)
     self.assertAlmostEqual(rms, expected_rms)
Example #11
0
 def test_2d(self):
     # 2-dimensional input.
     data = as_lazy_data(np.array([[5, 2, 6, 4], [12, 4, 10, 8]],
                                  dtype=np.float64),
                         chunks=-1)
     expected_rms = np.array([4.5, 9.0], dtype=np.float64)
     rms = RMS.lazy_aggregate(data, 1)
     self.assertArrayAlmostEqual(rms, expected_rms)
Example #12
0
 def test_masked(self):
     # masked entries should be completely ignored
     data = ma.array([5, 10, 2, 11, 6, 4],
                     mask=[False, True, False, True, False, False],
                     dtype=np.float64)
     expected_rms = 4.5
     rms = RMS.aggregate(data, 0)
     self.assertAlmostEqual(rms, expected_rms)
Example #13
0
 def test_masked(self):
     # masked entries should be completely ignored
     data = ma.array([5, 10, 2, 11, 6, 4],
                     mask=[False, True, False, True, False, False],
                     dtype=np.float64)
     expected_rms = 4.5
     rms = RMS.aggregate(data, 0)
     self.assertAlmostEqual(rms, expected_rms)
Example #14
0
 def test_masked(self):
     # Masked entries should be completely ignored.
     data = as_lazy_data(ma.array([5, 10, 2, 11, 6, 4],
                         mask=[False, True, False, True, False, False],
                         dtype=np.float64),
                         chunks=-1)
     expected_rms = 4.5
     rms = RMS.lazy_aggregate(data, 0)
     self.assertAlmostEqual(rms, expected_rms)
Example #15
0
 def test_1d_weighted(self):
     # 1-dimensional input with weights.
     data = as_lazy_data(np.array([4, 7, 10, 8], dtype=np.float64))
     weights = np.array([1, 4, 3, 2], dtype=np.float64)
     expected_rms = 8.0
     # https://github.com/dask/dask/issues/3846.
     with self.assertRaisesRegex(TypeError, "unexpected keyword argument"):
         rms = RMS.lazy_aggregate(data, 0, weights=weights)
         self.assertAlmostEqual(rms, expected_rms)
Example #16
0
 def test_unit_weighted(self):
     # Unit weights should be the same as no weights.
     data = as_lazy_data(np.array([5, 2, 6, 4], dtype=np.float64))
     weights = np.ones_like(data)
     expected_rms = 4.5
     # https://github.com/dask/dask/issues/3846.
     with self.assertRaisesRegex(TypeError, "unexpected keyword argument"):
         rms = RMS.lazy_aggregate(data, 0, weights=weights)
         self.assertAlmostEqual(rms, expected_rms)
Example #17
0
 def test_masked_weighted(self):
     # weights should work properly with masked arrays
     data = ma.array([4, 7, 18, 10, 11, 8],
                     mask=[False, False, True, False, True, False],
                     dtype=np.float64)
     weights = np.array([1, 4, 5, 3, 8, 2], dtype=np.float64)
     expected_rms = 8.0
     rms = RMS.aggregate(data, 0, weights=weights)
     self.assertAlmostEqual(rms, expected_rms)
Example #18
0
 def test_1d_weighted(self):
     # 1-dimensional input with weights.
     data = as_lazy_data(np.array([4, 7, 10, 8], dtype=np.float64),
                         chunks=-1)
     weights = np.array([1, 4, 3, 2], dtype=np.float64)
     expected_rms = 8.0
     # https://github.com/dask/dask/issues/3846.
     with self.assertRaisesRegexp(TypeError, 'unexpected keyword argument'):
         rms = RMS.lazy_aggregate(data, 0, weights=weights)
         self.assertAlmostEqual(rms, expected_rms)
Example #19
0
 def test_unit_weighted(self):
     # Unit weights should be the same as no weights.
     data = as_lazy_data(np.array([5, 2, 6, 4], dtype=np.float64),
                         chunks=-1)
     weights = np.ones_like(data)
     expected_rms = 4.5
     # https://github.com/dask/dask/issues/3846.
     with self.assertRaisesRegexp(TypeError, 'unexpected keyword argument'):
         rms = RMS.lazy_aggregate(data, 0, weights=weights)
         self.assertAlmostEqual(rms, expected_rms)
Example #20
0
 def test_masked(self):
     # Masked entries should be completely ignored.
     data = as_lazy_data(ma.array(
         [5, 10, 2, 11, 6, 4],
         mask=[False, True, False, True, False, False],
         dtype=np.float64),
                         chunks=-1)
     expected_rms = 4.5
     rms = RMS.lazy_aggregate(data, 0)
     self.assertAlmostEqual(rms, expected_rms)
Example #21
0
 def test_2d_weighted(self):
     # 2-dimensional input with weights.
     data = as_lazy_data(
         np.array([[4, 7, 10, 8], [14, 16, 20, 8]], dtype=np.float64))
     weights = np.array([[1, 4, 3, 2], [2, 1, 1.5, 0.5]], dtype=np.float64)
     expected_rms = np.array([8.0, 16.0], dtype=np.float64)
     # https://github.com/dask/dask/issues/3846.
     with self.assertRaisesRegex(TypeError, "unexpected keyword argument"):
         rms = RMS.lazy_aggregate(data, 1, weights=weights)
         self.assertArrayAlmostEqual(rms, expected_rms)
Example #22
0
 def test_masked_weighted(self):
     # Weights should work properly with masked arrays, but currently don't
     # (see https://github.com/dask/dask/issues/3846).
     # For now, masked weights are simply not supported.
     data = as_lazy_data(ma.array([4, 7, 18, 10, 11, 8],
                         mask=[False, False, True, False, True, False],
                         dtype=np.float64))
     weights = np.array([1, 4, 5, 3, 8, 2])
     expected_rms = 8.0
     with self.assertRaisesRegex(TypeError, 'unexpected keyword argument'):
         rms = RMS.lazy_aggregate(data, 0, weights=weights)
         self.assertAlmostEqual(rms, expected_rms)
Example #23
0
 def test_masked_weighted(self):
     # Weights should work properly with masked arrays, but currently don't
     # (see https://github.com/dask/dask/issues/3846).
     # For now, masked weights are simply not supported.
     data = as_lazy_data(ma.array([4, 7, 18, 10, 11, 8],
                         mask=[False, False, True, False, True, False],
                         dtype=np.float64),
                         chunks=-1)
     weights = np.array([1, 4, 5, 3, 8, 2])
     expected_rms = 8.0
     with self.assertRaisesRegexp(TypeError, 'unexpected keyword argument'):
         rms = RMS.lazy_aggregate(data, 0, weights=weights)
         self.assertAlmostEqual(rms, expected_rms)
Example #24
0
 def test_1d(self):
     # 1-dimensional input
     data = np.array([5, 2, 6, 4], dtype=np.float64)
     rms = RMS.aggregate(data, 0)
     expected_rms = 4.5
     self.assertAlmostEqual(rms, expected_rms)
Example #25
0
 def test(self):
     shape = ()
     kwargs = dict()
     self.assertTupleEqual(RMS.aggregate_shape(**kwargs), shape)
     kwargs = dict(tom='jerry', calvin='hobbes')
     self.assertTupleEqual(RMS.aggregate_shape(**kwargs), shape)
Example #26
0
 def test(self):
     shape = ()
     kwargs = dict()
     self.assertTupleEqual(RMS.aggregate_shape(**kwargs), shape)
     kwargs = dict(tom='jerry', calvin='hobbes')
     self.assertTupleEqual(RMS.aggregate_shape(**kwargs), shape)
Example #27
0
 def test(self):
     self.assertEqual(RMS.name(), 'root_mean_square')
Example #28
0
 def test(self):
     self.assertEqual(RMS.name(), 'root_mean_square')
Example #29
0
 def test_1d(self):
     # 1-dimensional input
     data = np.array([5, 2, 6, 4], dtype=np.float64)
     rms = RMS.aggregate(data, 0)
     expected_rms = 4.5
     self.assertAlmostEqual(rms, expected_rms)