improver.metadata.amend module

Module containing utilities for modifying cube metadata

improver.metadata.amend.add_coord(cube, coord_name, changes, warnings_on=False)[source]

Add coord to the cube.

Parameters
  • cube (iris.cube.Cube) – Cube containing combined data.

  • coord_name (str) – Name of the coordinate being added.

  • changes (dict) – Details of coordinate to be added to the cube, with string keys. Valid keys are ‘metatype’ (which should have value ‘DimCoord’ or ‘AuxCoord’), ‘points’, ‘bounds’, ‘units’, ‘attributes’ and ‘var_name’. Any other key strings in the dictionary are ignored. More detail is available in improver.metadata.amend.amend_metadata()

  • warnings_on (bool) – If True output warnings for mismatching metadata.

Returns

Cube with added coordinate.

Return type

iris.cube.Cube

Raises
  • ValueError – Trying to add new coord but no points defined.

  • ValueError – Can not add a coordinate of length > 1

  • UserWarning – adding new coordinate.

improver.metadata.amend.amend_attributes(cube, attributes_dict)[source]

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

Parameters
  • cube (iris.cube.Cube) – Input cube

  • attributes_dict (dict) – 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.

improver.metadata.amend.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 (iris.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.

improver.metadata.amend.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 (iris.cube.Cube) – Cube to modify attributes in (modified in place)

Returns

None