def test_number_of_slices_from_one_cube(self):
        """
        Test that the number of cubes returned, after slicing over the
        given coordinate is as expected.
        """
        cube1 = self.cube.copy()
        cube2 = self.cube.copy()
        cube2.coord("time").points = 402195.5
        time_origin = "hours since 1970-01-01 00:00:00"
        calendar = "gregorian"
        tunit = Unit(time_origin, calendar)
        cube1.add_aux_coord(DimCoord([402192.5],
                                     "forecast_reference_time",
                                     units=tunit),
                            data_dims=1)
        cube1.add_aux_coord(DimCoord([0], "forecast_period", units="hours"),
                            data_dims=1)
        cube2.add_aux_coord(DimCoord([402195.5],
                                     "forecast_reference_time",
                                     units=tunit),
                            data_dims=1)
        cube2.add_aux_coord(DimCoord([3], "forecast_period", units="hours"),
                            data_dims=1)

        cubelist = iris.cube.CubeList([cube1, cube2])

        cubelist = cubelist.concatenate_cube()

        result = _slice_over_coordinate(cubelist, "forecast_period")
        self.assertEqual(len(result), 2)
 def test_time_first_dimension(self):
     """
     Test that the first dimension of the output cube within the
     output cubelist has time as the first dimension.
     """
     cubelist = iris.cube.CubeList([self.cube])
     result = _slice_over_coordinate(cubelist, "time")
     dim_coord_names = []
     for cube in result:
         for dim_coord in cube.dim_coords:
             dim_coord_names.append(dim_coord.name())
     self.assertEqual(dim_coord_names[0], "time")
    def test_cubelist_no_history_removal(self):
        """
        Test that the utility returns an iris.cube.Cube with a
        history attribute and with the remove_history keyword argument
        set to True.
        """
        cube1 = self.cube.copy()
        cube2 = self.cube.copy()
        cube2.coord("time").points = 402195.0
        cube1.attributes["history"] = "2017-01-18T08:59:53: StaGE Decoupler"
        cube2.attributes["history"] = "2017-01-18T08:59:53: StaGE Decoupler"

        cubelist = iris.cube.CubeList([cube1, cube2])

        result = _slice_over_coordinate(cubelist, "time", remove_history=False)
        self.assertIn("history", result[0].attributes.keys())
        self.assertIn("history", result[1].attributes.keys())
    def test_cubelist_history_removal(self):
        """
        Test that the utility returns an iris.cube.Cube without a
        history attribute, given that the utility will try to remove the
        history attribute, if it exists.
        """
        cube1 = self.cube.copy()
        cube2 = self.cube.copy()
        cube2.coord("time").points = 402195.0
        cube1.attributes["history"] = "2017-01-18T08:59:53: StaGE Decoupler"
        cube2.attributes["history"] = "2017-01-19T08:59:53: StaGE Decoupler"

        cubelist = iris.cube.CubeList([cube1, cube2])

        result = _slice_over_coordinate(cubelist, "time")
        self.assertNotIn("history", result[0].attributes.keys())
        self.assertNotIn("history", result[1].attributes.keys())
 def test_basic_cube(self):
     """Test that the utility returns an iris.cube.CubeList."""
     result = _slice_over_coordinate(self.cube, "time")
     self.assertIsInstance(result, iris.cube.CubeList)