improver.calibration package

Submodules

Module contents

init for calibration that contains functionality to split forecast, truth and coefficient inputs.

add_warning_comment(forecast)[source]

Add a comment to warn that calibration has not been applied.

Parameters:

forecast (Cube) – The forecast to which a comment will be added.

Return type:

Cube

Returns:

Forecast with an additional comment.

split_forecasts_and_coeffs(cubes, land_sea_mask_name=None)[source]

Split the input forecast, coefficients, static additional predictors, land sea-mask and probability template, if provided. The coefficients cubes and land-sea mask are identified based on their name. The static additional predictors are identified as not have a time coordinate. The current forecast and probability template are then split.

Parameters:
  • cubes (CubeList) – A list of input cubes which will be split into relevant groups. This includes the forecast, coefficients, static additional predictors, land-sea mask and probability template.

  • land_sea_mask_name (Optional[str]) – Name of the land-sea mask cube to help identification.

Returns:

  • A cube containing the current forecast.

  • If found, a cubelist containing the coefficients else None.

  • If found, a cubelist containing the static additional predictor else None.

  • If found, a land-sea mask will be returned, else None.

  • If found, a probability template will be returned, else None.

Raises:
  • ValueError – If multiple items provided, when only one is expected.

  • ValueError – If no forecast is found.

split_forecasts_and_truth(cubes, truth_attribute)[source]

A common utility for splitting the various inputs cubes required for calibration CLIs. These are generally the forecast cubes, historic truths, and in some instances a land-sea mask is also required.

Parameters:
  • cubes (List[Cube]) – A list of input cubes which will be split into relevant groups. These include the historical forecasts, in the format supported by the calibration CLIs, and the truth cubes.

  • truth_attribute (str) – An attribute and its value in the format of “attribute=value”, which must be present on truth cubes.

Return type:

Tuple[Cube, Cube, Optional[Cube]]

Returns:

  • A cube containing all the historic forecasts.

  • A cube containing all the truth data.

  • If found within the input cubes list a land-sea mask will be returned, else None is returned.

Raises:
  • ValueError – An unexpected number of distinct cube names were passed in.

  • IOError – More than one cube was identified as a land-sea mask.

  • IOError – Missing truth or historical forecast in input cubes.

validity_time_check(forecast, validity_times)[source]

Check the validity time of the forecast matches the accepted validity times within the validity times list.

Parameters:
  • forecast (Cube) – Cube containing the forecast to be calibrated.

  • validity_times (List[str]) – Times at which the forecast must be valid. This must be provided as a four digit string (HHMM) where the first two digits represent the hour and the last two digits represent the minutes e.g. 0300 or 0315. If the forecast provided is at a different validity time then no coefficients will be applied.

Return type:

bool

Returns:

If the validity time within the cube matches a validity time within the validity time list, then True is returned. Otherwise, False is returned.