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:
- 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 cubeattributes_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:
- get_unique_attributes(cubes, attribute, separator=' ')[source]#
Return a dictionary with the unique values of the specified attribute from within the input cubes. The specified attribute is expected on all cubes.
- Parameters:
cubes (
Union[List[Cube],CubeList]) – List of input cubes that should have the specified attribute.attribute (
str) – Name of attribute expected on the input cubes. This attribute is expected on the cubes as a string, with values within the attribute separated by the specified separator character.separator (
str) – The character on which to split the attribute values. Default is a space.
- Return type:
- Returns:
Dictionary containing an attribute key, if available.
- Raises:
AttributeError – Expected to find the attribute on all cubes.
- 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”.