improver.spotdata.spot_extraction module

Spot data extraction from diagnostic fields using neighbour cubes.

class SpotExtraction(neighbour_selection_method='nearest')[source]

Bases: 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_impl = <_abc_data object>
static build_diagnostic_cube(neighbour_cube, diagnostic_cube, spot_values, additional_dims=[], scalar_coords=None, auxiliary_coords=None, unique_site_id=None, unique_site_id_key=None)[source]

Builds a spot data cube containing the extracted diagnostic values.

Parameters:
  • neighbour_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 (Cube) – The cube is needed to provide the name and units of the diagnostic that is being processed.

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

  • additional_dims (Optional[List[DimCoord]]) – Optional list containing iris.coord.DimCoords with any leading dimensions required before spot data.

  • scalar_coords (Optional[List[AuxCoord]]) – Optional list containing iris.coord.AuxCoords with all scalar coordinates relevant for the spot sites.

  • auxiliary_coords (Optional[List[AuxCoord]]) – Optional list containing iris.coords.AuxCoords which are non-scalar.

  • unique_site_id (Union[List[str], ndarray, None]) – Optional list of 8-digit unique site identifiers.

  • unique_site_id_key (Optional[str]) – String to name the unique_site_id coordinate. Required if unique_site_id is in use.

Return type:

Cube

Returns:

A spot data cube containing the extracted diagnostic data.

static check_for_unique_id(neighbour_cube)[source]

Determine if there is a unique ID coordinate, and if so return the values and name of that coordinate.

Parameters:

neighbour_cube (Cube) – This cube on which to look for a unique site ID coordinate.

Return type:

Optional[Tuple[ndarray, str]]

Returns:

  • array of unique site IDs

  • name of unique site ID coordinate

extract_coordinates(neighbour_cube)[source]

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

Parameters:

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

Return type:

Cube

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.

Raises:
  • ValueError if the neighbour_selection_method expected is not found

  • in the neighbour cube.

get_aux_coords(diagnostic_cube, x_indices, y_indices)[source]

Extract scalar and non-scalar auxiliary coordinates from the diagnostic cube. Multi-dimensional auxiliary coordinates have the relevant points and bounds extracted for each site and a 1-dimensional coordinate is constructed that can be associated with the spot-index coordinate.

Parameters:
  • diagnostic_cube (Cube) – The cube from which auxiliary coordinates will be taken.

  • x_indices (ndarray) – The array indices that correspond to sites for which coordinate data is to be extracted.

  • y_indices (ndarray) – The array indices that correspond to sites for which coordinate data is to be extracted.

Return type:

Tuple[List[AuxCoord], List[AuxCoord]]

Returns:

  • list of scalar coordinates

  • list of non-scalar, multi-dimensional coordinates reshaped into 1-dimensional coordinates.

static get_coordinate_data(diagnostic_cube, x_indices, y_indices, coordinate)[source]

Extracts coordinate points from 2-dimensional coordinates for association with sites.

diagnostic_cube:

The cube from which auxiliary coordinates will be taken.

x_indices, y_indices:

The array indices that correspond to sites for which coordinate data is to be extracted.

coordinate:

The name of the coordinate from which to extract data.

Return type:

Union[ndarray, List[Optional[ndarray]]]

Returns:

A list containing an array of coordinate and bound values, with the later instead being None if no bounds exist.

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 (Cube) – A cube containing information about the spot data sites and their grid point neighbours.

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

  • new_title (Optional[str]) – 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.

Return type:

Cube

Returns:

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

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 (Union[List[Cube], CubeList]) – 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.

Return type:

None