improver.metadata.amend module

Module containing utilities for modifying cube metadata

_update_cell_methods(cell_methods, original_name, new_diagnostic_name)[source]

Update any cell methods that include a comment that refers to the diagnostic name to refer instead to the new diagnostic name. Those cell methods that do not include the diagnostic name are passed through unmodified.

Parameters:
  • cell_methods (Tuple[CellMethod]) – The cell methods found on the cube that is being used as the metadata template.

  • original_name (str) – The full name of the metadata template cube.

  • new_diagnostic_name (str) – The new diagnostic name to use in the modified cell methods.

Return type:

List[CellMethod]

Returns:

A list of modified cell methods to replace the originals.

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. If the new value contains “{}”, the existing value will be inserted at this point (no existing value will result in the “{}” being removed, then applied as the attribute value). If the new value contains “{now:.*}”, where the .* is a valid date format, then this string is replaced with the current wall-clock time, formatted as specified.

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_diagnostic_name(source_cube, new_diagnostic_name, result)[source]

Used for renaming the threshold coordinate and modifying cell methods where necessary; excludes the in_vicinity component.

Parameters:
  • source_cube (Cube) – An original cube before any processing took place. Can be the same cube as result.

  • new_diagnostic_name (str) – The new diagnostic name to apply to result.

  • result (Cube) – The cube that needs to be modified in place.

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