improver.generate_ancillaries.generate_ancillary module

Module containing ancillary generation utilities for Improver

class CorrectLandSeaMask[source]

Bases: BasePlugin

Round landsea mask to binary values

Corrects interpolated land sea masks to boolean values of False [sea] and True [land].

_abc_impl = <_abc_data object>
static process(standard_landmask)[source]
Read in the interpolated landmask and round values < 0.5 to False

and values >=0.5 to True.

Parameters:

standard_landmask (Cube) – input landmask on standard grid.

Return type:

Cube

Returns:

output landmask of boolean values.

class GenerateOrographyBandAncils[source]

Bases: BasePlugin

Generate topographic band ancillaries for the standard grids.

Reads orography files, then generates binary mask of land points within the orography band specified.

_abc_impl = <_abc_data object>
gen_orography_masks(standard_orography, standard_landmask, thresholds, units='m')[source]

Function to generate topographical band masks.

For each threshold defined in ‘thresholds’, a cube with 0 over sea points and 1 for land points within the topography band will be generated. The lower threshold is exclusive to the band whilst the upper threshold is inclusive i.e: lower_threshold < band <= upper_threshold

For example, for threshold pair [1,3] with orography:

[[0 0 2]    and      sea mask: [[0 0 1]
 [2 2 3]                        [1 1 1]
 [0 1 4]]                       [0 1 1]]

the resultant array will be:

[[0 0 1]
 [0 1 1]
 [0 0 0]]
Parameters:
  • standard_orography (Cube) – The standard orography.

  • standard_landmask (Optional[Cube]) – The landmask generated by gen_landmask.

  • thresholds (List[float]) – Upper and/or lower thresholds of the current topographical band.

  • units (str) – Units to be fed to CF_units to create a unit for the cube. The unit must be convertable to meters. If no unit is given this will default to meters.

Return type:

Cube

Returns:

Cube containing topographical band mask.

Raises:

KeyError – if the key does not match any in THRESHOLD_DICT.

process(orography, thresholds_dict, landmask=None)[source]
Loops over the supplied orographic bands, adding a cube

for each band to the mask cubelist.

Parameters:
  • orography (Cube) – orography on standard grid.

  • thresholds_dict (Dict[str, Any]) –

    Definition of orography bands required. Has key-value pairs of “bounds”: list of list of pairs of bounds for each band and “units”:”string containing units of bounds”, for example:

    {'bounds':[[0,100], [100,200]], 'units': "m"}
    

  • landmask (Optional[Cube]) – land mask on standard grid, with land points set to one and sea points set to zero. If provided sea points are set to zero in every band.

Return type:

CubeList

Returns:

list of orographic band mask cubes.

static sea_mask(landmask, orog_band, sea_fill_value=None)[source]

Function to mask sea points and substitute the default numpy fill value behind this mask_cube.

Parameters:
  • landmask (ndarray) – The landmask generated by gen_landmask.

  • orog_band (ndarray) – The binary array to which the landmask will be applied.

  • sea_fill_value (Optional[int]) – A fill value to set sea points to and leave the output unmasked, rather than the default behaviour of returning a masked array with a default fill value.

Return type:

Union[MaskedArray, ndarray]

Returns:

An array where the sea points have been masked out and filled with a default fill value, or just filled with the given sea_fill_value and not masked.

_make_mask_cube(mask_data, coords, topographic_bounds, topographic_units, sea_points_included=False)[source]

Makes cube from numpy masked array generated from orography fields.

Parameters:
  • mask_data (MaskedArray) – The numpy array to make a cube from.

  • coords (List) – Dictionary of coordinate on the model ancillary file.

  • topographic_bounds (List[float]) – List containing the lower and upper thresholds defining the mask

  • topographic_units (str) – Name of the units of the topographic zone coordinate of the output cube.

  • sea_points_included (bool) – Default is False. Value for the output cube attribute ‘topographic_zones_include_seapoints’, signifying whether sea points have been included when the ancillary is generated.

Return type:

Cube

Returns:

Cube containing the mask_data array, with appropriate coordinate and attribute information.