improver.standardise module#

Plugin to standardise metadata

class StandardiseMetadata(new_name=None, new_units=None, coords_to_remove=None, coord_modification=None, coord_attribute_modification=None, attributes_dict=None, ancillary_variables_to_remove=None)[source]#

Bases: BasePlugin

Plugin to standardise cube metadata

__init__(new_name=None, new_units=None, coords_to_remove=None, coord_modification=None, coord_attribute_modification=None, attributes_dict=None, ancillary_variables_to_remove=None)[source]#

Instantiate our class for standardising cube metadata.

Parameters:
  • new_name (Optional[str]) – Optional rename for output cube

  • new_units (Optional[str]) – Optional unit conversion for output cube

  • coords_to_remove (Optional[List[str]]) – Optional list of scalar coordinates to remove from output cube

  • coord_modification (Optional[Dict[str, float]]) – Optional dictionary used to directly modify the values of scalar coordinates. To be used with extreme caution. For example this dictionary might take the form: {“height”: 1.5} to set the height coordinate to have a value of 1.5m (assuming original units of m). This can be used to align e.g. temperatures defined at slightly different heights where this difference is considered small enough to ignore. Type is inferred, so providing a value of 2 will result in an integer type, whilst a value of 2.0 will result in a float type.

  • coord_attribute_modification (Optional[Dict[str, Dict[str, Any]]]) – Optional dictionary used to modify attributes of scalar coordinates. Takes the form: {“coord_name”: {“attr_key”: “attr_value”, …}, …} For example: {“height”: {“positive”: “up”}} to set the positive attribute on the height coordinate. Multiple attributes can be set on a single coordinate, and multiple coordinates can be modified. If the coordinate does not exist, the modification is silently skipped.

  • attributes_dict (Optional[Dict[str, Any]]) – Optional dictionary of required attribute updates. Keys are attribute names, and values are the required changes. See improver.metadata.amend.amend_attributes for details.

  • ancillary_variables_to_remove (Optional[List[str]]) – Optional list of ancillary variable names to remove from the output cube.

_abc_impl = <_abc._abc_data object>#
static _collapse_scalar_dimensions(cube)[source]#

Demote any scalar dimensions (excluding “realization”) on the input cube to auxiliary coordinates.

Parameters:

cube (Cube) – The cube

Return type:

Cube

Returns:

The collapsed cube

static _discard_redundant_cell_methods(cube)[source]#

Removes cell method “point”: “time” from cube if present.

Return type:

None

static _modify_scalar_coord_attributes(cube, coord_attribute_modification)[source]#

Modifies the attributes of each specified scalar coordinate. Modifying attributes of dimension coordinates or time coordinates is specifically prevented as there is greater scope to harm data integrity.

If the coordinate does not exist the modification request is silently skipped.

Parameters:
  • cube (Cube) – Cube to be updated in place

  • coord_attribute_modification (Dict[str, Dict[str, Any]]) – Dictionary defining the coordinates (keys) and attributes (nested dict values) to be modified. For example: {“height”: {“positive”: “up”}}

Raises:

ValueError – If attempting to modify attributes on a dimension coordinate, a time coordinate, or if prohibited coordinate attributes are provided.

Return type:

None

static _modify_scalar_coord_value(cube, coord_modification)[source]#

Modifies the value of each specified scalar coord (dictionary key) to the provided value (dictionary value). Note that data types are not enforced here as the subsequent enforcement step will fulfil this requirement. Units are assumed to be the same as the original coordinate value. Modifying multi-valued coordinates or time coordinates is specifically prevented as there is greater scope to harm data integrity (i.e. the description of the data and the data becoming misaligned).

If the coordinate does not exist the modification request is silently skipped.

Parameters:
  • cube (Cube) – Cube to be updated in place

  • coord_modification (Dict[str, float]) – Dictionary defining the coordinates (keys) to be modified and the values (values) to which they should be set.

Raises:

ValueError – If attempting to modify a dimension coordinate, a multi-valued coordinate, or a time coordinate.

Return type:

None

static _remove_ancillary_variables(cube, ancillary_variables_to_remove)[source]#

Removes named ancillary variables from the input cube.

Return type:

None

static _remove_long_name_if_standard_name(cube)[source]#

Remove the long_name attribute from cubes if the cube also has a standard_name defined

Return type:

None

static _remove_scalar_coords(cube, coords_to_remove)[source]#

Removes named coordinates from the input cube.

Return type:

None

static _standardise_dtypes_and_units(cube)[source]#

Modify input cube in place to conform to mandatory dtype and unit standards.

Parameters:

cube (Cube) – Cube to be updated in place

Return type:

None

process(cube)[source]#

Perform compulsory and user-configurable metadata adjustments. The compulsory adjustments are:

  • to collapse any scalar dimensions apart from realization (which is expected always to be a dimension);

  • to cast the cube data and coordinates into suitable datatypes;

  • to convert time-related metadata into the required units

  • to remove cell method (“point”: “time”).

Parameters:

cube (Cube) – Input cube to be standardised

Return type:

Cube

Returns:

The processed cube