improver.nbhood.nbhood module

Module containing neighbourhood processing utilities.

class improver.nbhood.nbhood.BaseNeighbourhoodProcessing(neighbourhood_method, radii, lead_times=None)[source]

Bases: improver.BasePlugin

Apply a neighbourhood processing method to a thresholded cube. This is a base class for usage with a subclass that will inherit the functionality within this base class.

When applied to a thresholded probabilistic cube, it acts like a low-pass filter which reduces noisiness in the probabilities.

The neighbourhood methods will presently only work with projections in which the x grid point spacing and y grid point spacing are constant over the entire domain, such as the UK national grid projection

__init__(neighbourhood_method, radii, lead_times=None)[source]

Create a neighbourhood processing plugin that applies a smoothing to points in a cube.

Parameters
  • neighbourhood_method (Class object) – Instance of the class containing the method that will be used for the neighbourhood processing.

  • radii (float or list if defining lead times) – The radii in metres of the neighbourhood to apply. Rounded up to convert into integer number of grid points east and north, based on the characteristic spacing at the zero indices of the cube projection-x and y coords.

  • lead_times (list) – List of lead times or forecast periods, at which the radii within ‘radii’ are defined. The lead times are expected in hours.

_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 213
_abc_registry = <_weakrefset.WeakSet object>
_find_radii(cube_lead_times=None)[source]

Revise radius or radii for found lead times. If cube_lead_times is None, no automatic adjustment of the radii will take place. Otherwise it will interpolate to find the radius at each cube lead time as required.

Parameters

cube_lead_times (numpy.ndarray) – Array of forecast times found in cube.

Returns

Required neighbourhood sizes.

Return type

float or numpy.ndarray

process(cube, mask_cube=None)[source]

Supply neighbourhood processing method, in order to smooth the input cube.

Parameters
  • cube (iris.cube.Cube) – Cube to apply a neighbourhood processing method to, in order to generate a smoother field.

  • mask_cube (iris.cube.Cube) – Cube containing the array to be used as a mask.

Returns

Cube after applying a neighbourhood processing method, so that the resulting field is smoothed.

Return type

iris.cube.Cube

class improver.nbhood.nbhood.GeneratePercentilesFromANeighbourhood(neighbourhood_method, radii, lead_times=None, percentiles=(0, 5, 10, 20, 25, 30, 40, 50, 60, 70, 75, 80, 90, 95, 100))[source]

Bases: improver.nbhood.nbhood.BaseNeighbourhoodProcessing

Class for generating percentiles from a neighbourhood.

__init__(neighbourhood_method, radii, lead_times=None, percentiles=(0, 5, 10, 20, 25, 30, 40, 50, 60, 70, 75, 80, 90, 95, 100))[source]

Create a neighbourhood processing subclass that generates percentiles from a neighbourhood of points.

Parameters
  • neighbourhood_method (str) – Name of the neighbourhood method to use. Options: ‘circular’.

  • radii (float or list) – The radii in metres of the neighbourhood to apply. Rounded up to convert into integer number of grid points east and north, based on the characteristic spacing at the zero indices of the cube projection-x and y coords.

  • lead_times (list, optional) – List of lead times or forecast periods, at which the radii within ‘radii’ are defined. The lead times are expected in hours.

  • percentiles (list) – Percentile values at which to calculate; if not provided uses DEFAULT_PERCENTILES.

_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 213
_abc_registry = <_weakrefset.WeakSet object>
class improver.nbhood.nbhood.NeighbourhoodProcessing(neighbourhood_method, radii, lead_times=None, weighted_mode=True, sum_or_fraction='fraction', re_mask=False)[source]

Bases: improver.nbhood.nbhood.BaseNeighbourhoodProcessing

Class for applying neighbourhood processing to produce a smoothed field within the chosen neighbourhood.

__init__(neighbourhood_method, radii, lead_times=None, weighted_mode=True, sum_or_fraction='fraction', re_mask=False)[source]

Create a neighbourhood processing subclass that applies a smoothing to points in a cube.

Parameters
  • neighbourhood_method (str) – Name of the neighbourhood method to use. Options: ‘circular’, ‘square’.

  • radii (float or list) – The radii in metres of the neighbourhood to apply. Rounded up to convert into integer number of grid points east and north, based on the characteristic spacing at the zero indices of the cube projection-x and y coords.

  • lead_times (list) – List of lead times or forecast periods, at which the radii within ‘radii’ are defined. The lead times are expected in hours.

  • weighted_mode (bool) – If True, use a circle for neighbourhood kernel with weighting decreasing with radius. If False, use a circle with constant weighting.

  • sum_or_fraction (str) – Identifier for whether sum or fraction should be returned from neighbourhooding. The sum represents the sum of the neighbourhood. The fraction represents the sum of the neighbourhood divided by the neighbourhood area. “fraction” is the default. Valid options are “sum” or “fraction”.

  • re_mask (bool) – If re_mask is True, the original un-neighbourhood processed mask is applied to mask out the neighbourhood processed cube. If re_mask is False, the original un-neighbourhood processed mask is not applied. Therefore, the neighbourhood processing may result in values being present in areas that were originally masked.

_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 213
_abc_registry = <_weakrefset.WeakSet object>