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:
- 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”.
- 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.
- 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:
- Return type:
- Returns:
Dictionary containing a model_id_attr key, if available.
- Raises:
AttributeError – Expected to find the model_id_attr attribute on all cubes.