improver.generate_ancillaries.generate_ancillary module¶
Module containing ancillary generation utilities for Improver
-
class
improver.generate_ancillaries.generate_ancillary.CorrectLandSeaMask[source]¶ Bases:
objectRound landsea mask to binary values
Corrects interpolated land sea masks to boolean values of False [sea] and True [land].
-
class
improver.generate_ancillaries.generate_ancillary.GenerateOrographyBandAncils[source]¶ Bases:
objectGenerate topographic band ancillaries for the standard grids.
Reads orography files, then generates binary mask of land points within the orography band specified.
-
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 (iris.cube.Cube) – The standard orography.
- standard_landmask (iris.cube.Cube) – The landmask generated by gen_landmask.
- thresholds (list) – Upper and/or lower thresholds of the current topographical band.
Keyword Arguments: units (string) – 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.
Returns: Cube containing topographical band mask.
Return type: mask_cube (cube)
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 (iris.cube.Cube) – orography on standard grid.
- threshold_dict (dictionary) –
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"}
Keyword Arguments: landmask (iris.cube.Cube) – land mask on standard grid. If provided sea points are set to zero in every band.
Returns: list of orographic band mask cubes.
Return type: cubelist (iris.cube.CubeList)
-
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 (numpy array) – The landmask generated by gen_landmask.
- orog_band (numpy array) – The binary array to which the landmask will be applied.
Keyword Arguments: sea_fill_value (float) – 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.
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.
Return type: mask_data (numpy array)
-
-
improver.generate_ancillaries.generate_ancillary._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 (numpy masked array) – The numpy array to make a cube from.
- coords (dictionary) – Dictionary of coordinate on the model ancillary file.
- topographic_bounds (list) – List containing the lower and upper thresholds defining the mask
- topographic_units (string) – Name of the units of the topographic zone coordinate of the output cube.
Keyword Arguments: sea_points_included (boolean) – 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.
Returns: Cube containing the mask_data array, with appropriate coordinate and attribute information.
Return type: mask_cube (cube)