def test_desc_bounds_all_singleton(self): top = self._make_cube([5], [10, 0]) bottom = self._make_cube([15], [20, 10]) result1 = concatenate([top, bottom]) result2 = concatenate([bottom, top]) self.assertEqual(len(result1), 1) self.assertEqual(len(result2), 1) self.assertEqual(result1, result2)
def test_points_all_singleton(self): top = self._make_cube([5]) bottom = self._make_cube([15]) result1 = concatenate([top, bottom]) result2 = concatenate([bottom, top]) self.assertEqual(len(result1), 1) self.assertEqual(len(result2), 1) self.assertEqual(result1, result2)
def test_definition_difference_message(self): cube_1 = self.cube cube_2 = cube_1.copy() cube_2.units = '1' exc_regexp = 'Cube metadata differs for phenomenon: *' with self.assertRaisesRegexp(ConcatenateError, exc_regexp): result = concatenate([cube_1, cube_2], True)
def test_anonymous_coord_message(self): cube_1 = self.cube cube_2 = cube_1.copy() cube_2.remove_coord('latitude') exc_regexp = 'one or both cubes have anonymous dimensions' with self.assertRaisesRegexp(ConcatenateError, exc_regexp): result = concatenate([cube_1, cube_2], True)
def test_dimensions_metadata_difference_message(self): cube_1 = self.cube cube_2 = cube_1.copy() cube_2.coord('latitude').long_name = 'bob' exc_regexp = 'Dimension coordinates metadata differ: .* != .*' with self.assertRaisesRegexp(ConcatenateError, exc_regexp): result = concatenate([cube_1, cube_2], True)
def test_aux_coords_metadata_difference_message(self): cube_1 = self.cube cube_2 = cube_1.copy() cube_2.coord('foo').units = 'm' exc_regexp = 'Auxiliary coordinates metadata differ: .* != .*' with self.assertRaisesRegexp(ConcatenateError, exc_regexp): result = concatenate([cube_1, cube_2], True)
def test_dimensions_difference_message(self): cube_1 = self.cube cube_2 = cube_1.copy() cube_2.remove_coord('latitude') exc_regexp = 'Dimension coordinates differ: .* != .*' with self.assertRaisesRegexp(ConcatenateError, exc_regexp): result = concatenate([cube_1, cube_2], True)
def test_scalar_coords_difference_message(self): cube_1 = self.cube cube_2 = cube_1.copy() cube_2.remove_coord('height') exc_regexp = 'Scalar coordinates differ: .* != .*' with self.assertRaisesRegexp(ConcatenateError, exc_regexp): result = concatenate([cube_1, cube_2], True)
def test_aux_coords_metadata_difference_message(self): cube_1 = self.cube cube_2 = cube_1.copy() cube_2.coord("foo").units = "m" exc_regexp = "Auxiliary coordinates metadata differ: .* != .*" with self.assertRaisesRegex(ConcatenateError, exc_regexp): _ = concatenate([cube_1, cube_2], True)
def test_scalar_coords_metadata_difference_message(self): cube_1 = self.cube cube_2 = cube_1.copy() cube_2.coord('height').long_name = 'alice' exc_regexp = 'Scalar coordinates metadata differ: .* != .*' with self.assertRaisesRegexp(ConcatenateError, exc_regexp): result = concatenate([cube_1, cube_2], True)
def test_dimensions_metadata_difference_message(self): cube_1 = self.cube cube_2 = cube_1.copy() cube_2.coord("latitude").long_name = "bob" exc_regexp = "Dimension coordinates metadata differ: .* != .*" with self.assertRaisesRegex(ConcatenateError, exc_regexp): _ = concatenate([cube_1, cube_2], True)
def test_concat_1d_with_same_time_units(self): reftimes = ["hours since 1970-01-01 00:00:00", "hours since 1970-01-01 00:00:00"] coords_points = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]] cubes = self.simple_1d_time_cubes(reftimes, coords_points) result = concatenate(cubes) self.assertEqual(len(result), 1) self.assertEqual(result[0].shape, (10,))
def test_lazy_concatenate_masked_array_mixed_deferred(self): c1 = self.build_lazy_cube([1, 2]) c2 = self.build_lazy_cube([3, 4, 5]) c2.data = np.ma.masked_greater(c2.data, 3) cube, = concatenate([c1, c2]) self.assertTrue(cube.has_lazy_data()) self.assertTrue(ma.isMaskedArray(cube.data))
def test_aux_coords_difference_message(self): cube_1 = self.cube cube_2 = cube_1.copy() cube_2.remove_coord("foo") exc_regexp = "Auxiliary coordinates differ: .* != .*" with self.assertRaisesRegexp(ConcatenateError, exc_regexp): result = concatenate([cube_1, cube_2], True)
def test_cell_measure_metadata_difference_message(self): cube_1 = self.cube cube_2 = cube_1.copy() cube_2.cell_measure("bar").units = "m" exc_regexp = "Cell measures metadata differ: .* != .*" with self.assertRaisesRegex(ConcatenateError, exc_regexp): _ = concatenate([cube_1, cube_2], True)
def test_datatype_difference_message(self): cube_1 = self.cube cube_2 = cube_1.copy() cube_2.data.dtype = np.float64 exc_regexp = 'Datatypes differ: .* != .*' with self.assertRaisesRegexp(ConcatenateError, exc_regexp): result = concatenate([cube_1, cube_2], True)
def test_scalar_coords_metadata_difference_message(self): cube_1 = self.cube cube_2 = cube_1.copy() cube_2.coord("height").long_name = "alice" exc_regexp = "Scalar coordinates metadata differ: .* != .*" with self.assertRaisesRegex(ConcatenateError, exc_regexp): _ = concatenate([cube_1, cube_2], True)
def test_ancillary_variable_metadata_difference_message(self): cube_1 = self.cube cube_2 = cube_1.copy() cube_2.ancillary_variable("baz").units = "m" exc_regexp = "Ancillary variables metadata differ: .* != .*" with self.assertRaisesRegex(ConcatenateError, exc_regexp): _ = concatenate([cube_1, cube_2], True)
def test_lazy_concatenate_masked_array_mixed_deferred(self): c1 = self.build_lazy_cube([1, 2]) c2 = self.build_lazy_cube([3, 4, 5]) c2.data = np.ma.masked_greater(c2.data, 3) (cube, ) = concatenate([c1, c2]) self.assertTrue(cube.has_lazy_data()) self.assertTrue(ma.isMaskedArray(cube.data))
def test_concat_1d_with_same_time_units(self): reftimes = ['hours since 1970-01-01 00:00:00', 'hours since 1970-01-01 00:00:00'] coords_points = [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]] cubes = self.simple_1d_time_cubes(reftimes, coords_points) result = concatenate(cubes) self.assertEqual(len(result), 1) self.assertEqual(result[0].shape, (10,))
def test_diff_aux_coord(self): cube_a = self.create_cube() cube_b = cube_a.copy() cube_b.coord('time').points = [12, 18] cube_b.coord('longitude').points = [120, 150] result = concatenate([cube_a, cube_b]) self.assertEqual(len(result), 2)
def test_lazy_biggus_concatenate_masked_array_mixed_deffered(self): c1 = self.build_lazy_cube([1, 2]) c2 = self.build_lazy_cube([3, 4, 5]) c2.data = np.ma.masked_greater(c2.data, 3) self.assertFalse(c2.has_lazy_data()) cube, = concatenate([c1, c2]) self.assertTrue(cube.has_lazy_data()) self.assertIsInstance(cube.data, np.ma.MaskedArray)
def test_diff_ancillary_variables(self): cube_a = self.create_cube() cube_b = cube_a.copy() cube_b.coord("time").points = [12, 18] cube_b.ancillary_variable("quality").data = [120, 150] result = concatenate([cube_a, cube_b]) self.assertEqual(len(result), 2)
def test_diff_aux_coord(self): cube_a = self.create_cube() cube_b = cube_a.copy() cube_b.coord("time").points = [12, 18] cube_b.coord("longitude").points = [120, 150] result = concatenate([cube_a, cube_b]) self.assertEqual(len(result), 2)
def test_diff_cell_measure(self): cube_a = self.create_cube() cube_b = cube_a.copy() cube_b.coord("time").points = [12, 18] cube_b.cell_measure("volume").data = [120, 150] result = concatenate([cube_a, cube_b]) self.assertEqual(len(result), 2)
def test_ignore_diff_aux_coord(self): cube_a = self.create_cube() cube_b = cube_a.copy() cube_b.coord("time").points = [12, 18] cube_b.coord("longitude").points = [120, 150] result = concatenate([cube_a, cube_b], check_aux_coords=False) self.assertEqual(len(result), 1) self.assertEqual(result[0].shape, (4, 2))
def test_ignore_diff_ancillary_variables(self): cube_a = self.create_cube() cube_b = cube_a.copy() cube_b.coord("time").points = [12, 18] cube_b.ancillary_variable("quality").data = [120, 150] result = concatenate([cube_a, cube_b], check_ancils=False) self.assertEqual(len(result), 1) self.assertEqual(result[0].shape, (4, 2))
def test_ignore_diff_cell_measure(self): cube_a = self.create_cube() cube_b = cube_a.copy() cube_b.coord("time").points = [12, 18] cube_b.cell_measure("volume").data = [120, 150] result = concatenate([cube_a, cube_b], check_cell_measures=False) self.assertEqual(len(result), 1) self.assertEqual(result[0].shape, (4, 2))
def test_matching_2d_longitudes(self): cube1 = self.cube cube1.add_dim_coord(self.y_coord, 1) cube1.add_aux_coord(self.x_coord_2D, (1, 2)) cube2 = cube1.copy() cube2.coord("time").points = [12, 18] result = concatenate([cube1, cube2]) self.assertEqual(len(result), 1)
def test_matching_2d_longitudes(self): cube1 = self.cube cube1.add_dim_coord(self.y_coord, 1) cube1.add_aux_coord(self.x_coord_2D, (1, 2)) cube2 = cube1.copy() cube2.coord('time').points = [12, 18] result = concatenate([cube1, cube2]) self.assertEqual(len(result), 1)
def test_concat_1d_with_differing_time_units(self): reftimes = ['hours since 1970-01-01 00:00:00', 'hours since 1970-01-02 00:00:00'] coords_points = [[1, 2, 3, 4, 5], [1, 2, 3, 4, 5]] cubes = self.simple_1d_time_cubes(reftimes, coords_points) unify_time_units(cubes) result = concatenate(cubes) self.assertEqual(len(result), 1) self.assertEqual(result[0].shape, (10,))
def test_ignore_diff_aux_coord(self): cube_a = self.create_cube() cube_b = cube_a.copy() cube_b.coord('time').points = [12, 18] cube_b.coord('longitude').points = [120, 150] result = concatenate([cube_a, cube_b], check_aux_coords=False) self.assertEqual(len(result), 1) self.assertEqual(result[0].shape, (4, 2))
def test_concatenate_along_anon_dim(self): cube1 = self.cube cube1.add_aux_coord(self.y_coord_non_monotonic, 1) cube1.add_aux_coord(self.x_coord, 2) cube2 = cube1.copy() cube2.coord('latitude').points = [30, 0, 15] result = concatenate([cube1, cube2]) self.assertEqual(len(result), 2)
def test_anonymous_coord_message(self): cube_1 = self.cube cube_1.remove_coord('latitude') cube_2 = cube_1.copy() with warnings.catch_warnings(record=True) as warn: warnings.simplefilter("always") result = concatenate([cube_1, cube_2], True) self.assertEqual(len(warn), 1) msg = 'One or both cubes have anonymous dimensions' six.assertRegex(self, str(warn[0].message), msg)
def test_matching_non_monotonic_latitudes(self): cube1 = self.cube cube1.add_aux_coord(self.y_coord_non_monotonic, 1) cube1.add_aux_coord(self.x_coord, 2) cube2 = cube1.copy() cube2.coord("time").points = [12, 18] result = concatenate([cube1, cube2]) self.assertEqual(len(result), 1)
def test_matching_non_monotonic_latitudes(self): cube1 = self.cube cube1.add_aux_coord(self.y_coord_non_monotonic, 1) cube1.add_aux_coord(self.x_coord, 2) cube2 = cube1.copy() cube2.coord('time').points = [12, 18] result = concatenate([cube1, cube2]) self.assertEqual(len(result), 1)
def test_concatenate_along_anon_dim(self): cube1 = self.cube cube1.add_aux_coord(self.y_coord_non_monotonic, 1) cube1.add_aux_coord(self.x_coord, 2) cube2 = cube1.copy() cube2.coord("latitude").points = [30, 0, 15] result = concatenate([cube1, cube2]) self.assertEqual(len(result), 2)
def test_concatenate_anom_1st_dim(self): # Check that concatenation along a non anonymous dimension is # insensitive to the dimension which is anonymous. # Concatenate along longitude. # DIM: cube(--, lat, lon) & cube(--, lat, lon') # AUX: cube(wibble, --, --) & cube(wibble, --, --) cube1 = self.cube[..., :2] cube2 = self.cube[..., 2:] result = concatenate([cube1, cube2]) self.assertEqual(len(result), 1)
def test_ndim_difference_message(self): cube_1 = self.cube cube_2 = iris.cube.Cube(np.arange(5, dtype=np.float32), standard_name="air_temperature", units="K") x_coord = iris.coords.DimCoord( points=np.arange(5, dtype=np.float32), standard_name="longitude", units="degrees" ) cube_2.add_dim_coord(x_coord, 0) exc_regexp = "Data dimensions differ: [0-9] != [0-9]" with self.assertRaisesRegexp(ConcatenateError, exc_regexp): result = concatenate([cube_1, cube_2], True)
def test_differing_2d_longitudes(self): cube1 = self.cube cube1.add_aux_coord(self.y_coord, 1) cube1.add_aux_coord(self.x_coord_2D, (1, 2)) cube2 = cube1.copy() cube2.coord("time").points = [12, 18] cube2.coord("longitude").points = [[-30, -15], [0, 15], [30, 45]] result = concatenate([cube1, cube2]) self.assertEqual(len(result), 2)
def test_differing_2d_longitudes(self): cube1 = self.cube cube1.add_aux_coord(self.y_coord, 1) cube1.add_aux_coord(self.x_coord_2D, (1, 2)) cube2 = cube1.copy() cube2.coord('time').points = [12, 18] cube2.coord('longitude').points = [[-30, -15], [0, 15], [30, 45]] result = concatenate([cube1, cube2]) self.assertEqual(len(result), 2)
def test_concat_1d_with_differing_time_units(self): reftimes = [ "hours since 1970-01-01 00:00:00", "hours since 1970-01-02 00:00:00", ] coords_points = [[1, 2, 3, 4, 5], [1, 2, 3, 4, 5]] cubes = self.simple_1d_time_cubes(reftimes, coords_points) unify_time_units(cubes) result = concatenate(cubes) self.assertEqual(len(result), 1) self.assertEqual(result[0].shape, (10, ))
def test_differing_non_monotonic_latitudes(self): cube1 = self.cube cube1.add_aux_coord(self.y_coord_non_monotonic, 1) cube1.add_aux_coord(self.x_coord, 2) cube2 = cube1.copy() cube2.coord("time").points = [12, 18] cube2.coord("latitude").points = [30, 0, 15] result = concatenate([cube1, cube2]) self.assertEqual(len(result), 2)
def test_concatenate_anom_3rd_dim(self): # Check that concatenation along a non anonymous dimension is # insensitive to the dimension which is anonymous. # Concatenate along longitude. # DIM: cube(lat, lon, --) & cube(lat, lon', --) # AUX: cube(--, --, wibble) & cube(--, --, wibble) cube1 = self.cube[..., :2] cube2 = self.cube[..., 2:] cube1.transpose((1, 2, 0)) cube2.transpose((1, 2, 0)) result = concatenate([cube1, cube2]) self.assertEqual(len(result), 1)
def test_lazy_concatenate(self): c1 = self.build_lazy_cube([1, 2]) c2 = self.build_lazy_cube([3, 4, 5]) cube, = concatenate([c1, c2]) self.assertTrue(cube.has_lazy_data()) self.assertFalse(ma.isMaskedArray(cube.data))
def test_desc_bounds(self): top = self._make_cube([67.5, 22.5], [[90, 45], [45, 0]]) bottom = self._make_cube([-22.5, -67.5], [[0, -45], [-45, -90]]) result = concatenate([top, bottom]) self.assertEqual(len(result), 1)
def test_desc_points(self): top = self._make_cube([90, 70, 50, 30, 10]) bottom = self._make_cube([-10, -30, -50, -70, -90]) result = concatenate([top, bottom]) self.assertEqual(len(result), 1)
def test_lazy_biggus_concatenate(self): c1 = self.build_lazy_cube([1, 2]) c2 = self.build_lazy_cube([3, 4, 5]) cube, = concatenate([c1, c2]) self.assertTrue(cube.has_lazy_data()) self.assertNotIsInstance(cube.data, np.ma.MaskedArray)