improver.utilities.textural module

Module containing plugin to calculate whether or not the input field texture exceeds a given threshold.

class FieldTexture(nbhood_radius, textural_threshold, diagnostic_threshold, model_id_attr=None)[source]

Bases: BasePlugin

Plugin to calculate whether or not the input field texture exceeds a

given threshold.

  1. Takes a binary field that has been thresholded and looks for the transitions/edges in the field that mark out a transition.

  2. The transition calculation is then fed into the neighbourhooding code (_calculate_ratio) to calculate a ratio for each cell. This is the texture of the input field.

  3. The new cube of ratios is then thresholded and the realization coordinates are collapsed to generate a mean of the thresholded ratios. This gives a binary indication of whether a field is rough (texture values close to 1) or smooth (texture values close to zero).

__init__(nbhood_radius, textural_threshold, diagnostic_threshold, model_id_attr=None)[source]
Parameters:
  • nbhood_radius (float) – The neighbourhood radius in metres within which the number of potential transitions should be calculated. This forms the denominator in the calculation of the ratio of actual to potential transitions that indicates a field’s texture. A larger radius should be used for diagnosing larger-scale textural features.

  • textural_threshold (float) – A unit-less threshold value that defines the ratio value above which the field is considered rough and below which the field is considered smoother.

  • diagnostic_threshold (float) – A user defined threshold value related either to cloud or precipitation, used to extract the corresponding dimensional cube with assumed units of 1.

  • model_id_attr (Optional[str]) – Name of the attribute used to identify the source model for blending.

_abc_impl = <_abc_data object>
_calculate_ratio(cube, cube_name, radius)[source]

Calculates the ratio of actual to potential value transitions in a neighbourhood about each cell.

The process is as follows:

  1. For each grid cell find the number of cells of value 1 in a surrounding neighbourhood of a size defined by the arg radius. The potential transitions within that neighbourhood are defined as the number of orthogonal neighbours (up, down, left, right) about cells of value 1. This is 4 times the number of cells of value 1.

  2. Calculate the number of actual transitions within the neighbourhood, that is the number of cells of value 0 that orthogonally abut cells of value 1.

  3. Calculate the ratio of actual to potential transitions.

Ratios approaching 1 indicate that there are many transitions, so the field is highly textured (rough). Ratios close to 0 indicate a smoother field.

A neighbourhood full of cells of value 1 will return ratios of 0; the diagnostic that has been thresholded to produce the binary field is found everywhere within that neighbourhood, giving a smooth field. At the other extreme, in neighbourhoods in which there are no cells of value 1 the ratio is set to 1.

Parameters:
  • cube (Cube) – Input data in cube format containing a two-dimensional field of binary data.

  • cube_name (str) – Name of input data cube, used for determining output texture cube name.

  • radius (float) – Radius for neighbourhood in metres.

Return type:

Cube

Returns:

A ratio between 0 and 1 of actual transitions over potential transitions.

static _calculate_transitions(data)[source]

Identifies actual transitions present in a binary field. These transitions are defined as the number of cells of value zero that directly neighbour cells of value 1. The number of transitions is calculated for all cells of value 1 whilst avoiding double-counting transitions. The number of transitions for cells of value 0 is set to 0.

Parameters:

data (ndarray) – A NumPy array of the input cube for data manipulation.

Return type:

ndarray

Returns:

A NumPy array containing the transitions for ratio calculation.

process(input_cube)[source]

Calculates a field of texture to use in differentiating solid and more scattered features.

Parameters:

input_cube (Cube) – Input data in cube format containing the field for which the texture is to be assessed.

Return type:

Cube

Returns:

A cube containing either the mean across realization of the thresholded ratios to give the field texture, if a realization coordinate is present, or the thresholded ratios directly, if no realization coordinate is present.