improver.utilities.interpolation module

Module to contain interpolation functions.

class InterpolateUsingDifference[source]

Bases: BasePlugin

Uses interpolation to fill masked regions in the data contained within the input cube. This is achieved by calculating the difference between the input cube and a complete (i.e. complete across the whole domain) reference cube. The difference between the data in regions where they overlap is calculated and this difference field is then interpolated across the domain. Any masked regions in the input cube data are then filled with data calculated as the reference cube data minus the interpolated difference field.

_abc_impl = <_abc_data object>
static _check_inputs(cube, reference_cube, limit)[source]

Check that the input cubes are compatible and the data is complete or masked as expected.

Return type:

None

process(cube, reference_cube, limit=None, limit_as_maximum=True)[source]

Apply plugin to input data.

Parameters:
  • cube (Cube) – Cube for which interpolation is required to fill masked regions.

  • reference_cube (Cube) – A cube that covers the entire domain that it shares with cube.

  • limit (Optional[Cube]) – A cube of limiting values to apply to the cube that is being filled in. This can be used to ensure that the resulting values do not fall below / exceed the limiting values; whether the limit values should be used as a minima or maxima is determined by the limit_as_maximum option. These values should be on an x-y grid of the same size as an x-y slice of cube.

  • limit_as_maximum (bool) – If True the test against the values allowed by the limit array is that if the interpolated values exceed the limit they should be set to the limit value. If False, the test is whether the interpolated values fall below the limit value.

Return type:

Cube

Returns:

A copy of the input cube in which the missing data has been populated with values obtained through interpolating the difference field and subtracting the result from the reference cube.

Raises:

ValueError – If the reference cube is not complete across the entire domain.

interpolate_missing_data(data, method='linear', limit=None, limit_as_maximum=True, valid_points=None)[source]
Parameters:
  • data (ndarray) – The field of data to be interpolated across gaps.

  • method (str) – The method to use to fill in the data. This is usually “linear” for linear interpolation, and “nearest” for a nearest neighbour approach. It can take any method available to the method scipy.interpolate.griddata.

  • limit (Optional[ndarray]) – The array containing limits for each grid point that are imposed on any value in the region that has been interpolated.

  • limit_as_maximum (bool) – If True the test against the limit array is that if the interpolated values exceed the limit they should be set to the limit value. If False, the test is whether the interpolated values fall below the limit value.

  • valid_points (Optional[ndarray]) – A boolean array that allows a subset of the unmasked data to be chosen as source data for the interpolation process. True values in this array mark points that can be used for interpolation if they are not otherwise invalid. False values mark points that should not be used, even if they are otherwise valid data points.

Return type:

ndarray

Returns:

The original data plus interpolated data in masked regions where it was possible to fill these in.