improver.metadata.check_datatypes module

Utilities for mandatory datatype and units checking

_is_time_coord(obj)[source]

Checks whether the supplied object is an iris.coords.Coord and has a name that matches a known time coord.

Parameters:

obj (Union[Cube, Coord]) – Object to be tested

Return type:

bool

Returns:

True if obj is a recognised time coord.

check_dtype(obj)[source]

Finds the mandatory dtype for obj and checks that it is correctly applied. If obj is a coord, any bounds are checked too.

Parameters:

obj (Union[Cube, Coord]) – Object to be tested

Return type:

bool

Returns:

True if obj is of the mandated dtype.

check_mandatory_standards(cube)[source]

Checks for mandatory dtype and unit standards on a cube and raises a useful exception if any non-compliance is found.

Parameters:

cube (Cube) – The cube to be checked for conformance with standards.

Raises:

ValueError – If the cube fails to meet any mandatory dtype and units standards

Return type:

None

check_units(obj)[source]

Checks if the supplied object complies with the relevant mandatory units.

Parameters:

obj (Union[Cube, Coord]) – Object to be tested

Return type:

bool

Returns:

True if obj meets the mandatory units requirements or has no mandatory units requirement.

enforce_dtype(operation, inputs, result)[source]

Ensures that result has not been automatically promoted to float64.

Parameters:
  • operation (str) – The operation that was performed (for the error message)

  • inputs (Union[List[Cube], CubeList]) – The Numpy arrays or cubes that the operation was performed on (for the error message)

  • result (Cube) – The result of the operation

Raises:

TypeError – If result.dtype does not match the meta-data standard.

Return type:

None

get_required_dtype(obj)[source]

Returns the appropriate dtype for the supplied object. This includes special dtypes for time coordinates.

Parameters:

obj (Union[Cube, Coord]) – Object to be tested

Return type:

dtype

Returns:

The mandatory dtype corresponding to the object supplied.

get_required_units(obj)[source]

Returns the mandatory units for the supplied obj. Only time coords have these.

Parameters:

obj (Union[Cube, Coord]) – Object to be tested

Return type:

Optional[str]

Returns:

The mandatory units corresponding to the object supplied or None if there are no specific requirements for the object.