improver.utilities.copy_metadata module#

class CopyMetadata(attributes=[], aux_coord=[])[source]#

Bases: BasePlugin

Copy attribute or auxilary coordinate values from template_cube to cube, overwriting any existing values.

__init__(attributes=[], aux_coord=[])[source]#

Initialise the plugin with a list of attributes to copy.

Parameters:
  • attributes (List) – List of names of attributes to copy. If any are not present on template_cube, a KeyError will be raised.

  • aux_coord (List) – List of names of auxilary coordinates to copy. If any are not present on template_cube, a KeyError will be raised. If the aux_coord is already present in the cube, it will be overwritten.

_abc_impl = <_abc._abc_data object>#
find_common_attributes(cubes, attributes)[source]#

Find the common attribute values between the cubes. If the attribute is history, the most recent value will be returned.

Parameters:
  • cubes (CubeList) – A list of template cubes to extract common attributes from.

  • attributes (List) – A list of attributes to be copied.

Return type:

dict

Returns:

A dictionary of common attributes.

Raises:
  • ValueError – If the attribute is not found in any of the template cubes

  • ValueError – If the attribute has different values in the provided template cubes.

static get_most_recent_history(datelist)[source]#

Gets the most recent history attribute from the list of provided dates.

Parameters:

datelist (list) – A list of dates to find the most recent calue from.

Return type:

list

Returns:

The most recent history attribute.

process(*cubes)[source]#

Copy attribute or auxilary coordinate values from template_cube to cube, overwriting any existing values. If the history attribute is present in the list of requested attributes, the most recent value will be used. If an auxilary coordinate needs to be copied then all template cubes must have the auxilary coordinate present.

Operation is performed in-place on provided inputs.

Parameters:

cubes (Union[Cube, CubeList]) – List of cubes. First cube provided represents the cube to be updated. All other cubes are treated as template cubes.

Return type:

Cube

Returns:

A cube with attributes copied from the template cubes