improver.utilities.cube_checker module

Provides support utilities for checking cubes.

assert_spatial_coords_match(cubes)[source]

Raises an Exception if spatial_coords_match returns False.

Parameters:

cubes (Union[List, CubeList]) – A list of cubes to compare.

Raises:

ValueError if spatial coords do not match.

assert_time_coords_valid(inputs, time_bounds)[source]

Raises appropriate ValueError if

  • Any input cube has or is missing time bounds (depending on time_bounds)

  • Input cube times do not match

  • Input cube forecast_reference_times do not match (unless blend_time is present)

Note that blend_time coordinates do not have to match as it is likely that data from nearby blends will be used together.

Parameters:
  • inputs (List[Cube]) – List of Cubes where times should match

  • time_bounds (bool) – When True, time bounds are checked for and compared on the input cubes. When False, the absence of time bounds is checked for.

Raises:

ValueError – If any of the stated checks fail.

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 (Cube) – The input cube that will be checked to identify the preferred coordinate order for the output cube.

  • new_cube (Cube) – The cube that must be checked and adjusted using the coordinate order from the original cube.

  • exception_coordinates (Optional[List[str]]) – The names of the coordinates that are permitted to be within the new_cube but are not available within the original cube.

Return type:

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.

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.

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 (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.

Return type:

None

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 (Cube) – First cube to compare.

  • second_cube (Cube) – Second cube to compare.

  • two_way_mismatch (bool) –

    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

Return type:

List[str]

Returns:

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

spatial_coords_match(cubes)[source]

Determine if the x and y coords of all the input cubes are the same.

Parameters:

cubes (Union[List, CubeList]) – A list of cubes to compare.

Return type:

bool

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.