improver.psychrometric_calculations.psychrometric_calculations module¶
Module to contain Psychrometric Calculations.
-
class
improver.psychrometric_calculations.psychrometric_calculations.PhaseChangeLevel(phase_change, grid_point_radius=2)[source]¶ Bases:
improver.BasePluginCalculate a continuous field of heights relative to sea level at which a phase change of precipitation is expected.
-
__init__(phase_change, grid_point_radius=2)[source]¶ Initialise class.
- Parameters
phase_change (str) –
The desired phase change for which the altitude should be returned. Options are:
snow-sleet - the melting of snow to sleet. sleet-rain - the melting of sleet to rain.
grid_point_radius (int) – The radius in grid points used to calculate the maximum height of the orography in a neighbourhood as part of this calculation.
-
_abc_cache= <_weakrefset.WeakSet object>¶
-
_abc_negative_cache= <_weakrefset.WeakSet object>¶
-
_abc_negative_cache_version= 213¶
-
_abc_registry= <_weakrefset.WeakSet object>¶
-
static
fill_in_by_horizontal_interpolation(phase_change_level_data, max_in_nbhood_orog, orog_data)[source]¶ Fill in any remaining unset areas in the phase change level by using linear horizontal interpolation across the grid. As phase change levels at the highest height levels will be filled in by this point any points that still don’t have a valid phase change level have the phase change level at or below the surface orography. This function uses the following steps to help ensure that the filled in values are above or below the orography:
Fill in the phase change level for points with no value yet set using horizontal interpolation from surrounding set points. Only interpolate from surrounding set points at which the phase change level is below the maximum orography height in the region around the unset point. This helps us avoid spreading very high phase change levels across areas where we had missing data.
Fill any gaps that still remain where the linear interpolation has not been able to find a value because there is not enough data (e.g at the corners of the domain). Use nearest neighbour interpolation.
Check whether despite our efforts we have still filled in some of the missing points with phase change levels above the orography. In these cases set the missing points to the height of orography.
We then return the filled in array, which hopefully has no more missing data.
- Parameters
phase_change_level_data (numpy.ndarray) – The phase change level array, filled with values for points whose wet bulb temperature integral crossed the theshold.
max_in_nbhood_orog (numpy.ndarray) – The array containing maximum of the orography field in a given radius.
orog_data (numpy.data) – The array containing the orography data.
- Returns
The phase change level array with missing data filled by horizontal interpolation.
- Return type
-
fill_in_high_phase_change_falling_levels(phase_change_level_data, orog_data, highest_wb_int_data, highest_height)[source]¶ Fill in any data in the phase change level where the whole wet bulb temperature integral is above the the threshold. Set these points to the highest height level + orography.
- Parameters
phase_change_level_data (numpy.ndarray) – Phase change level data (m).
orog_data (numpy.ndarray) – Orographic data (m)
highest_wb_int_data (numpy.ndarray) – Wet bulb integral data on highest level (K m).
highest_height (float) – Highest height at which the integral starts (m).
-
fill_in_sea_points(phase_change_level_data, land_sea_data, max_wb_integral, wet_bulb_temperature, heights)[source]¶ Fill in any sea points where we have not found a phase change level by the time we get to sea level, i.e. where the whole wet bulb temperature integral is below the threshold.
This function finds a linear fit to the wet bulb temperature close to sea level and uses this to find where an extrapolated wet bulb temperature integral would cross the threshold. This results in phase change levels below sea level for points where we have applied the extrapolation.
Assumes that height is the first axis in the wet_bulb_integral array.
- Parameters
phase_change_level_data (numpy.ndarray) – The phase change level array, filled with values for points whose wet bulb temperature integral crossed the theshold.
land_sea_data (numpy.ndarray) – The binary land-sea mask
max_wb_integral (numpy.ndarray) – The wet bulb temperature integral at the final height level used in the integration. This has the maximum values for the wet bulb temperature integral at any level.
wet_bulb_temperature (numpy.ndarray) – The wet bulb temperature profile at each grid point, with height as the leading dimension.
heights (numpy.ndarray) – The vertical height levels above orography, matching the leading dimension of the wet_bulb_temperature.
-
find_extrapolated_falling_level(max_wb_integral, gradient, intercept, phase_change_level_data, sea_points)[source]¶ Find the phase change level below sea level using the linear extrapolation of the wet bulb temperature integral and update the phase change level array with these values.
The phase change level is calculated from finding the point where the integral of wet bulb temperature crosses the falling level threshold.
In cases where the wet bulb temperature integral has not reached the threshold by the time we reach sea level, we can find a fit to the wet bulb temperature profile near the surface, and use this to estimate where the phase change level would be below sea level.
The difference between the wet bulb temperature integral at the threshold and the wet bulb integral at the surface is equal to the integral of the wet bulb temperature between sea level and the negative height corresponding to the phase change level. As we are using a simple linear fit, we can integrate this to find an expression for the extrapolated phase change level.
The form of this expression depends on whether the linear fit of wet bulb temperature crosses the height axis above or below zero altitude.
If we have our linear fit of the form:
\[{{wet\:bulb\:temperature} = m \times height + c}\]and let \(I\) be the wet bulb temperature integral we have found above sea level.
If it crosses above zero, then the limits on the integral are the phase change level and zero and we find the following expression for the phase change level:
\[{{phase\:change\:level} = \frac{c \pm \sqrt{ c^2-2 m (threshold-I)}}{-m}}\]If the linear fit crosses below zero the limits on our integral are the phase change level and the point where the linear fit crosses the height axis, as only positive wet bulb temperatures count towards the integral. In this case our expression for the phase change level is:
\[{{phase\:change\:level} = \frac{c \pm \sqrt{ 2 m (I-threshold)}}{-m}}\]- Parameters
max_wb_integral (numpy.ndarray) – The wet bulb temperature integral at sea level.
gradient (numpy.ndarray) – The gradient of the line of best fit we are using in the extrapolation.
intercept (numpy.ndarray) – The intercept of the line of best fit we are using in the extrapolation.
phase_change_level_data (numpy.ndarray) – The phase change level array with values filled in with phase change levels calculated through extrapolation.
sea_points (numpy.ndarray) – A boolean array with True where the points are sea points.
-
find_falling_level(wb_int_data, orog_data, height_points)[source]¶ Find the phase change level by finding the level of the wet-bulb integral data at the required threshold. Wet-bulb integral data is only available above ground level and there may be an insufficient number of levels in the input data, in which case the required threshold may lie outside the Wet-bulb integral data and the value at that point will be set to np.nan.
- Parameters
wb_int_data (numpy.ndarray) – Wet bulb integral data on heights
orog_data (numpy.ndarray) – Orographic data
height_points (numpy.ndarray) – heights agl
- Returns
Phase change level data asl.
- Return type
-
find_max_in_nbhood_orography(orography_cube)[source]¶ Find the maximum value of the orography in the region around each grid point in your orography field by finding the maximum in a neighbourhood around that point.
- Parameters
orography_cube (iris.cube.Cube) – The cube containing a single 2 dimensional array of orography data
- Returns
The cube containing the maximum in a neighbourhood of the orography data.
- Return type
-
static
linear_wet_bulb_fit(wet_bulb_temperature, heights, sea_points, start_point=0, end_point=5)[source]¶ Calculates a linear fit to the wet bulb temperature profile close to the surface to use when we extrapolate the wet bulb temperature below sea level for sea points.
We only use a set number of points close to the surface for this fit, specified by a start_point and end_point.
- Parameters
wet_bulb_temperature (numpy.ndarray) – The wet bulb temperature profile at each grid point, with height as the leading dimension.
heights (numpy.ndarray) – The vertical height levels above orography, matching the leading dimension of the wet_bulb_temperature.
sea_points (numpy.ndarray) – A boolean array with True where the points are sea points.
start_point (int) – The index of the the starting height we want to use in our linear fit.
end_point (int) – The index of the the end height we want to use in our linear fit.
- Returns
- tuple containing:
gradient (numpy.ndarray) - An array, the same shape as a 2D slice of the wet_bulb_temperature input, containing the gradients of the fitted straight line at each point where it could be found, filled with zeros elsewhere.
intercept (numpy.ndarray) - An array, the same shape as a 2D slice of the wet_bulb_temperature input, containing the intercepts of the fitted straight line at each point where it could be found, filled with zeros elsewhere.
- Return type
(tuple)
-
process(wet_bulb_temperature, wet_bulb_integral, orog, land_sea_mask)[source]¶ Use the wet bulb temperature integral to find the altitude at which a phase change occurs (e.g. snow to sleet). This is achieved by finding the height above sea level at which the integral matches an empirical threshold that is expected to correspond with the phase change. This empirical threshold is the falling_level_threshold. Fill in missing data appropriately.
- Parameters
wet_bulb_temperature (iris.cube.Cube) – Cube of wet bulb temperatures on height levels.
wet_bulb_integral (iris.cube.Cube) – Cube of wet bulb temperature integral (Kelvin-metres).
orog (iris.cube.Cube) – Cube of orography (m).
land_sea_mask (iris.cube.Cube) – Cube containing a binary land-sea mask.
- Returns
Cube of phase change level above sea level (asl).
- Return type
-
-
class
improver.psychrometric_calculations.psychrometric_calculations.Utilities[source]¶ Bases:
objectUtilities for psychrometric calculations.
-
static
calculate_d_enthalpy_dt(mixing_ratio, specific_heat, latent_heat, temperature)[source]¶ Calculate the enthalpy gradient with respect to temperature.
Method from referenced UM documentation.
References
Met Office UM Documentation Paper 080, UM Version 10.8, last updated 2014-12-05.
- Parameters
mixing_ratio (numpy.ndarray) – Array of mixing ratios.
specific_heat (numpy.ndarray) – Array of specific heat capacities of moist air (J kg-1 K-1).
latent_heat (numpy.ndarray) – Array of latent heats of condensation of water vapour (J kg-1).
temperature (numpy.ndarray) – Array of temperatures (K).
- Returns
Array of the enthalpy gradient with respect to temperature.
- Return type
-
static
calculate_enthalpy(mixing_ratio, specific_heat, latent_heat, temperature)[source]¶ Calculate the enthalpy (total energy per unit mass) of air (J kg-1).
Method from referenced UM documentation.
References
Met Office UM Documentation Paper 080, UM Version 10.8, last updated 2014-12-05.
- Parameters
mixing_ratio (numpy.ndarray) – Array of mixing ratios.
specific_heat (numpy.ndarray) – Array of specific heat capacities of moist air (J kg-1 K-1).
latent_heat (numpy.ndarray) – Array of latent heats of condensation of water vapour (J kg-1).
temperature (numpy.ndarray) – Array of air temperatures (K).
- Returns
Array of enthalpy values calculated at the same points as the input cubes (J kg-1).
- Return type
-
static
latent_heat_of_condensation(temperature_input)[source]¶ Calculate a temperature adjusted latent heat of condensation for water vapour using the relationship employed by the UM.
- Parameters
temperature_input (np.ndarray) – A Array of air temperatures (K).
- Returns
Temperature adjusted latent heat of condensation (J kg-1).
- Return type
np.ndarray
-
static
saturation_vapour_pressure_goff_gratch(temperature)[source]¶ Saturation Vapour pressure in a water vapour system calculated using the Goff-Gratch Equation (WMO standard method).
- Parameters
temperature (iris.cube.Cube) – Cube of temperature which will be converted to Kelvin prior to calculation. Valid from 173K to 373K
- Returns
Cube containing the saturation vapour pressure of a pure water vapour system. A correction must be applied to the data when used to convert this to the SVP in air; see the WetBulbTemperature.pressure_correct_svp function.
- Return type
References
Numerical data and functional relationships in science and technology. New series. Group V. Volume 4. Meteorology. Subvolume b. Physical and chemical properties of the air, P35.
-
static
specific_heat_of_moist_air(mixing_ratio)[source]¶ Calculate the specific heat capacity for moist air by combining that of dry air and water vapour in proportion given by the specific humidity.
- Parameters
mixing_ratio (numpy.ndarray) – Array of specific humidity (fractional).
- Returns
Specific heat capacity of moist air (J kg-1 K-1).
- Return type
-
static
-
class
improver.psychrometric_calculations.psychrometric_calculations.WetBulbTemperature(precision=0.005)[source]¶ Bases:
improver.BasePluginA plugin to calculate wet bulb temperatures from air temperature, relative humidity, and pressure data. Calculations are performed using a Newton iterator, with saturated vapour pressures drawn from a lookup table using linear interpolation.
The svp_table used in this plugin is imported (see top of file). It is a table of saturated vapour pressures calculated for a range of temperatures. The import also brings in attributes that describe the range of temperatures covered by the table and the increments in the table.
-
__init__(precision=0.005)[source]¶ Initialise class.
- Parameters
precision (float) – The precision to which the Newton iterator must converge before returning wet bulb temperatures.
-
_abc_cache= <_weakrefset.WeakSet object>¶
-
_abc_negative_cache= <_weakrefset.WeakSet object>¶
-
_abc_negative_cache_version= 213¶
-
_abc_registry= <_weakrefset.WeakSet object>¶
-
_calculate_mixing_ratio(temperature, pressure)[source]¶ Function to compute the mixing ratio given temperature and pressure.
- Parameters
temperature (numpy.ndarray) – Array of air temperature (K).
pressure (numpy.ndarray) – Array of air pressure (Pa).
- Returns
- numpy.ndarray:
Array of mixing ratios.
Method from referenced documentation. Note that EARTH_REPSILON is simply given as an unnamed constant in the reference (0.62198).
References
ASHRAE Fundamentals handbook (2005) Equation 22, 24, p6.8
-
_calculate_wbt(pressure, relative_humidity, temperature)[source]¶ Calculates the wet bulb temperature. without using iris.cubes’
A Newton iterator is used to minimise the gradient of enthalpy against temperature.
- Parameters
pressure (numpy.ndarray) – Array of air Pressure (Pa).
relative_humidity (numpy.ndarray) – Array of relative humidities (1).
temperature (numpy.ndarray) – Array of air temperature (K).
- Returns
Array of wet bulb temperature (K).
- Return type
-
calculate_wet_bulb_temperature(temperature, relative_humidity, pressure)[source]¶ Calculates the wet bulb temperature.
- Parameters
temperature (iris.cube.Cube) – Cube of air temperatures (K).
relative_humidity (iris.cube.Cube) – Cube of relative humidities (%, converted to fractional).
pressure (iris.cube.Cube) – Cube of air pressures (Pa).
- Returns
Cube of wet bulb temperature (K).
- Return type
-
static
check_range(cube, low, high)[source]¶ Function to wrap functionality for throwing out temperatures too low or high for a method to use safely.
- Parameters
cube (numpy.ndarray) – Array of temperature.
high (int or float) – Highest allowable temperature for check
- Raises
UserWarning – If any of the values in cube.data are outside the bounds set by the low and high variables.
-
lookup_svp(temperature)[source]¶ Looks up a value for the saturation vapour pressure of water vapour using the temperature and a table of values. These tabulated values have been calculated using the utilities.ancillary_creation SaturatedVapourPressureTable plugin that uses the Goff-Gratch method.
- Parameters
temperature (numpy.ndarray) – Array of air temperatures (K).
- Returns
Array of saturated vapour pressures (Pa).
- Return type
-
static
pressure_correct_svp(svp, temperature, pressure)[source]¶ Convert saturated vapour pressure in a pure water vapour system into the saturated vapour pressure in air.
Method from referenced documentation.
References
Atmosphere-Ocean Dynamics, Adrian E. Gill, International Geophysics Series, Vol. 30; Equation A4.7.
- Parameters
svp (numpy.ndarray) – Array of saturated vapour pressures (Pa).
temperature (numpy.ndarray) – Array of air temperatures (K).
pressure (numpy.ndarray) – Array of pressure (Pa).
- Returns
The input Array of saturated vapour pressure of air (Pa) is modified by the pressure correction.
- Return type
-
process(temperature, relative_humidity, pressure)[source]¶ Call the calculate_wet_bulb_temperature function to calculate wet bulb temperatures. This process function splits input cubes over vertical levels to mitigate memory issues when trying to operate on multi-level data.
- Parameters
temperature (iris.cube.Cube) – Cube of air temperatures (K).
relative_humidity (iris.cube.Cube) – Cube of relative humidities (%, converted to fractional).
pressure (iris.cube.Cube) – Cube of air pressures (Pa).
- Returns
Cube of wet bulb temperature (K).
- Return type
-
-
class
improver.psychrometric_calculations.psychrometric_calculations.WetBulbTemperatureIntegral(coord_name_to_integrate='height', start_point=None, end_point=None, direction_of_integration='negative')[source]¶ Bases:
improver.BasePluginCalculate a wet-bulb temperature integral.
-
__init__(coord_name_to_integrate='height', start_point=None, end_point=None, direction_of_integration='negative')[source]¶ Initialise class.
- Parameters
coord_name_to_integrate (str) – Name of the coordinate to be integrated.
start_point (float or None) – Point at which to start the integration. Default is None. If start_point is None, integration starts from the first available point.
end_point (float or None) – Point at which to end the integration. Default is None. If end_point is None, integration will continue until the last available point.
direction_of_integration (str) – Description of the direction in which to integrate. Options are ‘positive’ or ‘negative’. ‘positive’ corresponds to the values within the array increasing as the array index increases. ‘negative’ corresponds to the values within the array decreasing as the array index increases.
-
_abc_cache= <_weakrefset.WeakSet object>¶
-
_abc_negative_cache= <_weakrefset.WeakSet object>¶
-
_abc_negative_cache_version= 213¶
-
_abc_registry= <_weakrefset.WeakSet object>¶
-
process(wet_bulb_temperature)[source]¶ Calculate the vertical integal of wet bulb temperature from the input wet bulb temperatures on height levels.
- Parameters
wet_bulb_temperature (iris.cube.Cube) – Cube of wet bulb temperatures of height levels.
- Returns
Cube of wet bulb temperature integral (Kelvin-metres).
- Return type
wet_bulb_temperature_integral (iris.cube.Cube)
-