improver.standardise module

Plugin to standardise metadata

class StandardiseMetadata[source]

Bases: BasePlugin

Plugin to standardise cube metadata

_abc_impl = <_abc_data object>
static _collapse_scalar_dimensions(cube)[source]

Demote any scalar dimensions (excluding “realization”) on the input cube to auxiliary coordinates.

Parameters:

cube (Cube) – The cube

Return type:

Cube

Returns:

The collapsed cube

static _discard_redundant_cell_methods(cube)[source]

Removes cell method “point”: “time” from cube if present.

Return type:

None

static _modify_scalar_coord_value(cube, coord_modification)[source]

Modifies the value of each specified scalar coord (dictionary key) to the provided value (dictionary value). Note that data types are not enforced here as the subsequent enforcement step will fulfil this requirement. Units are assumed to be the same as the original coordinate value. Modifying multi-valued coordinates or time coordinates is specifically prevented as there is greater scope to harm data integrity (i.e. the description of the data and the data becoming misaligned).

If the coordinate does not exist the modification request is silently skipped.

Parameters:
  • cube (Cube) – Cube to be updated in place

  • coord_modification (Dict[str, float]) – Dictionary defining the coordinates (keys) to be modified and the values (values) to which they should be set.

Return type:

None

static _remove_scalar_coords(cube, coords_to_remove)[source]

Removes named coordinates from the input cube.

Return type:

None

static _rm_air_temperature_status_flag(cube)[source]

Remove air_temperature status_flag coord by applying as NaN to cube data.

See https://github.com/metoppv/improver/pull/1839 for further details.

Return type:

Cube

static _standardise_dtypes_and_units(cube)[source]

Modify input cube in place to conform to mandatory dtype and unit standards.

Parameters:

cube (Cube) – Cube to be updated in place

Return type:

None

process(cube, new_name=None, new_units=None, coords_to_remove=None, coord_modification=None, attributes_dict=None)[source]

Perform compulsory and user-configurable metadata adjustments. The compulsory adjustments are:

  • to collapse any scalar dimensions apart from realization (which is expected always to be a dimension);

  • to cast the cube data and coordinates into suitable datatypes;

  • to convert time-related metadata into the required units

  • to remove cell method (“point”: “time”).

Parameters:
  • cube (Cube) – Input cube to be standardised

  • new_name (Optional[str]) – Optional rename for output cube

  • new_units (Optional[str]) – Optional unit conversion for output cube

  • coords_to_remove (Optional[List[str]]) – Optional list of scalar coordinates to remove from output cube

  • coord_modification (Optional[Dict[str, float]]) – Optional dictionary used to directly modify the values of scalar coordinates. To be used with extreme caution. For example this dictionary might take the form: {“height”: 1.5} to set the height coordinate to have a value of 1.5m (assuming original units of m). This can be used to align e.g. temperatures defined at slightly different heights where this difference is considered small enough to ignore. Type is inferred, so providing a value of 2 will result in an integer type, whilst a value of 2.0 will result in a float type.

  • attributes_dict (Optional[Dict[str, Any]]) – Optional dictionary of required attribute updates. Keys are attribute names, and values are the required changes. See improver.metadata.amend.amend_attributes for details.

Return type:

Cube

Returns:

The processed cube