improver.lapse_rate module

Module containing lapse rate calculation plugins.

class improver.lapse_rate.LapseRate(max_height_diff=35, nbhood_radius=7, max_lapse_rate=0.0294, min_lapse_rate=-0.0098)[source]

Bases: improver.BasePlugin

Plugin to calculate the lapse rate from orography and temperature cubes.

References

The method applied here is based on the method used in the 2010 paper: https://rmets.onlinelibrary.wiley.com/doi/abs/10.1002/met.177

Code methodology:

  1. Apply land/sea mask to temperature and orography datasets. Mask sea points as NaN since image processing module does not recognise Numpy masks.

  2. Extracts neighbourhoods from both datasets: Apply “generic_filter” image processing module to temperature data to extract a neighbourhood for each single point and save this neighbourhood into a larger array. Repeat for orography data. generic_filter mode=”constant” ensures that points beyond edges of dataset will be filled with “cval”. (NaN in this case)

  3. For all the stored orography neighbourhoods - take the neighbours around the central point and create a mask where the height difference from the central point is greater than 35m.

  4. Loop through array of neighbourhoods and take the height and temperature of all grid points and calculate the temperature/height gradient = lapse rate

  5. Constrain the returned lapse rates between min_lapse_rate and max_lapse_rate. These default to > DALR and < -3.0*DALR but are user configurable

__init__(max_height_diff=35, nbhood_radius=7, max_lapse_rate=0.0294, min_lapse_rate=-0.0098)[source]

The class is called with the default constraints for the processing code.

Parameters
  • max_height_diff (float) – Maximum allowable height difference between the central point and points in the neighbourhood over which the lapse rate will be calculated (metres). The default value of 35m is from the referenced paper.

  • nbhood_radius (int) – Radius of neighbourhood around each point. The neighbourhood will be a square array with side length 2*nbhood_radius + 1. The default value of 7 is from the referenced paper.

  • max_lapse_rate (float) – Maximum lapse rate allowed.

  • min_lapse_rate (float) – Minimum lapse rate allowed.

_abc_cache = <_weakrefset.WeakSet object>
_abc_negative_cache = <_weakrefset.WeakSet object>
_abc_negative_cache_version = 213
_abc_registry = <_weakrefset.WeakSet object>
_calc_lapse_rate(temperature, orography)[source]

Function to calculate the lapse rate.

This holds the function to determine the local lapse rate at a point by calculating a least-squares fit to local temperature and altitude data to find the local lapse rate.

Parameters
  • temperature (1D numpy.ndarray) – Contains the temperature values for the central point and its neighbours.

  • orography (1D numpy.ndarray) – Contains the height values for the central point and its neighbours.

Returns

The gradient of the temperature/orography values. This represents the lapse rate.

Return type

float

_create_heightdiff_mask(all_orog_subsections)[source]

Function to create a mask for any neighbouring points where the height difference from the central point is greater than max_height_diff.

Slice through the orography subsection array to remove central points. Extracts the height value of each central point and masks out the neighbouring points where their height difference is greater than the maximum.

Parameters

all_orog_subsections (2D numpy.ndarray) – Each row contains the height values of each neighbourhood.

Returns

A 2D array of boolean values.

Return type

numpy.ndarray

process(temperature_cube, orography_cube, land_sea_mask_cube)[source]

Calculates the lapse rate from the temperature and orography cubes.

Parameters
  • temperature_cube (iris.cube.Cube) – Cube of air temperatures (K).

  • orography_cube (iris.cube.Cube) – Cube containing orography data (metres)

  • land_sea_mask_cube (iris.cube.Cube) – Cube containing a binary land-sea mask. True for land-points and False for Sea.

Returns

Cube containing lapse rate (K m-1)

Return type

iris.cube.Cube

Raises
  • TypeError – If input cubes are not cubes:

  • ValueError – If input cubes are the wrong units.:

class improver.lapse_rate.SaveNeighbourhood(allbuffers)[source]

Bases: object

Saves the neighbourhood around each central point.

The “generic_filter” module extracts the neighbourhood around each point as “buffer”. This buffer is passed to the “SaveNeighbourhood” class. The “filter” function then saves this buffer into the “allbuffers” array.

__init__(allbuffers)[source]

Initialise the class.

Create the global variables that allows the “filter” function to save each extracted buffer into “allbuffers”.

Parameters

allbuffers (numpy.ndarray) – Where to save each extracted buffer.

filter(buffer)[source]

Defines filter function to be applied to extracted buffers.

Saves the contents of the buffer into “allbuffers” array. Therefore a return value isn’t required. However “generic_filter” requires a return value - so use zero.

Parameters

buffer (numpy.ndarray) – Array containing neighourbood points.

Returns

zero (float)

Blank return value required by “generic_filter”.

improver.lapse_rate.apply_gridded_lapse_rate(temperature, lapse_rate, source_orog, dest_orog)[source]

Function to apply a lapse rate adjustment to temperature data forecast at “source_orog” heights, to be applicable at “dest_orog” heights.

Parameters
  • temperature (iris.cube.Cube) – Input temperature field to be adjusted

  • lapse_rate (iris.cube.Cube) – Cube of pre-calculated lapse rates (units modified in place), which must match the temperature cube

  • source_orog (iris.cube.Cube) – 2D cube of source orography heights (units modified in place)

  • dest_orog (iris.cube.Cube) – 2D cube of destination orography heights (units modified in place)

Returns

Lapse-rate adjusted temperature field

Return type

iris.cube.Cube