improver.metadata.amend module

Module containing utilities for modifying cube metadata

amend_attributes(cube, attributes_dict)[source]

Add, update or remove attributes from a cube. Modifies cube in place.

Parameters
  • cube (Cube) – Input cube

  • attributes_dict (Dict[str, Any]) – Dictionary containing items of the form {attribute_name: value}. The “value” item is either the string “remove” or the new value of the attribute required.

Return type

None

set_history_attribute(cube, value, append=False)[source]

Add a history attribute to a cube. This uses the current datetime to generate the timestamp for the history attribute. The new history attribute will overwrite any existing history attribute unless the “append” option is set to True. The history attribute is of the form “Timestamp: Description”.

Parameters
  • cube (Cube) – The cube to which the history attribute will be added.

  • value (str) – String defining details to be included in the history attribute.

  • append (bool) – If True, add to the existing history rather than replacing the existing attribute. Default is False.

Return type

None

update_model_id_attr_attribute(cubes, model_id_attr)[source]

Update the dictionary with the unique values of the model_id_attr attribute from within the input cubes. The model_id_attr attribute is expected on all cubes.

Parameters
  • cubes (Union[List[Cube], CubeList]) – List of input cubes that might have a model_id_attr attribute.

  • model_id_attr (str) – Name of attribute expected on the input cubes. This attribute is expected on the cubes as a space-separated string.

Return type

Dict

Returns

Dictionary containing a model_id_attr key, if available.

Raises

AttributeError – Expected to find the model_id_attr attribute on all cubes.

update_stage_v110_metadata(cube)[source]

Translates attributes relating to the grid_id attribute from StaGE version 1.1.0 to later StaGE versions. Cubes that have no “grid_id” attribute are not recognised as v1.1.0 and are ignored.

Parameters

cube (Cube) – Cube to modify attributes in (modified in place)

Return type

None