improver.utilities.cube_checker module

Provides support utilities for checking cubes.

improver.utilities.cube_checker.check_cube_coordinates(cube, new_cube, exception_coordinates=None)[source]

Find and promote to dimension coordinates any scalar coordinates in new_cube that were originally dimension coordinates in the progenitor cube. If coordinate is in new_cube that is not in the old cube, keep coordinate in its current position.

Parameters:
  • cube (iris.cube.Cube) – The input cube that will be checked to identify the preferred coordinate order for the output cube.
  • new_cube (iris.cube.Cube) – The cube that must be checked and adjusted using the coordinate order from the original cube.
  • exception_coordinates (List of strings or None) – The names of the coordinates that are permitted to be within the new_cube but are not available within the original cube.
Returns:

Modified cube with relevant scalar coordinates promoted to dimension coordinates with the dimension coordinates re-ordered, as best as can be done based on the original cube.

Return type:

new_cube (iris.cube.Cube)

Raises:
  • CoordinateNotFoundError – Raised if the final dimension coordinates of the returned cube do not match the input cube.
  • CoordinateNotFoundError – If a coordinate is within in the permitted exceptions but is not in the new_cube.
improver.utilities.cube_checker.check_cube_not_float64(cube, fix=False)[source]

Check a cube does not contain any float64 data, excepting time coordinates. The cube can be modified in place, if the fix keyword is specified to be True.

Parameters:cube (iris.cube.Cube) – The input cube that will be checked for float64 inclusion.
Keyword Arguments:
 fix (bool) – If fix is True, then the cube is amended to not include float64 data, otherwise, an error will be raised if float64 data is found.
Raises:TypeError – Raised if float64 values are found in the cube.
improver.utilities.cube_checker.check_for_x_and_y_axes(cube, require_dim_coords=False)[source]

Check whether the cube has an x and y axis, otherwise raise an error.

Parameters:
  • cube (Iris.cube.Cube) – Cube to be checked for x and y axes.
  • require_dim_coords (bool) – If true the x and y coordinates must be dimension coordinates.
Raises:

ValueError – Raise an error if non-uniform increments exist between grid points.

improver.utilities.cube_checker.find_dimension_coordinate_mismatch(first_cube, second_cube, two_way_mismatch=True)[source]

Determine if there is a mismatch between the dimension coordinates in two cubes.

Parameters:
  • first_cube (Iris.cube.Cube) – First cube to compare.
  • second_cube (Iris.cube.Cube) – Second cube to compare.
  • two_way_mismatch (Logical) –
    If True, a two way mismatch is calculated e.g.
    second_cube - first_cube AND first_cube - second_cube
    If False, a one way mismatch is calculated e.g.
    second_cube - first_cube
Returns:

List of the dimension coordinates that are only present in one out of the two cubes.

Return type:

result (List)

improver.utilities.cube_checker.find_percentile_coordinate(cube)[source]

Find percentile coord in cube.

Parameters:

cube (iris.cube.Cube) – Cube contain one or more percentiles.

Returns:

Percentile coordinate.

Return type:

perc_coord(iris.coords.Coord)

Raises:
  • TypeError – If cube is not of type iris.cube.Cube.
  • CoordinateNotFoundError – If no percentile coordinate is found in cube.
  • ValueError – If there is more than one percentile coords in the cube.
improver.utilities.cube_checker.spatial_coords_match(first_cube, second_cube)[source]

Determine if the x and y coords in the two cubes are the same.

Parameters:
  • first_cube (Iris.cube.Cube) – First cube to compare.
  • second_cube (Iris.cube.Cube) – Second cube to compare.
Returns:

True if the x and y coords are the exactly the same to the precision of the floating-point values (this should be true for any cubes derived using cube.regrid()), otherwise False.

Return type:

result (bool)