improver.ensemble_calibration.utilities module

This module defines all the utilities used by the “plugins” specific for ensemble calibration.

improver.ensemble_calibration.utilities.check_predictor_of_mean_flag(predictor_of_mean_flag)[source]

Check the predictor_of_mean_flag at the start of the process methods in relevant ensemble calibration plugins, to avoid having to check and raise an error later.

Parameters

predictor_of_mean_flag (str) – String to specify the input to calculate the calibrated mean. Currently the ensemble mean (“mean”) and the ensemble realizations (“realizations”) are supported as the predictors.

Raises

ValueError – If the predictor_of_mean_flag is not valid.

improver.ensemble_calibration.utilities.convert_cube_data_to_2d(forecast, coord='realization', transpose=True)[source]

Function to convert data from a N-dimensional cube into a 2d numpy array. The result can be transposed, if required.

Parameters
  • forecast (iris.cube.Cube) – N-dimensional cube to be reshaped.

  • coord (str) – The data will be flattened along this coordinate.

  • transpose (bool) – If True, the resulting flattened data is transposed. This will transpose a 2d array of the format [:, coord] to [coord, :]. If False, the resulting flattened data is not transposed. This will result in a 2d array of format [:, coord].

Returns

Reshaped 2d array.

Return type

numpy.ndarray

improver.ensemble_calibration.utilities.flatten_ignoring_masked_data(data_array, preserve_leading_dimension=False)[source]

Flatten an array, selecting only valid data if the array is masked. There is also the option to reshape the resulting array so it has the same leading dimension as the input array, but the other dimensions of the array are flattened. It is assumed that each of the slices along the leading dimension are masked in the same way. This functionality is used in EstimateCoefficientsForEnsembleCalibration when realizations are used as predictors.

Parameters
  • data_array (numpy.ndarray or numpy.ma.MaskedArray) – An array or masked array to be flattened. If it is masked and the leading dimension is preserved the mask must be the same for every slice along the leading dimension.

  • preserve_leading_dimension (bool) – Default False. If True the flattened array is reshaped so it has the same leading dimension as the input array. If False the returned array is 1D.

Returns

A flattened array containing only valid data. Either 1D or, if preserving the leading dimension 2D. In the latter case the leading dimension is the same as the input data_array.

Return type

numpy.ndarray

Raises

ValueError – If preserving the leading dimension and the mask on the input array is not the same for every slice along the leading dimension.