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 str 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
- 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_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
list of str
-
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
-
improver.utilities.cube_checker.time_coords_match(first_cube, second_cube, raise_exception=False)[source]¶ Determine if two cubes have equivalent time, forecast_period, and forecast_reference_time points.
- Parameters
first_cube (iris.cube.Cube) – First cube to compare.
second_cube (iris.cube.Cube) – Second cube to compare.
raise_exception (bool) – By default this function returns a boolean, but if this argument is set to True it will raise an exception if there is a mismatch in the coordinates.
- Returns
True if the cube time coordinates are equivalent, False if they are not.
- Return type
- Raised:
ValueError: The two cubes are not equivalent. CoordinateNotFoundError: One of the expected temporal coordinates is not present on one or more cubes.