def test_source_realizations(self): """Test when the array has source_realization attribute.""" realization_list = [0, 1, 2, 3] cube = (set_up_cube_with_no_realizations( source_realizations=realization_list)) radii = 5600 neighbourhood_method = CircularNeighbourhood() plugin = NBHood(neighbourhood_method, radii) result = plugin.process(cube) self.assertIsInstance(result, Cube) expected = np.ones([1, 16, 16]) expected[0, 6:9, 6:9] = ([0.91666667, 0.875, 0.91666667], [0.875, 0.83333333, 0.875], [0.91666667, 0.875, 0.91666667]) self.assertArrayAlmostEqual(result.data, expected)
def test_radii_varying_with_lead_time(self): """ Test that a cube is returned when the radius varies with lead time. """ cube = set_up_cube(num_time_points=3) iris.util.promote_aux_coord_to_dim_coord(cube, "time") time_points = cube.coord("time").points fp_points = [2, 3, 4] cube = add_forecast_reference_time_and_forecast_period( cube, time_point=time_points, fp_point=fp_points) radii = [10000, 20000, 30000] lead_times = [2, 3, 4] neighbourhood_method = CircularNeighbourhood() plugin = NBHood(neighbourhood_method, radii, lead_times) result = plugin.process(cube) self.assertIsInstance(result, Cube)
def test_radii_varying_with_lead_time_with_interpolation(self): """Test that a cube is returned for the following conditions: 1. The radius varies with lead time. 2. Linear interpolation is required to create values for the radii which are required but were not specified within the 'radii' argument.""" cube = set_up_cube(num_time_points=3) iris.util.promote_aux_coord_to_dim_coord(cube, "time") time_points = cube.coord("time").points fp_points = [2, 3, 4] cube = add_forecast_reference_time_and_forecast_period( cube, time_point=time_points, fp_point=fp_points) radii = [10000, 30000] lead_times = [2, 4] neighbourhood_method = CircularNeighbourhood() plugin = NBHood(neighbourhood_method, radii, lead_times) result = plugin.process(cube) self.assertIsInstance(result, Cube)
def test_radii_varying_with_lead_time_fp_seconds(self): """ Test that a cube fp coord is unchanged by the lead time calculation. """ cube = set_up_cube(num_time_points=3) iris.util.promote_aux_coord_to_dim_coord(cube, "time") time_points = cube.coord("time").points fp_points = [2, 3, 4] cube = add_forecast_reference_time_and_forecast_period( cube, time_point=time_points, fp_point=fp_points) cube.coord("forecast_period").convert_units("seconds") radii = [10000, 20000, 30000] lead_times = [2, 3, 4] neighbourhood_method = CircularNeighbourhood() plugin = NBHood(neighbourhood_method, radii, lead_times) result = plugin.process(cube) self.assertIsInstance(result, Cube) self.assertEqual(cube.coord("forecast_period").units, "seconds")
def test_radii_varying_with_lead_time_with_interpolation_check_data(self): """Test that a cube with the correct data is returned for the following conditions: 1. The radius varies with lead time. 2. Linear interpolation is required to create values for the radii which are required but were not specified within the 'radii' argument.""" cube = set_up_cube(zero_point_indices=((0, 0, 7, 7), ( 0, 1, 7, 7, ), (0, 2, 7, 7)), num_time_points=3) expected = np.ones_like(cube.data) expected[0, 0, 6:9, 6:9] = ([0.91666667, 0.875, 0.91666667], [0.875, 0.83333333, 0.875], [0.91666667, 0.875, 0.91666667]) expected[0, 1, 5:10, 5:10] = SINGLE_POINT_RANGE_3_CENTROID expected[0, 2, 4:11, 4:11] = ([ 1, 0.9925, 0.985, 0.9825, 0.985, 0.9925, 1 ], [0.9925, 0.98, 0.9725, 0.97, 0.9725, 0.98, 0.9925], [0.985, 0.9725, 0.965, 0.9625, 0.965, 0.9725, 0.985], [ 0.9825, 0.97, 0.9625, 0.96, 0.9625, 0.97, 0.9825 ], [0.985, 0.9725, 0.965, 0.9625, 0.965, 0.9725, 0.985], [0.9925, 0.98, 0.9725, 0.97, 0.9725, 0.98, 0.9925], [1, 0.9925, 0.985, 0.9825, 0.985, 0.9925, 1]) iris.util.promote_aux_coord_to_dim_coord(cube, "time") time_points = cube.coord("time").points fp_points = [2, 3, 4] cube = add_forecast_reference_time_and_forecast_period( cube, time_point=time_points, fp_point=fp_points) radii = [5600, 9500] lead_times = [2, 4] neighbourhood_method = CircularNeighbourhood() plugin = NBHood(neighbourhood_method, radii, lead_times) result = plugin.process(cube) self.assertArrayAlmostEqual(result.data, expected)
def test_radii_varying_with_lead_time_check_data(self): """ Test that the expected data is produced when the radius varies with lead time. """ cube = set_up_cube(zero_point_indices=((0, 0, 7, 7), ( 0, 1, 7, 7, ), (0, 2, 7, 7)), num_time_points=3) expected = np.ones_like(cube.data) expected[0, 0, 6:9, 6:9] = ([0.91666667, 0.875, 0.91666667], [0.875, 0.83333333, 0.875], [0.91666667, 0.875, 0.91666667]) expected[0, 1, 5:10, 5:10] = SINGLE_POINT_RANGE_3_CENTROID expected[0, 2, 4:11, 4:11] = ([ 1, 0.9925, 0.985, 0.9825, 0.985, 0.9925, 1 ], [0.9925, 0.98, 0.9725, 0.97, 0.9725, 0.98, 0.9925], [0.985, 0.9725, 0.965, 0.9625, 0.965, 0.9725, 0.985], [ 0.9825, 0.97, 0.9625, 0.96, 0.9625, 0.97, 0.9825 ], [0.985, 0.9725, 0.965, 0.9625, 0.965, 0.9725, 0.985], [0.9925, 0.98, 0.9725, 0.97, 0.9725, 0.98, 0.9925], [1, 0.9925, 0.985, 0.9825, 0.985, 0.9925, 1]) iris.util.promote_aux_coord_to_dim_coord(cube, "time") time_points = cube.coord("time").points fp_points = [2, 3, 4] cube = add_forecast_reference_time_and_forecast_period( cube, time_point=time_points, fp_point=fp_points) radii = [5600, 7600, 9500] lead_times = [2, 3, 4] neighbourhood_method = CircularNeighbourhood() plugin = NBHood(neighbourhood_method, radii, lead_times) result = plugin.process(cube) self.assertArrayAlmostEqual(result.data, expected)