improver.utilities.pad_spatial module¶
Utilities for spatial padding of iris cubes.
-
improver.utilities.pad_spatial._create_cube_with_padded_data(source_cube, data, coord_x, coord_y)[source]¶ Create a cube with newly created data where the metadata is copied from the input cube and the supplied x and y coordinates are added to the cube.
- Parameters
source_cube (iris.cube.Cube) – Template cube used for copying metadata and non x and y axes coordinates.
data (numpy.ndarray) – Data to be put into the new cube.
coord_x (iris.coords.DimCoord) – Coordinate to be added to the new cube to represent the x axis.
coord_y (iris.coords.DimCoord) – Coordinate to be added to the new cube to represent the y axis.
- Returns
Cube built from the template cube using the requested data and the supplied x and y axis coordinates.
- Return type
-
improver.utilities.pad_spatial.create_cube_with_halo(cube, halo_radius)[source]¶ Create a template cube defining a new grid by adding a fixed width halo on all sides to the input cube grid. The cube contains no meaningful data.
- Parameters
cube (iris.cube.Cube) – Cube on original grid
halo_radius (float) – Size of border to pad original grid, in metres
- Returns
New cube defining the halo-padded grid (data set to zero)
- Return type
-
improver.utilities.pad_spatial.pad_coord(coord, width, method)[source]¶ Construct a new coordinate by extending the current coordinate by the padding width.
- Parameters
coord (iris.coords.Coord) – Original coordinate which will be used as the basis of the new extended coordinate.
width (int) – The width of padding in grid cells (the extent of the neighbourhood radius in grid cells in a given direction).
method (str) – A string determining whether the coordinate is being expanded or contracted. Options: ‘remove’ to remove points from coord; ‘add’ to add points to coord.
- Returns
Coordinate with expanded or contracted length, to be added to the padded or unpadded iris cube.
- Return type
- Raises
ValueError – Raise an error if non-uniform increments exist between grid points.
-
improver.utilities.pad_spatial.pad_cube_with_halo(cube, width_x, width_y, halo_mean_data=True)[source]¶ Method to pad a halo around the data in an iris cube. If halo_with_data is False, the halo is filled with zeros. Otherwise the padding calculates a mean within half the padding width with which to fill the halo region.
- Parameters
cube (iris.cube.Cube) – The original cube prior to applying padding. The cube should contain only x and y dimensions, so will generally be a slice of a cube.
width_x (int) – The width in x directions of the neighbourhood radius in grid cells. This will be the width of padding to be added to the numpy array.
width_y (int) – The width in y directions of the neighbourhood radius in grid cells. This will be the width of padding to be added to the numpy array.
halo_mean_data (bool) – Flag whether to populate the halo region with 0.0 or to fill with mean values derived from the existing data matrix. By default the mean data is used.
- Returns
Cube containing the new padded cube, with appropriate changes to the cube’s dimension coordinates.
- Return type
-
improver.utilities.pad_spatial.remove_cube_halo(cube, halo_radius)[source]¶ Remove halo of halo_radius from a cube.
This function converts the halo radius into the number of grid points in the x and y coordinate that need to be removed. It then calls remove_halo_from_cube which only acts on a cube with x and y coordinates so we need to slice the cube and them merge the cube back together ensuring the resulting cube has the same dimension coordinates.
- Parameters
cube (iris.cube.Cube) – Cube on extended grid
halo_radius (float) – Size of border to remove, in metres
- Returns
New cube with the halo removed.
- Return type
-
improver.utilities.pad_spatial.remove_halo_from_cube(cube, width_x, width_y)[source]¶ Method to remove rows/columns from the edge of an iris cube. Used to ‘unpad’ cubes which have been previously padded by pad_cube_with_halo.
- Parameters
cube (iris.cube.Cube) – The original cube to be trimmed of edge data. The cube should contain only x and y dimensions, so will generally be a slice of a cube.
width_x (int) – The width in x directions of the neighbourhood radius in grid cells. This will be the width of padding to be added to the numpy array.
width_y (int) – The width in y directions of the neighbourhood radius in grid cells. This will be the width of padding to be added to the numpy array.
- Returns
Cube containing the new trimmed cube, with appropriate changes to the cube’s dimension coordinates.
- Return type