improver.regrid.landsea module

Plugin to regrid with land-sea awareness

class AdjustLandSeaPoints(extrapolation_mode='nanmask', vicinity_radius=25000.0)[source]

Bases: PostProcessingPlugin

Replace data values at points where the nearest-regridding technique selects a source grid-point with an opposite land-sea-mask value to the target grid-point. The replacement data values are selected from a vicinity of points on the source-grid and the closest point of the correct mask is used. Where no match is found within the vicinity, the data value is not changed.

exception _NoMatchesError[source]

Bases: ValueError

Raise when there are no matches for the specified selector.

__init__(extrapolation_mode='nanmask', vicinity_radius=25000.0)[source]

Initialise class

Parameters:
  • extrapolation_mode (str) – Mode to use for extrapolating data into regions beyond the limits of the source_data domain. Available modes are documented in iris.analysis Defaults to “nanmask”.

  • vicinity_radius (float) – Distance in metres to search for a sea or land point.

_abc_impl = <_abc_data object>
_get_matches(selector_val)[source]
Return type:

Tuple[ndarray, ndarray, ndarray, ndarray]

correct_where_input_true(selector_val)[source]

Replace points in the output_cube where output_land matches the selector_val and the input_land does not match, but has matching points in the vicinity, with the nearest matching point in the vicinity in the original nearest_cube. Updates self.output_cube.data.

Parameters:

selector_val (int) – Value of mask to replace if needed. Intended to be 1 for filling land points near the coast and 0 for filling sea points near the coast.

Return type:

None

process(cube, input_land, output_land)[source]

Update cube.data so that output_land and sea points match an input_land or sea point respectively so long as one is present within the specified vicinity radius. Note that before calling this plugin the input land mask MUST be checked against the source grid, to ensure the grids match.

Parameters:
  • cube (Cube) – Cube of data to be updated (on same grid as output_land).

  • input_land (Cube) – Cube of land_binary_mask data on the grid from which “cube” has been reprojected (it is expected that the iris.analysis.Nearest method would have been used). Land points should be set to one and sea points set to zero. This is used to determine where the input model data is representing land and sea points.

  • output_land (Cube) – Cube of land_binary_mask data on target grid.

Return type:

Cube

Returns:

Cube of regridding results.

class RegridLandSea(regrid_mode='bilinear', extrapolation_mode='nanmask', landmask=None, landmask_vicinity=25000)[source]

Bases: PostProcessingPlugin

Nearest-neighbour and bilinear regridding with or without land-sea mask awareness. When land-sea mask considered, surface-type-mismatched source points are excluded from field regridding calculation for target points. For example, for regridding a field using nearest-neighbour approach with land-sea awareness, regridded land points always take values from a land point on the source grid, and vice versa for sea points.

REGRID_REQUIRES_LANDMASK = {'bilinear': False, 'bilinear-2': False, 'bilinear-with-mask-2': True, 'nearest': False, 'nearest-2': False, 'nearest-with-mask': True, 'nearest-with-mask-2': True}
__init__(regrid_mode='bilinear', extrapolation_mode='nanmask', landmask=None, landmask_vicinity=25000)[source]

Initialise regridding parameters.

Parameters:
  • regrid_mode (str) – Mode of interpolation in regridding. Valid options are “bilinear”, “nearest”, “nearest-with-mask”, “bilinear-2”,”nearest-2”, “nearest-with-mask-2” or “bilinear-with-mask-2”. “*-with-mask” option triggers adjustment of regridded points to match source points in terms of land / sea type.

  • extrapolation_mode (str) – Mode to fill regions outside the domain in regridding.

  • landmask (Optional[Cube]) – Land-sea mask (“land_binary_mask”) on the input cube grid, with land points set to one and sea points set to zero. Required for “nearest-with-mask” regridding option.

  • landmask_vicinity (float) – Radius of vicinity to search for a coastline, in metres.

_abc_impl = <_abc_data object>
_regrid_to_target(cube, target_grid, regridded_title, regrid_mode)[source]

Regrid cube to target_grid, inherit grid attributes and update title

Parameters:
  • cube (Cube) – Cube to be regridded

  • target_grid (Cube) – Data on the target grid. If regridding with mask, this cube should contain land-sea mask data to be used in adjusting land and sea points after regridding.

  • regridded_title (Optional[str]) – New value for the “title” attribute to be used after regridding. If not set, a default value is used.

  • regrid_mode (str) – “bilinear”,”nearest”,”nearest-with-mask”, “nearest-2”,”nearest-with-mask-2”,”bilinear-2”,”bilinear-with-mask-2”

Return type:

Cube

Returns:

Regridded cube with updated attributes.

process(cube, target_grid, regridded_title=None)[source]

Regrids cube onto spatial grid provided by target_grid.

Parameters:
  • cube (Cube) – Cube to be regridded.

  • target_grid (Cube) – Data on the target grid. If regridding with mask, this cube should contain land-sea mask data to be used in adjusting land and sea points after regridding.

  • regridded_title (Optional[str]) – New value for the “title” attribute to be used after regridding. If not set, a default value is used.

Return type:

Cube

Returns:

Regridded cube with updated attributes.

grid_contains_cutout(grid, cutout)[source]

Check that a spatial cutout is contained within a given grid

Parameters:
  • grid (Cube) – A cube defining a data grid.

  • cutout (Cube) – The cutout to search for within the grid.

Return type:

bool

Returns:

True if cutout is contained within grid, False otherwise.