improver.lapse_rate module

Module containing lapse rate calculation plugins.

class ApplyGriddedLapseRate[source]

Bases: PostProcessingPlugin

Class to apply a lapse rate adjustment to a temperature data forecast

_abc_impl = <_abc_data object>
_calc_orog_diff(source_orog, dest_orog)[source]

Get difference in orography heights, in metres

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

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

Return type

Cube

Returns

The difference cube

static _check_dim_coords(temperature, lapse_rate)[source]

Throw an error if the dimension coordinates are not the same for temperature and lapse rate cubes

Parameters
  • temperature (Cube) –

  • lapse_rate (Cube) –

Return type

None

process(temperature, lapse_rate, source_orog, dest_orog)[source]

Applies lapse rate correction to temperature forecast. All cubes’ units are modified in place.

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

  • lapse_rate (Cube) – Cube of pre-calculated lapse rates

  • source_orog (Cube) – 2D cube of source orography heights

  • dest_orog (Cube) – 2D cube of destination orography heights

Return type

Cube

Returns

Lapse-rate adjusted temperature field, in Kelvin

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

Bases: 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. Creates “views” of both datasets, where each view represents a neighbourhood of points. To do this, each array is padded with NaN values to a width of half the neighbourhood size.

  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_impl = <_abc_data object>
_create_windows(temp, orog)[source]

Uses neighbourhood tools to pad and generate rolling windows of the temp and orog datasets.

Parameters
  • temp (ndarray) – 2D array (single realization) of temperature data, in Kelvin

  • orog (ndarray) – 2D array of orographies, in metres

Return type

Tuple[ndarray, ndarray]

Returns

  • Rolling windows of the padded temperature dataset.

  • Rolling windows of the padded orography dataset.

_generate_lapse_rate_array(temperature_data, orography_data, land_sea_mask_data)[source]

Calculate lapse rates and apply filters

Parameters
  • temperature_data (ndarray) – 2D array (single realization) of temperature data, in Kelvin

  • orography_data (ndarray) – 2D array of orographies, in metres

  • land_sea_mask_data (ndarray) – 2D land-sea mask

Return type

ndarray

Returns

Lapse rate values

process(temperature, orography, land_sea_mask, model_id_attr=None)[source]

Calculates the lapse rate from the temperature and orography cubes.

Parameters
  • temperature (Cube) – Cube of air temperatures (K).

  • orography (Cube) – Cube containing orography data (metres)

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

  • model_id_attr (Optional[str]) – Name of the attribute used to identify the source model for blending. This is inherited from the input temperature cube.

Return type

Cube

Returns

Cube containing lapse rate (K m-1)

Raises
  • TypeError – If input cubes are not cubes:

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