def test_error_unmatched_weights(self):
     """Test error when weights shape doesn't match length of blend dimension
     (in this case 3 weights for 2 blend slices)"""
     weights = generate_matching_weights_array([0.7, 0.1, 0.2], 1)
     percentiles = np.array([0, 50, 100])
     perc_data = np.array([[1.0, 2.0], [5.0, 5.0], [10.0, 9.0]])
     with self.assertRaisesRegex(ValueError,
                                 "Weights shape does not match data"):
         PercentileBlendingAggregator.aggregate(perc_data, 1, percentiles,
                                                weights)
 def test_blend_percentile_aggregate(self):
     """Test blend_percentile_aggregate function works"""
     weights = np.array([0.8, 0.2])
     percentiles = np.array([0, 20, 40, 60, 80, 100])
     result = PercentileBlendingAggregator.aggregate(
         np.reshape(PERCENTILE_DATA, (6, 2, 2, 2)), 1, percentiles, weights,
         0)
     expected_result_array = np.reshape(BLENDED_PERCENTILE_DATA2, (6, 2, 2))
     self.assertArrayAlmostEqual(result, expected_result_array)
 def test_3D_simple_case(self):
     """ Test that for a simple case with only one point and an extra
         internal dimension behaves as expected"""
     weights = np.array([0.5, 0.5])
     percentiles = np.array([0, 50, 100])
     perc_data = np.array([[[1.0], [2.0]], [[5.0], [6.0]], [[10.0], [9.0]]])
     result = PercentileBlendingAggregator.aggregate(
         perc_data, 1, percentiles, weights, 0)
     expected_result = np.array([[1.0], [5.555555], [10.0]])
     self.assertArrayAlmostEqual(result, expected_result)
 def test_2D_simple_case(self):
     """ Test that for a simple case with only one point in the resulting
         array the function behaves as expected"""
     weights = np.array([0.8, 0.2])
     percentiles = np.array([0, 50, 100])
     perc_data = np.array([[1.0, 2.0], [5.0, 5.0], [10.0, 9.0]])
     result = PercentileBlendingAggregator.aggregate(
         perc_data, 1, percentiles, weights, 0)
     expected_result = np.array([1.0, 5.0, 10.0])
     self.assertArrayAlmostEqual(result, expected_result)
 def test_blend_percentile_aggregate(self):
     """Test blend_percentile_aggregate function works"""
     weights = generate_matching_weights_array([0.6, 0.3, 0.1], 4)
     percentiles = np.array([0, 20, 40, 60, 80, 100]).astype(np.float32)
     result = PercentileBlendingAggregator.aggregate(
         PERCENTILE_DATA, 1, percentiles, weights)
     self.assertArrayAlmostEqual(
         result,
         BLENDED_PERCENTILE_DATA,
     )
 def test_blend_percentile_aggregate_reorder2(self):
     """Test blend_percentile_aggregate works with out of order dims 2"""
     weights = np.array([0.8, 0.2])
     percentiles = np.array([0, 20, 40, 60, 80, 100])
     perc_data = np.reshape(PERCENTILE_DATA, (6, 2, 2, 2))
     perc_data = np.moveaxis(perc_data, [0, 1], [1, 2])
     result = PercentileBlendingAggregator.aggregate(
         perc_data, 2, percentiles, weights, 1)
     expected_result_array = np.reshape(BLENDED_PERCENTILE_DATA2, (6, 2, 2))
     expected_result_array = np.moveaxis(expected_result_array, 0, 1)
     self.assertArrayAlmostEqual(result, expected_result_array)
Example #7
0
    def test_blend_percentile_aggregate(self):
        """Test blend_percentile_aggregate function works"""
        weights = np.array([0.6, 0.3, 0.1])
        weights = generate_matching_weights_array(weights, (4, 6, 3))
        weights = np.moveaxis(weights, (0, 1, 2), (2, 1, 0))

        percentiles = np.array([0, 20, 40, 60, 80, 100]).astype(np.float32)
        result = PercentileBlendingAggregator.aggregate(
            np.reshape(PERCENTILE_DATA, (6, 3, 2, 2)), 1, percentiles, weights, 0
        )
        self.assertArrayAlmostEqual(
            result, BLENDED_PERCENTILE_DATA,
        )
 def test_4D_simple_case(self):
     """ Test that for a simple case with only one point and 4D input data
         it behaves as expected"""
     weights = np.array([0.5, 0.5])
     percentiles = np.array([0, 50, 100])
     perc_data = np.array([1.0, 3.0, 2.0, 4.0, 5.0, 6.0])
     input_shape = (3, 2, 1, 1)
     perc_data = perc_data.reshape(input_shape)
     result = PercentileBlendingAggregator.aggregate(
         perc_data, 1, percentiles, weights, 0)
     expected_result = np.array([[[1.0]], [[3.5]], [[6.0]]])
     expected_result_shape = (3, 1, 1)
     self.assertArrayAlmostEqual(result, expected_result)
     self.assertEqual(result.shape, expected_result_shape)
Example #9
0
    def test_blend_percentile_aggregate_reorder2(self):
        """Test blend_percentile_aggregate works with out of order dims 2"""
        weights = np.array([0.6, 0.3, 0.1])
        weights = generate_matching_weights_array(weights, (4, 6, 3))
        weights = np.moveaxis(weights, (0, 1, 2), (2, 1, 0))

        percentiles = np.array([0, 20, 40, 60, 80, 100])
        perc_data = np.reshape(PERCENTILE_DATA, (6, 3, 2, 2))
        perc_data = np.moveaxis(perc_data, [0, 1], [1, 2])
        result = PercentileBlendingAggregator.aggregate(
            perc_data, 2, percentiles, weights, 1)
        expected_result_array = BLENDED_PERCENTILE_DATA
        expected_result_array = np.moveaxis(expected_result_array, 0, 1)
        self.assertArrayAlmostEqual(result, expected_result_array)