improver.utilities.mathematical_operations module¶
Module to contain mathematical operations.
-
class
improver.utilities.mathematical_operations.Integration(coord_name_to_integrate, start_point=None, end_point=None, direction_of_integration='negative')[source]¶ Bases:
improver.BasePluginPerform integration along a chosen coordinate. This class currently supports the integration of positive values only, in order to support its usage as part of computing the wet-bulb temperature integral. Generalisation of this class to support standard numerical integration can be undertaken, if required.
-
__init__(coord_name_to_integrate, 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>¶
-
ensure_monotonic_increase_in_chosen_direction(cube)[source]¶ Ensure that the chosen coordinate is monotonically increasing in the specified direction.
- Parameters
cube (iris.cube.Cube) – The cube containing the coordinate to check. Note that the input cube will be modified by this method.
- Returns
The cube containing a coordinate that is monotonically increasing in the desired direction.
- Return type
-
perform_integration(upper_bounds_cube, lower_bounds_cube, integrated_cube)[source]¶ Perform the integration.
Integration is performed by firstly defining the stride as the difference between the upper and lower bound. The contribution from the uppermost half of the stride is calculated by multiplying the upper bound value by 0.5 * stride, and the contribution from the lowermost half of the stride is calculated by multiplying the lower bound value by 0.5 * stride. The contribution from the uppermost half of the stride and the bottom half of the stride is summed.
As the coordinate is progressively integrated, the contribution of each stride is cumulatively summed.
- Parameters
upper_bounds_cube (iris.cube.Cube) – Cube containing the upper bounds to be used during the integration.
lower_bounds_cube (iris.cube.Cube) – Cube containing the lower bounds to be used during the integration.
integrated_cube (iris.cube.Cube) – Cube that will be used for storing the output of the integration containing the most appropriate coordinates.
- Returns
Cube containing the output from the integration.
- Return type
-
prepare_for_integration(cube)[source]¶ Prepare for integration by creating the cubes needed for the integration. These are separate cubes for representing the upper limit of the integration and the lower limit of the integration, as well as setting up the output cube for the integrated output.
- Parameters
cube (iris.cube.Cube) – Cube containing the data to be integrated.
- Returns
- tuple containing:
- upper_bounds_cube (iris.cube.Cube):
Cube containing the upper bounds to be used during the integration.
- lower_bounds_cube (iris.cube.Cube):
Cube containing the lower bounds to be used during the integration.
- integrated_cube (iris.cube.Cube):
Cube that will be used for storing the output of the integration containing the most appropriate coordinates.
- Return type
(tuple)
-
process(cube)[source]¶ Integrate a specified coordinate. This is calculated by defining the upper and lower bounds for the steps along a chosen coordinate within the cube.
- Functions utilised are:
Ensure the cube is sorted in the direction desired for integration.
Prepare for integration by creating cubes that represent the upper and lower limits of the integration, as well as as a template cube to put the integrated output.
Perform the integration using the trapezoidal rule.
Ensure that the integrated coordinate is a dimension coordinate and ensure that the integrated coordinate is sorted in the desired direction.
- Parameters
cube (iris.cube.Cube) – Cube containing the data to be integrated.
- Returns
The cube containing the result of the integration. This will contain the same metadata as the input cube.
- Return type
-