Source code for improver.wind_calculations.vertical_updraught
# (C) Crown Copyright, Met Office. All rights reserved.
#
# This file is part of 'IMPROVER' and is released under the BSD 3-Clause license.
# See LICENSE in the root of the repository for full licensing details.
"""This module contains the VerticalUpdraught plugin"""
from typing import Union
import numpy as np
from iris.cube import Cube, CubeList
from improver import BasePlugin
from improver.metadata.utilities import (
create_new_diagnostic_cube,
generate_mandatory_attributes,
)
from improver.utilities.common_input_handle import as_cubelist
from improver.utilities.cube_checker import spatial_coords_match
[docs]
class VerticalUpdraught(BasePlugin):
"""
Methods to calculate the maximum vertical updraught from CAPE and precipitation rate as
defined in Hand (2002) and Golding (1998) with the precipitation rate modifier found in
the UKPP CDP code.
Hand, W. 2002. "The Met Office Convection Diagnosis Scheme." Meteorological Applications
9(1): 69-83. https://doi.org/10.1017/S1350482702001081.
Golding, B.W. 1998. "Nimrod: A system for generating automated very short range forecasts."
Meteorol. Appl. 5: 1-16. https://doi.org/10.1017/S1350482798000577.
"""
[docs]
def __init__(self, model_id_attr: str = None):
"""
Set up class
Args:
model_id_attr:
Name of model ID attribute to be copied from source cubes to output cube
"""
self.model_id_attr = model_id_attr
self.cape = Cube(shape=(0,))
self.precip = Cube(shape=(0,))
self.cube_names = [
"atmosphere_convective_available_potential_energy",
"lwe_precipitation_rate_max",
]
self._minimum_cape = 10.0 # J kg-1. Minimum value to diagnose updraught from
self._minimum_precip = 5.0 # mm h-1. Minimum value to diagnose updraught from
[docs]
def _updraught_from_cape(self) -> np.ndarray:
"""
Calculate the updraught from CAPE data
Calculation is 0.25 * sqrt(2 * cape)
Returns zero where CAPE < 10 J kg-1
"""
updraught = 0.25 * (2 * self.cape.data) ** 0.5
updraught[self.cape.data < self._minimum_cape] = 0.0
return updraught.astype(np.float32)
[docs]
def _updraught_increment_from_precip(self) -> np.ndarray:
"""
Calculate the updraught increment from the precipitation rate.
Calculation is 7.33 * (precip / 28.7)^0.22
Where precipitation rate < 5 mm h-1, increment is zero.
"""
increment = 7.33 * (self.precip.data / 28.7) ** 0.22
increment[self.precip.data < self._minimum_precip] = 0.0
return increment.astype(np.float32)
[docs]
def _make_updraught_cube(self, data: np.ndarray) -> Cube:
"""Puts the data array into a CF-compliant cube"""
attributes = {}
if self.model_id_attr:
attributes[self.model_id_attr] = self.precip.attributes[self.model_id_attr]
cube = create_new_diagnostic_cube(
"maximum_vertical_updraught",
"m s-1",
self.precip,
mandatory_attributes=generate_mandatory_attributes(
[self.precip, self.cape]
),
optional_attributes=attributes,
data=data,
)
return cube
[docs]
def process(self, *cubes: Union[Cube, CubeList]) -> Cube:
"""Executes methods to calculate updraught from CAPE and precipitation rate
and packages this as a Cube with appropriate metadata.
Args:
inputs:
List of CAPE and precipitation rate cubes (any order)
Returns:
Cube:
Containing maximum vertical updraught
"""
cubes = as_cubelist(*cubes)
self._parse_inputs(cubes)
return self._make_updraught_cube(
self._updraught_from_cape() + self._updraught_increment_from_precip()
)