Ejemplo n.º 1
0
 def test_fails_mismatch_array_sizes(self):
     """Test it fails if weights and missing_weights not the same size."""
     weights_in = np.array([0.7, 0.2, 0.1])
     missing_weights = np.ones(2)
     msg = ('Arrays weights and forecast_present not the same size')
     with self.assertRaisesRegexp(ValueError, msg):
         WeightsUtilities.redistribute_weights(weights_in, missing_weights)
Ejemplo n.º 2
0
 def test_fails_weight_less_than_zero(self):
     """Test it fails if weight less than zero. """
     weights_in = np.array([-0.1, 1.1])
     missing_weights = np.ones(2)
     msg = ('Weights should be positive or at least one > 0.0')
     with self.assertRaisesRegexp(ValueError, msg):
         WeightsUtilities.redistribute_weights(weights_in, missing_weights)
Ejemplo n.º 3
0
 def test_fails_sum__not_equal_to_one(self):
     """Test it fails if sum of input weights not equal to one. """
     weights_in = np.array([3.0, 2.0, 1.0])
     missing_weights = np.ones(3)
     msg = ('Sum of weights must be 1.0')
     with self.assertRaisesRegexp(ValueError, msg):
         WeightsUtilities.redistribute_weights(weights_in, missing_weights)
Ejemplo n.º 4
0
 def test_all_missing(self):
     """Test it raises the correct error when none of the expected
        coordinate values are present on the cube."""
     weights_in = np.array([0.6, 0.3, 0.1])
     missing_weights = np.zeros(3)
     msg = 'None of the expected forecasts were found.'
     with self.assertRaisesRegexp(ValueError, msg):
         WeightsUtilities.redistribute_weights(weights_in, missing_weights)
Ejemplo n.º 5
0
 def test_basic(self):
     """Test that the function returns an array of weights. """
     weights_in = np.array([0.6, 0.3, 0.1])
     missing_weights = np.ones(3)
     result = WeightsUtilities.redistribute_weights(weights_in,
                                                    missing_weights)
     self.assertIsInstance(result, np.ndarray)
Ejemplo n.º 6
0
 def test_returns_correct_values_evenly(self):
     """Test it returns the correct values, method is evenly."""
     weights_in = np.array([
         0.41957573, 0.25174544, 0.15104726, 0.09062836, 0.05437701,
         0.03262621
     ])
     missing_weights = np.ones(6)
     missing_weights[2] = 0.0
     result = WeightsUtilities.redistribute_weights(weights_in,
                                                    missing_weights)
     expected_result = np.array(
         [0.44978518, 0.28195489, 0.12083781, 0.08458647, 0.06283566])
     self.assertArrayAlmostEqual(result, expected_result)
Ejemplo n.º 7
0
 def test_returns_correct_values_proportional(self):
     """Test it returns the correct values, method is proportional."""
     weights_in = np.array([
         0.41957573, 0.25174544, 0.15104726, 0.09062836, 0.05437701,
         0.03262621
     ])
     missing_weights = np.ones(6)
     missing_weights[2] = 0.0
     result = WeightsUtilities.redistribute_weights(weights_in,
                                                    missing_weights,
                                                    method='proportional')
     expected_result = np.array(
         [0.49422742, 0.29653645, 0.10675312, 0.06405187, 0.03843112])
     self.assertArrayAlmostEqual(result, expected_result)