improver.spotdata.spot_extraction module

Spot data extraction from diagnostic fields using neighbour cubes.

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

Bases: object

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', grid_metadata_identifier='mosg')[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.
  • grid_metadata_identifier (str or None) – A string to search for in the input cube attributes that can be used to ensure that the neighbour cube being used has been created for the model/grid of the diagnostic cube. If set to None, no such check is made and the cubes are assumed to be suitable for use with one another.
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 (np.array) – An array containing the diagnostic values extracted for the required spot sites.
Returns:

A spot data cube containing the extracted diagnostic data.

Return type:

neighbour_cube (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:

coordinate_cube (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:

spot_values (np.array)

process(neighbour_cube, diagnostic_cube)[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.
Returns:

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

Return type:

spotdata_cube (iris.cube.Cube)

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

Uses the provided grid_metadata_identifier to extract and compare attributes on the input cubes. The expectation is that all the metadata identified should match for the cubes to be deemed compatible.

Parameters:
  • grid_metadata_identifier (str or None) – A partial or complete attribute name. Attributes matching this are compared between the two cubes. If set to None, no such check is made and the cubes are assumed to be suitable for use with one another.
  • cubes (list of iris.cube.Cube items) – List of cubes for which the attributes should be tested.
Raises:

ValueError – Raised if the metadata extracted is not identical on all cubes.