class Test__associate_any_coordinate_with_master_coordinate(IrisTest):
    """Test the _associate_any_coordinate_with_master_coordinate method"""

    def setUp(self):
        """Set up default plugin and test cube"""
        self.plugin = ConcatenateCubes("time")
        data = 275.*np.ones((3, 3, 3), dtype=np.float32)
        cube = set_up_variable_cube(
            data, time=dt(2017, 1, 10, 3), frt=dt(2017, 1, 10, 0))
        # cubes can only be concatenated along an existing dimension;
        # therefore promote "time"
        self.cube = iris.util.new_axis(cube, scalar_coord="time")

    def test_forecast_period_association(self):
        """Test forecast period is correctly promoted to associate with time"""
        result = self.plugin._associate_any_coordinate_with_master_coordinate(
            self.cube)
        scalar, aux = check_coord_type(result, "forecast_period")
        self.assertFalse(scalar)
        self.assertTrue(aux)

    def test_forecast_period_not_added(self):
        """Test auxiliary coordinates aren't added if not originally present"""
        self.cube.remove_coord("forecast_period")
        result = self.plugin._associate_any_coordinate_with_master_coordinate(
            self.cube)
        self.assertNotIn("forecast_period", result.coords())

    def test_cube_with_latitude_and_height(self):
        """
        Test that the utility returns an iris.cube.Cube with a height
        coordinate, if this coordinate is added to the input cube. This checks
        that the height coordinate points are not modified.
        """
        plugin = ConcatenateCubes("latitude", coords_to_associate=["height"])

        cube = self.cube
        for latitude_slice in cube.slices_over("latitude"):
            cube = iris.util.new_axis(latitude_slice, "latitude")

        cube.add_aux_coord(
            DimCoord([10], "height", units="m"))

        result = plugin._associate_any_coordinate_with_master_coordinate(
            cube)
        self.assertArrayAlmostEqual(result.coord("height").points, [10])
        scalar, aux = check_coord_type(result, "height")
        self.assertFalse(scalar)
        self.assertTrue(aux)
Ejemplo n.º 2
0
    def test_cube_with_latitude_and_height(self):
        """
        Test that the utility returns an iris.cube.Cube with a height
        coordinate, if this coordinate is added to the input cube. This checks
        that the height coordinate points are not modified.
        """
        plugin = ConcatenateCubes("latitude", coords_to_associate=["height"])

        cube = self.cube
        for latitude_slice in cube.slices_over("latitude"):
            cube = iris.util.new_axis(latitude_slice, "latitude")

        cube.add_aux_coord(DimCoord([10], "height", units="m"))

        result = plugin._associate_any_coordinate_with_master_coordinate(cube)
        self.assertArrayAlmostEqual(result.coord("height").points, [10])
        scalar, aux = check_coord_type(result, "height")
        self.assertFalse(scalar)
        self.assertTrue(aux)