Exemple #1
0
 def setUp(self):
     """Set up a cube."""
     data = np.zeros((1, 1, 5, 5))
     data[0, 0, 0, 1] = 1.0
     data[0, 0, 2, 3] = 1.0
     y_dimension_values = np.arange(0.0, 10000.0, 2000.0)
     self.cube = set_up_cube(data, "lwe_precipitation_rate", "m s-1",
                             y_dimension_values=y_dimension_values,
                             x_dimension_values=y_dimension_values)
Exemple #2
0
 def test_additional_arguments(self):
     """Test when all keyword arguments are passed in."""
     expected = np.array(
         [[[1., 1., 0.8333333, 0.666667, 0.5],
           [0.66666667, 0.77777778, 0.77777778, 0.77777778, 0.66666667],
           [0.33333333, 0.55555556, 0.77777778, 1., 1.],
           [0., 0.22222222, 0.44444444, 0.66666667, 0.66666667],
           [0., 0.16666667, 0.33333333, 0.5, 0.5]],
          [[0.77777778, 0.75, 0.73333333, 0.75, 0.77777778],
           [0.66666667, 0.6875, 0.7, 0.75, 0.8333333],
           [0.53333333, 0.55, 0.56, 0.6, 0.66666667],
           [0.41666667, 0.5, 0.55, 0.625, 0.75],
           [0.22222222, 0.33333333, 0.4, 0.5, 0.66666667]]])
     data = np.zeros((1, 2, 5, 5))
     data[0, :, 0, 1] = 1.0
     data[0, :, 2, 3] = 1.0
     y_dimension_values = np.arange(0.0, 10000.0, 2000.0)
     cube = set_up_cube(data,
                        "lwe_precipitation_rate",
                        "m s-1",
                        y_dimension_values=y_dimension_values,
                        x_dimension_values=y_dimension_values,
                        timesteps=np.array([402192.5, 402195.5]))
     distance = 2000
     neighbourhood_method = "square"
     radii = [2000, 4000]
     lead_times = [3, 6]
     cube.add_aux_coord(
         AuxCoord(lead_times, "forecast_period", units="hours"), 1)
     weighted_mode = False
     ens_factor = 0.9
     expected_cube_for_shape = cube.copy()
     expected_cube_for_shape = expected_cube_for_shape.collapsed(
         "realization", MEAN)
     orig_shape = expected_cube_for_shape.data.copy().shape
     result = (ProbabilityOfOccurrence(distance,
                                       neighbourhood_method,
                                       radii,
                                       lead_times=lead_times,
                                       weighted_mode=weighted_mode,
                                       ens_factor=ens_factor).process(cube))
     self.assertIsInstance(result, Cube)
     self.assertArrayAlmostEqual(result.data, expected)
     self.assertEqual(result.data.shape, orig_shape)
     self.assertEqual(result.coord("forecast_period").units, "hours")
 def test_additional_arguments(self):
     """Test when all keyword arguments are passed in."""
     expected = np.array(
         [[[[1., 1., 0.77777778, 0.55555556, 0.333333],
            [0.66666667, 0.77777778, 0.77777778, 0.77777778, 0.66666667],
            [0.33333333, 0.55555556, 0.77777778, 1., 1.],
            [0., 0.22222222, 0.44444444, 0.66666667, 0.66666667],
            [0., 0.11111111, 0.22222222, 0.33333333, 0.33333333]],
           [[0.84, 0.8, 0.76, 0.72, 0.68], [0.68, 0.7, 0.72, 0.74, 0.76],
            [0.48, 0.52, 0.56, 0.6, 0.64], [0.3, 0.4, 0.5, 0.6, 0.7],
            [0.12, 0.24, 0.36, 0.48, 0.6]]]])
     data = np.zeros((1, 2, 5, 5))
     data[0, :, 0, 1] = 1.0
     data[0, :, 2, 3] = 1.0
     y_dimension_values = np.arange(0.0, 10000.0, 2000.0)
     cube = set_up_cube(data,
                        "lwe_precipitation_rate",
                        "m s-1",
                        y_dimension_values=y_dimension_values,
                        x_dimension_values=y_dimension_values,
                        timesteps=np.array([402192.5, 402195.5]))
     distance = 2000
     neighbourhood_method = "square"
     radii = [2000, 4000]
     lead_times = [3, 6]
     cube.add_aux_coord(
         AuxCoord(lead_times, "forecast_period", units="hours"), 1)
     unweighted_mode = True
     ens_factor = 0.9
     result = (ProbabilityOfOccurrence(distance,
                                       neighbourhood_method,
                                       radii,
                                       lead_times=lead_times,
                                       unweighted_mode=unweighted_mode,
                                       ens_factor=ens_factor).process(cube))
     self.assertIsInstance(result, Cube)
     self.assertArrayAlmostEqual(result.data, expected)