improver.standardise module¶
Plugin to regrid cube data and standardise metadata
-
class
improver.standardise.AdjustLandSeaPoints(extrapolation_mode='nanmask', vicinity_radius=25000.0)[source]¶ Bases:
objectReplace 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.
-
__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.
-
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.
-
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 (iris.cube.Cube) – Cube of data to be updated (on same grid as output_land).
input_land (iris.cube.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). This is used to determine where the input model data is representing land and sea points.
output_land (iris.cube.Cube) – Cube of land_binary_mask data on target grid.
-
-
class
improver.standardise.StandardiseGridAndMetadata(regrid_mode='bilinear', extrapolation_mode='nanmask', landmask=None, landmask_vicinity=25000)[source]¶ Bases:
improver.BasePluginPlugin to regrid cube data and standardise metadata
-
REGRID_REQUIRES_LANDMASK= {'bilinear': False, 'nearest': False, 'nearest-with-mask': 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.
extrapolation_mode (str) – Mode to fill regions outside the domain in regridding.
landmask (iris.cube.Cube or None) – Land-sea mask (“land_binary_mask”) on the input cube grid. Required for “nearest-with-mask” regridding option.
landmask_vicinity (float) – Radius of vicinity to search for a coastline, in metres
- Raises
ValueError – If a landmask is required but not passed in
-
_abc_cache= <_weakrefset.WeakSet object>¶
-
_abc_negative_cache= <_weakrefset.WeakSet object>¶
-
_abc_negative_cache_version= 213¶
-
_abc_registry= <_weakrefset.WeakSet object>¶
-
_adjust_landsea(cube, target_grid)[source]¶ Adjust regridded data using differences between the target landmask and that obtained by regridding the source grid landmask, to ensure that the “land” or “sea” nature of the points in the regridded cube matches that of the target grid.
- Parameters
cube (iris.cube.Cube) – Cube after initial regridding
target_grid (iris.cube.Cube) – Cube containing landmask data on the target grid
- Returns
Adjusted cube
- Return type
-
static
_collapse_scalar_dimensions(cube)[source]¶ Demote any scalar dimensions (excluding “realization”) on the input cube to auxiliary coordinates.
- Returns
iris.cube.Cube
-
_regrid_to_target(cube, target_grid)[source]¶ Regrid cube to target_grid and inherit appropriate grid attributes
- Parameters
cube (iris.cube.Cube) – Cube to be regridded
target_grid (iris.cube.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.
- Returns
Regridded cube with updated attributes
- Return type
-
static
_remove_scalar_coords(cube, coords_to_remove)[source]¶ Removes named coordinates from the input cube.
-
static
_standardise_time_coordinates(cube)[source]¶ If cube time-type coordinates do not conform to expected standards, update units and datatypes in place.
-
process(cube, target_grid=None, new_name=None, new_units=None, coords_to_remove=None, attributes_dict=None, fix_float64=False)[source]¶ Perform regridding and metadata adjustments
- Parameters
cube (iris.cube.Cube) – Input cube to be standardised
target_grid (iris.cube.Cube or None) – Cube on the required grid. For “nearest-with-mask” regridding, this cube should contain a binary land-sea mask (“land_binary_mask”). If target_grid is None, no regridding is performed.
new_units (str or None) – Optional unit conversion for output cube
coords_to_remove (list of str or None) – Optional list of scalar coordinates to remove from output cube
attributes_dict (dict or None) – Optional dictionary of required attribute updates. Keys are attribute names, and values are the required value or “remove”.
fix_float64 (bool) – Flag to de-escalate float64 precision
- Returns
iris.cube.Cube
-
-
improver.standardise.grid_contains_cutout(grid, cutout)[source]¶ Check that a spatial cutout is contained within a given grid
- Parameters
grid (iris.cube.Cube) – A cube defining a data grid
cutout (iris.cube.Cube) – The cutout to search for within the grid
- Returns
True if cutout is contained within grid, False otherwise
- Return type