improver.nowcasting.utilities module

Module with utilities required for nowcasting.

class ApplyOrographicEnhancement(operation)[source]

Bases: BasePlugin

Apply orographic enhancement to precipitation rate input, either to add or subtract an orographic enhancement component.

__init__(operation)[source]

Initialise class.

Parameters:

operation (str) – Operation (“add” or “subtract”) to apply to the incoming cubes.

Raises:

ValueError – Operation not supported.

_abc_impl = <_abc_data object>
_apply_minimum_precip_rate(precip_cube, cube)[source]

Ensure that negative precipitation rates are capped at the defined minimum precipitation rate.

Parameters:
  • precip_cube (Cube) – Cube containing a precipitation rate input field.

  • cube (Cube) – Cube containing the precipitation rate field after combining with orographic enhancement.

Return type:

Cube

Returns:

Cube containing the precipitation rate field where any negative precipitation rates have been capped at the defined minimum precipitation rate.

_apply_orographic_enhancement(precip_cube, oe_cube)[source]

Combine the precipitation rate cube and the orographic enhancement cube.

Parameters:
  • precip_cube (Cube) – Cube containing the input precipitation field.

  • oe_cube (Cube) – Cube containing the orographic enhancement field matching the validity time of the precipitation cube.

Return type:

Cube

Returns:

Cube containing the precipitation rate field modified by the orographic enhancement cube.

static _select_orographic_enhancement_cube(precip_cube, oe_cube, allowed_time_diff=1800)[source]

Select the orographic enhancement cube with the required time coordinate.

Parameters:
  • precip_cube (Cube) – Cube containing the input precipitation fields.

  • oe_cube (Cube) – Cube containing orographic enhancement fields at one or more times.

  • allowed_time_diff (int) – The maximum permitted difference, in integer seconds, between the datetime of the precipitation cube and the time points available within the orographic enhancement cube. If this limit is exceeded, then an error is raised.

Return type:

Cube

Returns:

Cube containing the orographic enhancement field at the required time.

Raises:

ValueError – If required time step is not available within tolerance (in theory. In practise, the tolerance is left as the default None, which matches ANY available field regardless of time offset. So this error will never be thrown.)

process(precip_cubes, orographic_enhancement_cube)[source]

Apply orographic enhancement by modifying the input fields. This can include either adding or deleting the orographic enhancement component from the input precipitation fields.

Parameters:
  • precip_cubes (Union[Cube, List[Cube]]) – Cube or iterable (list, CubeList or tuple) of cubes containing the input precipitation fields.

  • orographic_enhancement_cube (Cube) – Cube containing the orographic enhancement fields.

Return type:

CubeList

Returns:

CubeList of precipitation rate cubes that have been updated using orographic enhancement.

class ExtendRadarMask[source]

Bases: BasePlugin

Extend the mask on radar rainrate data based on the radar coverage composite

__init__()[source]

Initialise with known values of the coverage composite for which radar data is valid. All other areas will be masked.

_abc_impl = <_abc_data object>
process(radar_data, coverage)[source]

Update the mask on the input rainrate cube to reflect where coverage is valid

Parameters:
  • radar_data (Cube) – Radar data with mask corresponding to radar domains

  • coverage (Cube) –

    Radar coverage data containing values:

    0: outside composite 1: precip detected 2: precip not detected & 1/32 mm/h detectable at this range 3: precip not detected & 1/32 mm/h NOT detectable

Return type:

Cube

Returns:

Radar data with mask extended to mask out regions where 1/32 mm/h are not detectable

class FillRadarHoles[source]

Bases: BasePlugin

Fill in small “no data” regions in the radar composite by interpolating in log rainrate space.

The log-linear transformation does not preserve non-zero rainrates of less than 0.001 mm/h. Since the radar composite encodes trace rain rates with a value of 0.03 mm/h, this should not have any effect on “real” data from the Met Office.

MIN_RR_MMH = 0.001
__init__()[source]

Initialise parameters of interpolation

The constants defining neighbourhood size and proportion of neighbouring masked pixels for speckle identification have been empirically tuned for UK radar data. As configured, this method will flag “holes” of up to 24 pixels in size (30% of a 9 x 9 neighbourhood).

The radius used to interpolate data into these holes has been chosen to match these constants, by defining the smallest radius that ensures there will always be valid data in the neighbourhood (25 pixels) over which averaging is performed.

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

Identify and interpolate “speckle” points, where “speckle” is defined as areas of “no data” that are small enough to fill by interpolation without affecting data integrity. We would not wish to interpolate large areas as this may give false confidence in “no precipitation”, where in fact precipitation exists in a “no data” region.

Masked pixels near the borders of the input data array are not considered for interpolation.

Parameters:

cube (Cube) – Cube containing rainrates (mm/h). Data modified in place.

Return type:

None

process(masked_radar)[source]

Fills in and unmasks small “no data” regions within the radar composite, to minimise gaps in the extrapolation nowcast.

Parameters:

masked_radar (Cube) – A masked cube of radar precipitation rates

Return type:

Cube

Returns:

A masked cube with continuous coverage over the radar composite domain, where missing data has been interpolated