improver.spotdata.spot_extraction module

Spot data extraction from diagnostic fields using neighbour cubes.

class improver.spotdata.spot_extraction.SpotExtraction(neighbour_selection_method='nearest')[source]

Bases: improver.BasePlugin

For the extraction of diagnostic data using neighbour cubes that contain spot-site information and the appropriate grid point from which to source data.

__init__(neighbour_selection_method='nearest')[source]
Parameters

neighbour_selection_method (str) – The neighbour cube may contain one or several sets of grid coordinates that match a spot site. These are determined by the neighbour finding method employed. This keyword is used to extract the desired set of coordinates from the neighbour cube.

_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 213
_abc_registry = <_weakrefset.WeakSet object>
static build_diagnostic_cube(neighbour_cube, diagnostic_cube, spot_values)[source]

Builds a spot data cube containing the extracted diagnostic values.

Parameters
  • neighbour_cube (iris.cube.Cube) – This cube is needed as a source for information about the spot sites which needs to be included in the spot diagnostic cube.

  • diagnostic_cube (iris.cube.Cube) – The cube is needed to provide the name and units of the diagnostic that is being processed.

  • spot_values (numpy.ndarray) – An array containing the diagnostic values extracted for the required spot sites.

Returns

A spot data cube containing the extracted diagnostic data.

Return type

iris.cube.Cube

extract_coordinates(neighbour_cube)[source]

Extract the desired set of grid coordinates that correspond to spot sites from the neighbour cube.

Parameters

neighbour_cube (iris.cube.Cube) – A cube containing information about the spot data sites and their grid point neighbours.

Returns

A cube containing only the x and y grid coordinates for the grid point neighbours given the chosen neighbour selection method. The neighbour cube contains the indices stored as floating point values, so they are converted to integers in this cube.

Return type

iris.cube.Cube

Raises
  • ValueError if the neighbour_selection_method expected is not found

  • in the neighbour cube.

static extract_diagnostic_data(coordinate_cube, diagnostic_cube)[source]

Extracts diagnostic data from the desired grid points in the diagnostic cube. The neighbour finding routine that produces the coordinate cube works in x-y order. As such, the diagnostic cube is changed to match before the indices are used to extract data.

Parameters
  • coordinate_cube (iris.cube.Cube) – A cube containing the x and y grid coordinates for the grid point neighbours.

  • diagnostic_cube (iris.cube.Cube) – A cube of diagnostic data from which spot data is being taken.

Returns

An array of diagnostic values at the grid coordinates found within the coordinate cube.

Return type

numpy.ndarray

process(neighbour_cube, diagnostic_cube, new_title=None)[source]

Create a spot data cube containing diagnostic data extracted at the coordinates provided by the neighbour cube.

Examples

The neighbour_cube required for use in this method is constructed using the NeighbourSelection() class. Such a cube will contain grid point neighbours to spot sites found by one or more neighbour_selection_methods. The vertical displacement between the spot data site and the grid point neighbour is the third attribute shown in the cube below. The spot site information is also contained within the cube, stored within auxiliary coordinates. An example of such a cube is shown here, where in this case grid point neighbours are provided for 4 different methods of choosing them:

grid_neighbours / (1)               (spot_index: 121; neighbour_selection_method: 4; grid_attributes: 3)
     Dimension coordinates:
          spot_index                           x                                -                   -
          neighbour_selection_method           -                                x                   -
          grid_attributes                      -                                -                   x
     Auxiliary coordinates:
          altitude                             x                                -                   -
          latitude                             x                                -                   -
          longitude                            x                                -                   -
          wmo_id                               x                                -                   -
          neighbour_selection_method_name      -                                x                   -
          grid_attributes_key                  -                                -                   x
     Attributes:
          Conventions: CF-1.5
          mosg__grid_domain: uk_extended
          mosg__grid_type: standard
          mosg__grid_version: 1.2.0
          mosg__model_configuration: uk_det

The diagnostic cube will be a standard IMPROVER diagnostic cube, where there may be dimensions leading the x and y spatial coordinates. These will be maintained in the output cube. So for an input diagnostic cube such as:

air_temperature / (K)               (realization: 12; projection_y_coordinate: 970; projection_x_coordinate: 1042)
     Dimension coordinates:
          realization                           x                            -                             -
          projection_y_coordinate               -                            x                             -
          projection_x_coordinate               -                            -                             x
     Scalar coordinates:
          forecast_period: 0 seconds
          forecast_reference_time: 2018-07-23 09:00:00
          height: 1.5 m
          time: 2018-07-23 09:00:00
     Attributes:
          Conventions: CF-1.5
          history: 2018-07-23T12:57:06Z: StaGE Decoupler
          institution: Met Office
          mosg__grid_domain: uk_extended
          mosg__grid_type: standard
          mosg__grid_version: 1.2.0
          mosg__model_configuration: uk_ens
          source: Met Office Unified Model
          title: MOGREPS-UK Model Forecast on UK 2 km Standard Grid
          um_version: 10.8

The resulting output cube will have the following form, in which the spatial coordinates have been removed and in there place is the information about the spot data sites. Note that the data provenance metadata is also copied forward onto the output cube:

air_temperature / (K)               (realization: 12; spot_index: 121)
     Dimension coordinates:
          realization                           x               -
          spot_index                            -               x
     Auxiliary coordinates:
          altitude                              -               x
          latitude                              -               x
          longitude                             -               x
          wmo_id                                -               x
     Scalar coordinates:
          forecast_period: 0 seconds
          forecast_reference_time: 2018-07-23 09:00:00
          height: 1.5 m
          time: 2018-07-23 09:00:00
     Attributes:
          Conventions: CF-1.5
          history: 2018-07-23T12:57:06Z: StaGE Decoupler
          institution: Met Office
          mosg__grid_domain: uk_extended
          mosg__grid_type: standard
          mosg__grid_version: 1.2.0
          mosg__model_configuration: uk_ens
          source: Met Office Unified Model
          title: MOGREPS-UK Model Forecast on UK 2 km Standard Grid
          um_version: 10.8
Parameters
  • neighbour_cube (iris.cube.Cube) – A cube containing information about the spot data sites and their grid point neighbours.

  • diagnostic_cube (iris.cube.Cube) – A cube of diagnostic data from which spot data is being taken.

  • new_title (str or None) – New title for spot-extracted data. If None, this attribute is reset to a default value, since it has no prescribed standard and may therefore contain grid information that is no longer correct after spot-extraction.

Returns

A cube containing diagnostic data for each spot site, as well as information about the sites themselves.

Return type

iris.cube.Cube

improver.spotdata.spot_extraction.check_grid_match(cubes)[source]

Checks that cubes are on, or originate from, compatible coordinate grids. Each cube is first checked for an existing ‘model_grid_hash’ which can be used to encode coordinate information on cubes that do not themselves contain a coordinate grid (e.g. spotdata cubes). If this is not found a new hash is generated to enable comparison. If the cubes are not compatible, an exception is raised to prevent the use of unmatched cubes.

Parameters

cubes (list of iris.cube.Cube) – A list of cubes to check for grid compatibility.

Raises

ValueError – Raised if the cubes are not on matching grids as identified by the model_grid_hash.